@clowder-ai/plugin-sdk 0.1.0-beta.10

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.
@@ -0,0 +1,210 @@
1
+ import { validateManifest, } from '@clowder-ai/plugin-contract';
2
+ export class FeatureContextRevokedError extends Error {
3
+ constructor() {
4
+ super('feature context has been revoked');
5
+ this.name = 'FeatureContextRevokedError';
6
+ }
7
+ }
8
+ export class ContributionConflictError extends Error {
9
+ constructor(key) {
10
+ super(`contribution ${key} is already registered with a different payload`);
11
+ this.name = 'ContributionConflictError';
12
+ }
13
+ }
14
+ function canonicalJson(value, ancestors = new Set()) {
15
+ if (value === null)
16
+ return 'null';
17
+ if (typeof value === 'string' || typeof value === 'boolean')
18
+ return JSON.stringify(value);
19
+ if (typeof value === 'number' && Number.isFinite(value))
20
+ return JSON.stringify(value);
21
+ if (typeof value !== 'object')
22
+ throw new TypeError('contribution payload must contain only JSON values');
23
+ if (ancestors.has(value))
24
+ throw new TypeError('contribution payload must not contain JSON cycles');
25
+ if (Object.getOwnPropertySymbols(value).length > 0) {
26
+ throw new TypeError('contribution payload must contain only JSON string keys');
27
+ }
28
+ const prototype = Object.getPrototypeOf(value);
29
+ if (Array.isArray(value) ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {
30
+ throw new TypeError('contribution payload must contain only plain JSON objects or arrays');
31
+ }
32
+ ancestors.add(value);
33
+ try {
34
+ if (Array.isArray(value)) {
35
+ if (Object.keys(value).some((key) => !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length)) {
36
+ throw new TypeError('contribution payload must contain only JSON array elements');
37
+ }
38
+ const elements = [];
39
+ const length = value.length;
40
+ for (let index = 0; index < length; index += 1) {
41
+ if (!Object.hasOwn(value, index))
42
+ throw new TypeError('contribution payload must not contain JSON array holes');
43
+ elements.push(canonicalJson(value[index], ancestors));
44
+ }
45
+ return `[${elements.join(',')}]`;
46
+ }
47
+ const object = value;
48
+ return `{${Object.keys(object)
49
+ .sort()
50
+ .map((key) => `${JSON.stringify(key)}:${canonicalJson(object[key], ancestors)}`)
51
+ .join(',')}}`;
52
+ }
53
+ finally {
54
+ ancestors.delete(value);
55
+ }
56
+ }
57
+ function deepFreeze(value) {
58
+ if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
59
+ for (const nested of Object.values(value))
60
+ deepFreeze(nested);
61
+ Object.freeze(value);
62
+ }
63
+ return value;
64
+ }
65
+ /**
66
+ * Creates the author-facing context around a Host-issued binding.
67
+ *
68
+ * This helper does not grant authority: every adapter operation carries the opaque lease and the Host
69
+ * remains responsible for verifying its signature, revisions, grants, integrity epoch, and liveness.
70
+ */
71
+ export function createFeatureContextSession(binding, adapter) {
72
+ let revoked = false;
73
+ let revokePromise;
74
+ const active = new Map();
75
+ const assertActive = () => {
76
+ if (revoked)
77
+ throw new FeatureContextRevokedError();
78
+ };
79
+ const register = async (type, input) => {
80
+ assertActive();
81
+ const digest = canonicalJson({ ...input, type });
82
+ // Dispatch exactly the JSON snapshot used for identity; cloning first can
83
+ // silently erase non-JSON keys, while reading twice can invoke changing getters.
84
+ const contribution = deepFreeze(JSON.parse(digest));
85
+ const key = `${type}:${contribution.id}`;
86
+ const existing = active.get(key);
87
+ if (existing !== undefined) {
88
+ if (existing.disposePromise !== undefined) {
89
+ await existing.disposePromise.catch(() => undefined);
90
+ assertActive();
91
+ return register(type, input);
92
+ }
93
+ if (existing.digest !== digest)
94
+ throw new ContributionConflictError(key);
95
+ const registration = await existing.promise;
96
+ if (revoked) {
97
+ await registration.dispose().catch(() => undefined);
98
+ throw new FeatureContextRevokedError();
99
+ }
100
+ return registration;
101
+ }
102
+ let entry;
103
+ const promise = adapter.registerContribution(binding, contribution).then((receipt) => {
104
+ const registration = {
105
+ key,
106
+ receipt,
107
+ dispose: () => {
108
+ if (entry.disposePromise !== undefined)
109
+ return entry.disposePromise;
110
+ entry.disposePromise = adapter.disposeContribution(binding, receipt).then(() => {
111
+ if (active.get(key) === entry)
112
+ active.delete(key);
113
+ }, (error) => {
114
+ entry.disposePromise = undefined;
115
+ throw error;
116
+ });
117
+ return entry.disposePromise;
118
+ },
119
+ };
120
+ return registration;
121
+ });
122
+ entry = { digest, promise };
123
+ active.set(key, entry);
124
+ let registered = false;
125
+ try {
126
+ const registration = await promise;
127
+ registered = true;
128
+ if (revoked) {
129
+ await registration.dispose().catch(() => undefined);
130
+ throw new FeatureContextRevokedError();
131
+ }
132
+ return registration;
133
+ }
134
+ catch (error) {
135
+ if (!registered && active.get(key) === entry)
136
+ active.delete(key);
137
+ throw error;
138
+ }
139
+ };
140
+ const registrar = (type) => ({
141
+ register: (input) => register(type, input),
142
+ });
143
+ const runWhileActive = async (operation) => {
144
+ assertActive();
145
+ const result = await operation();
146
+ assertActive();
147
+ return result;
148
+ };
149
+ const readConfig = async (key) => {
150
+ return runWhileActive(() => adapter.readConfig(binding, key));
151
+ };
152
+ const readSecret = async (key) => {
153
+ return runWhileActive(() => adapter.readSecret(binding, key));
154
+ };
155
+ const readState = async (key) => {
156
+ return runWhileActive(() => adapter.readState(binding, key));
157
+ };
158
+ const writeState = async (key, value) => {
159
+ return runWhileActive(() => adapter.writeState(binding, key, value));
160
+ };
161
+ const subscriptions = registrar('message-subscription');
162
+ const context = {
163
+ featureId: binding.featureId,
164
+ config: { get: readConfig },
165
+ secrets: { get: readSecret },
166
+ state: { get: readState, set: writeState },
167
+ identity: registrar('identity'),
168
+ scheduler: registrar('schedule'),
169
+ tools: registrar('tool'),
170
+ mcp: registrar('mcp'),
171
+ skills: registrar('skill'),
172
+ limbs: registrar('limb'),
173
+ webhooks: registrar('webhook'),
174
+ messaging: { subscribe: subscriptions.register },
175
+ services: registrar('service'),
176
+ connectors: registrar('connector'),
177
+ ui: registrar('ui'),
178
+ contentEditors: registrar('content-editor-provider'),
179
+ };
180
+ return {
181
+ context,
182
+ revoke: () => {
183
+ revoked = true;
184
+ if (revokePromise !== undefined)
185
+ return revokePromise;
186
+ revokePromise = Promise.all([...active.values()].map(async (entry) => (await entry.promise).dispose())).then(() => undefined, (error) => {
187
+ revokePromise = undefined;
188
+ throw error;
189
+ });
190
+ return revokePromise;
191
+ },
192
+ };
193
+ }
194
+ /** Validate one manifest truth and bind only activators for declared feature IDs. */
195
+ export function definePlugin(input) {
196
+ const validation = validateManifest(input.manifest);
197
+ if (!validation.valid) {
198
+ throw new TypeError(`plugin manifest is invalid: ${validation.errors[0]?.message ?? 'unknown error'}`);
199
+ }
200
+ const featureIds = new Set(validation.manifest.features.map((feature) => feature.id));
201
+ const activate = input.activate === undefined ? {} : input.activate;
202
+ for (const featureId of Object.keys(activate)) {
203
+ if (!featureIds.has(featureId)) {
204
+ throw new TypeError(`activator ${featureId} is not declared by the plugin manifest`);
205
+ }
206
+ }
207
+ const manifest = deepFreeze(structuredClone(validation.manifest));
208
+ return Object.freeze({ manifest, activate: Object.freeze({ ...activate }) });
209
+ }
210
+ //# sourceMappingURL=feature-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-context.js","sourceRoot":"","sources":["../src/feature-context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAgBjB,MAAM,6BAA6B,CAAC;AA+BrC,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD;QACE,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,GAAW;QACrB,KAAK,CAAC,gBAAgB,GAAG,iDAAiD,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAiDD,SAAS,aAAa,CAAC,KAAc,EAAE,YAAY,IAAI,GAAG,EAAU;IAClE,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAA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,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { type BrokerReadyParams, type CandidateHello, type HandshakeRejectReason, type SessionBinding } from '@clowder-ai/plugin-contract';
2
+ export type HandshakePhase = 'candidate' | 'bound' | 'activated' | 'rejected';
3
+ export interface CandidateHandshakeState {
4
+ readonly phase: 'candidate';
5
+ readonly candidate: CandidateHello;
6
+ }
7
+ export interface BoundHandshakeState {
8
+ readonly phase: 'bound';
9
+ readonly candidate: CandidateHello;
10
+ readonly binding: SessionBinding;
11
+ }
12
+ export interface ActivatedHandshakeState {
13
+ readonly phase: 'activated';
14
+ readonly candidate: CandidateHello;
15
+ readonly binding: SessionBinding;
16
+ readonly activation: BrokerReadyParams;
17
+ }
18
+ export interface RejectedHandshakeState {
19
+ readonly phase: 'rejected';
20
+ readonly reason: HandshakeRejectReason;
21
+ }
22
+ export type LocalHandshakeState = CandidateHandshakeState | BoundHandshakeState | ActivatedHandshakeState | RejectedHandshakeState;
23
+ export interface HandshakeValidationLevels {
24
+ /** All H1–H9 fields use the published beta.8 closed grammar. */
25
+ readonly contractFields: 'full';
26
+ }
27
+ export interface CandidateHandshakeIntent {
28
+ readonly kind: 'candidate';
29
+ readonly transport: 'local-only';
30
+ readonly candidate: CandidateHello;
31
+ readonly validation: HandshakeValidationLevels;
32
+ }
33
+ export interface BindingHandshakeIntent {
34
+ readonly kind: 'binding';
35
+ readonly transport: 'local-only';
36
+ readonly binding: SessionBinding;
37
+ readonly validation: HandshakeValidationLevels;
38
+ }
39
+ export interface ActivationHandshakeIntent {
40
+ readonly kind: 'activation';
41
+ readonly transport: 'local-only';
42
+ readonly ready: BrokerReadyParams;
43
+ readonly validation: HandshakeValidationLevels;
44
+ }
45
+ /**
46
+ * Objects in this union are deliberately codec-free. They retain the future
47
+ * HarnessWireShape outbound/inbound orientation without constructing wire
48
+ * frames. The published contract now owns the complete beta.8 grammar.
49
+ */
50
+ export type LocalHandshakeIntent = CandidateHandshakeIntent | BindingHandshakeIntent | ActivationHandshakeIntent;
51
+ export type LocalHandshakeTransition = {
52
+ readonly accepted: true;
53
+ readonly state: CandidateHandshakeState | BoundHandshakeState | ActivatedHandshakeState;
54
+ readonly intent: LocalHandshakeIntent;
55
+ } | {
56
+ readonly accepted: false;
57
+ readonly reason: HandshakeRejectReason;
58
+ readonly state: RejectedHandshakeState;
59
+ };
60
+ /** Starts a local-only handshake by validating the candidate claims. */
61
+ export declare function beginLocalHandshake(candidate: unknown): LocalHandshakeTransition;
62
+ /** Accepts a Host-provided binding only from the local candidate state. */
63
+ export declare function acceptSessionBinding(state: LocalHandshakeState, binding: unknown): LocalHandshakeTransition;
64
+ /** Creates the local activation intent after the binding nonce oracle passes. */
65
+ export declare function prepareActivation(state: LocalHandshakeState, ready: unknown): LocalHandshakeTransition;
66
+ //# sourceMappingURL=handshake-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handshake-client.d.ts","sourceRoot":"","sources":["../src/handshake-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC;AAE9E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,QAA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GACxB,sBAAsB,GACtB,yBAAyB,CAAC;AAE9B,MAAM,MAAM,wBAAwB,GAChC;IACE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,uBAAuB,GAAG,mBAAmB,GAAG,uBAAuB,CAAC;IACxF,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;CACvC,GACD;IACE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAC;CACxC,CAAC;AAsEN,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,OAAO,GAAG,wBAAwB,CAgBhF;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,OAAO,GACf,wBAAwB,CAuB1B;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,OAAO,GACb,wBAAwB,CAqB1B"}
@@ -0,0 +1,124 @@
1
+ import { HANDSHAKE_REJECT_REASONS, validateBrokerReadyParams, validateCandidateHello, validateSessionBinding, } from '@clowder-ai/plugin-contract';
2
+ const HANDSHAKE_REASON_SET = new Set(HANDSHAKE_REJECT_REASONS);
3
+ const CLOSED_CONTRACT = {
4
+ contractFields: 'full',
5
+ };
6
+ function reject(reason) {
7
+ if (!HANDSHAKE_REASON_SET.has(reason)) {
8
+ throw new RangeError(`unknown handshake rejection reason: ${reason}`);
9
+ }
10
+ return { accepted: false, reason, state: { phase: 'rejected', reason } };
11
+ }
12
+ function snapshotCandidate(candidate) {
13
+ return {
14
+ pluginId: candidate.pluginId,
15
+ packageDigest: candidate.packageDigest,
16
+ contractVersion: candidate.contractVersion,
17
+ wireVersion: candidate.wireVersion,
18
+ };
19
+ }
20
+ function snapshotBinding(binding) {
21
+ return {
22
+ pluginId: binding.pluginId,
23
+ packageDigest: binding.packageDigest,
24
+ contractVersion: binding.contractVersion,
25
+ wireVersion: binding.wireVersion,
26
+ pluginInstanceId: binding.pluginInstanceId,
27
+ brokerSessionId: binding.brokerSessionId,
28
+ grantRevision: binding.grantRevision,
29
+ effectiveGrants: [...binding.effectiveGrants],
30
+ bindingNonce: binding.bindingNonce,
31
+ };
32
+ }
33
+ function snapshotReady(ready) {
34
+ return { bindingNonce: ready.bindingNonce };
35
+ }
36
+ function isCandidateHello(value) {
37
+ return validateCandidateHello(value);
38
+ }
39
+ function validateBinding(candidate, value) {
40
+ if (!validateSessionBinding(value)) {
41
+ return { valid: false, reason: 'AUTHORITY_VIOLATION' };
42
+ }
43
+ if (value.pluginId !== candidate.pluginId || value.packageDigest !== candidate.packageDigest) {
44
+ return { valid: false, reason: 'PACKAGE_MISMATCH' };
45
+ }
46
+ if (value.contractVersion !== candidate.contractVersion) {
47
+ return { valid: false, reason: 'CONTRACT_INCOMPATIBLE' };
48
+ }
49
+ if (value.wireVersion !== candidate.wireVersion) {
50
+ return { valid: false, reason: 'WIRE_INCOMPATIBLE' };
51
+ }
52
+ return { valid: true, binding: snapshotBinding(value) };
53
+ }
54
+ function validateReady(value, binding) {
55
+ return (validateBrokerReadyParams(value) &&
56
+ value.bindingNonce === binding.bindingNonce);
57
+ }
58
+ /** Starts a local-only handshake by validating the candidate claims. */
59
+ export function beginLocalHandshake(candidate) {
60
+ if (!isCandidateHello(candidate)) {
61
+ return reject('MALFORMED_HELLO');
62
+ }
63
+ const candidateSnapshot = snapshotCandidate(candidate);
64
+ const state = { phase: 'candidate', candidate: candidateSnapshot };
65
+ return {
66
+ accepted: true,
67
+ state,
68
+ intent: {
69
+ kind: 'candidate',
70
+ transport: 'local-only',
71
+ candidate: candidateSnapshot,
72
+ validation: CLOSED_CONTRACT,
73
+ },
74
+ };
75
+ }
76
+ /** Accepts a Host-provided binding only from the local candidate state. */
77
+ export function acceptSessionBinding(state, binding) {
78
+ if (state.phase !== 'candidate') {
79
+ return reject('BINDING_REPLAY');
80
+ }
81
+ const result = validateBinding(state.candidate, binding);
82
+ if (!result.valid) {
83
+ return reject(result.reason);
84
+ }
85
+ const next = {
86
+ phase: 'bound',
87
+ candidate: state.candidate,
88
+ binding: result.binding,
89
+ };
90
+ return {
91
+ accepted: true,
92
+ state: next,
93
+ intent: {
94
+ kind: 'binding',
95
+ transport: 'local-only',
96
+ binding: result.binding,
97
+ validation: CLOSED_CONTRACT,
98
+ },
99
+ };
100
+ }
101
+ /** Creates the local activation intent after the binding nonce oracle passes. */
102
+ export function prepareActivation(state, ready) {
103
+ if (state.phase !== 'bound' || !validateReady(ready, state.binding)) {
104
+ return reject('BINDING_REPLAY');
105
+ }
106
+ const readySnapshot = snapshotReady(ready);
107
+ const next = {
108
+ phase: 'activated',
109
+ candidate: state.candidate,
110
+ binding: state.binding,
111
+ activation: readySnapshot,
112
+ };
113
+ return {
114
+ accepted: true,
115
+ state: next,
116
+ intent: {
117
+ kind: 'activation',
118
+ transport: 'local-only',
119
+ ready: readySnapshot,
120
+ validation: CLOSED_CONTRACT,
121
+ },
122
+ };
123
+ }
124
+ //# sourceMappingURL=handshake-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handshake-client.js","sourceRoot":"","sources":["../src/handshake-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,GAKvB,MAAM,6BAA6B,CAAC;AAiFrC,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAS,wBAAwB,CAAC,CAAC;AACvE,MAAM,eAAe,GAA8B;IACjD,cAAc,EAAE,MAAM;CACvB,CAAC;AAEF,SAAS,MAAM,CAAC,MAA6B;IAC3C,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CAAC,uCAAuC,MAAM,EAAE,CAAC,CAAC;IACxE,CAAC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,SAAS,EAAE,YAAY;YACvB,KAAK,EAAE,aAAa;YACpB,UAAU,EAAE,eAAe;SAC5B;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Public SDK entrypoint.
3
+ *
4
+ * This package exposes:
5
+ * 1. Schema-neutral NDJSON transport (stdio-runtime, S0/#12)
6
+ * 2. Wire dispatch classifier (wire-dispatch, S1)
7
+ *
8
+ * The beta.8 handshake, beta.9 events.publish, beta.10 lifecycle, and beta.11
9
+ * messaging rows are executable. SDK beta.10 adds the content editor provider
10
+ * registrar to the Train B author facade without widening the frozen M0 wire registry.
11
+ * The dispatch classifier gates every method before standalone callbacks or
12
+ * Host-bound transport behavior can run.
13
+ */
14
+ export { NdjsonFrameError, StdioRuntimeFatalError, createStdioChannel, startStdioRuntime, type StdioChannel, type StdioChannelOptions, type JsonObject, type StdioFrame, type StdioFrameErrorCode, type StdioFrameHandler, type StdioRuntimeFatalReason, type StdioRuntimeFatalErrorOptions, type StdioRuntimeOptions, } from './stdio-runtime.js';
15
+ export { loadStandaloneManifest, ManifestStartupError, startStandaloneHost, type StandaloneHost, type StandaloneHostOptions, type StandaloneMessageDisposition, type StandaloneMessageHandler, } from './standalone-host.js';
16
+ export { acceptSessionBinding, beginLocalHandshake, prepareActivation, type ActivatedHandshakeState, type ActivationHandshakeIntent, type BindingHandshakeIntent, type BoundHandshakeState, type CandidateHandshakeIntent, type CandidateHandshakeState, type HandshakePhase, type HandshakeValidationLevels, type LocalHandshakeIntent, type LocalHandshakeState, type LocalHandshakeTransition, type RejectedHandshakeState, } from './handshake-client.js';
17
+ export { classifyFrame, type DispatchResult, type InFlightEntry, type RequestSnapshot, } from './wire-dispatch.js';
18
+ export { EventsPublishError, createEventsPublisher, type EventsPublishErrorCode, type EventsPublishHostTransport, type StdioSessionLiveness, type EventsPublisherOptions, type EventsPublisher, } from './events-publisher.js';
19
+ export { ContributionConflictError, FeatureContextRevokedError, createFeatureContextSession, definePlugin, type ContributionRegistration, type ContributionRegistrar, type DefinedPlugin, type FeatureActivator, type FeatureBinding, type FeatureContext, type FeatureContextSession, type FeatureHostAdapter, type HostContributionReceipt, type PluginDefinitionInput, } from './feature-context.js';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,GAC9B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,GAC5B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,YAAY,EACZ,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Public SDK entrypoint.
3
+ *
4
+ * This package exposes:
5
+ * 1. Schema-neutral NDJSON transport (stdio-runtime, S0/#12)
6
+ * 2. Wire dispatch classifier (wire-dispatch, S1)
7
+ *
8
+ * The beta.8 handshake, beta.9 events.publish, beta.10 lifecycle, and beta.11
9
+ * messaging rows are executable. SDK beta.10 adds the content editor provider
10
+ * registrar to the Train B author facade without widening the frozen M0 wire registry.
11
+ * The dispatch classifier gates every method before standalone callbacks or
12
+ * Host-bound transport behavior can run.
13
+ */
14
+ export { NdjsonFrameError, StdioRuntimeFatalError, createStdioChannel, startStdioRuntime, } from './stdio-runtime.js';
15
+ export { loadStandaloneManifest, ManifestStartupError, startStandaloneHost, } from './standalone-host.js';
16
+ export { acceptSessionBinding, beginLocalHandshake, prepareActivation, } from './handshake-client.js';
17
+ export { classifyFrame, } from './wire-dispatch.js';
18
+ export { EventsPublishError, createEventsPublisher, } from './events-publisher.js';
19
+ export { ContributionConflictError, FeatureContextRevokedError, createFeatureContextSession, definePlugin, } from './feature-context.js';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAUlB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GAKpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAalB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,aAAa,GAId,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GAMtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,YAAY,GAWb,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,55 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ import { type DeliverInput, type DeliveryRejectReason, type ManifestValidationError, type PluginManifest } from '@clowder-ai/plugin-contract';
3
+ import { type StdioChannel, type StdioRuntimeFatalError } from './stdio-runtime.js';
4
+ export declare class ManifestStartupError extends Error {
5
+ readonly errors: readonly ManifestValidationError[];
6
+ constructor(errors: readonly ManifestValidationError[]);
7
+ }
8
+ export interface StandaloneHostOptions {
9
+ /** Untrusted manifest content; it is validated before stdio starts. */
10
+ readonly manifest: unknown;
11
+ /** Caller-owned streams are useful for embedding and tests; provide both or neither. */
12
+ readonly input?: Readable;
13
+ readonly output?: Writable;
14
+ /**
15
+ * Runs before the closed drain row is acknowledged with `result: null`.
16
+ * A cleanup that outlives its drain deadline is acknowledged as expired;
17
+ * callers that need cancellation must arrange it within their callback.
18
+ */
19
+ readonly onDrain?: (input: {
20
+ readonly deadlineUnixMs: number;
21
+ }) => void | Promise<void>;
22
+ /**
23
+ * Handles the ready Host-to-plugin messaging callback and reports only the
24
+ * plugin-observed delivery fact. Retry and dead-letter policy remain Host-owned.
25
+ */
26
+ readonly onMessage?: StandaloneMessageHandler;
27
+ readonly onFatal?: (error: StdioRuntimeFatalError) => void;
28
+ }
29
+ export type StandaloneMessageDisposition = {
30
+ readonly accepted: true;
31
+ } | {
32
+ readonly accepted: false;
33
+ readonly reason: DeliveryRejectReason;
34
+ };
35
+ export type StandaloneMessageHandler = (input: DeliverInput) => StandaloneMessageDisposition | Promise<StandaloneMessageDisposition>;
36
+ export interface StandaloneHost extends StdioChannel {
37
+ readonly manifest: PluginManifest;
38
+ }
39
+ /**
40
+ * Loads and contract-validates a manifest file for a standalone plugin.
41
+ *
42
+ * File and JSON parsing errors deliberately propagate: callers have not yet
43
+ * started a transport, so no protocol peer can observe a partial startup.
44
+ */
45
+ export declare function loadStandaloneManifest(path: string | URL): Promise<PluginManifest>;
46
+ /**
47
+ * Starts the fail-closed plugin-side standalone shell.
48
+ *
49
+ * A manifest is validated by the published contract runtime before any stdio
50
+ * listener is attached. Lifecycle rows execute locally. beta.8 handshake
51
+ * requests reach the handler only to receive a conservative standard error;
52
+ * no Broker behavior is present in this shell.
53
+ */
54
+ export declare function startStandaloneHost(options: StandaloneHostOptions): StandaloneHost;
55
+ //# sourceMappingURL=standalone-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone-host.d.ts","sourceRoot":"","sources":["../src/standalone-host.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EAWL,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAIL,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAC5B,MAAM,oBAAoB,CAAC;AAG5B,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,uBAAuB,EAAE,CAAC;gBAExC,MAAM,EAAE,SAAS,uBAAuB,EAAE;CAKvD;AAED,MAAM,WAAW,qBAAqB;IACpC,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;I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