@semiont/core 0.4.19 → 0.4.21

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/dist/index.js CHANGED
@@ -117,23 +117,211 @@ var PERSISTED_EVENT_TYPES = [
117
117
  ];
118
118
 
119
119
  // src/bus-protocol.ts
120
- var STREAM_COMMAND_RESULT_TYPES = [
121
- // Match flow search results for binding candidates
122
- "match:search-results",
123
- "match:search-failed",
124
- // Gather flowassembled context for reference resolution
125
- "gather:complete",
126
- "gather:failed",
127
- "gather:annotation-progress",
128
- // Mark flow — AI-assisted annotation progress
129
- "mark:progress",
130
- "mark:assist-finished",
131
- "mark:assist-failed",
132
- // Yield flow — resource generation progress
133
- "yield:progress",
134
- "yield:finished",
135
- "yield:failed"
120
+ var RESOURCE_BROADCAST_TYPES = [
121
+ // Post-unification: job:complete / job:fail carry the "job ended on
122
+ // this resource" signal that yield:finished / yield:failed used to.
123
+ // Scope them by resource so every viewer of the affected resource
124
+ // not just the initiator can react (toast, refresh, etc.).
125
+ "job:complete",
126
+ "job:fail"
136
127
  ];
128
+ var CHANNEL_SCHEMAS = {
129
+ // ── YIELD FLOW ──────────────────────────────────────────────────
130
+ "yield:created": null,
131
+ // StoredEvent
132
+ "yield:cloned": null,
133
+ "yield:updated": null,
134
+ "yield:moved": null,
135
+ "yield:representation-added": null,
136
+ "yield:representation-removed": null,
137
+ "yield:request": "YieldRequestCommand",
138
+ "yield:create": "YieldCreateCommand",
139
+ "yield:update": "YieldUpdateCommand",
140
+ "yield:mv": "YieldMvCommand",
141
+ "yield:clone": null,
142
+ // void
143
+ "yield:clone-token-requested": "YieldCloneTokenRequest",
144
+ "yield:clone-resource-requested": "YieldCloneResourceRequest",
145
+ "yield:clone-create": "YieldCloneCreateCommand",
146
+ "yield:create-ok": "YieldCreateOk",
147
+ "yield:create-failed": "CommandError",
148
+ "yield:update-ok": "YieldUpdateOk",
149
+ "yield:update-failed": null,
150
+ // YieldUpdateOk & CommandError
151
+ "yield:move-ok": "YieldMoveOk",
152
+ "yield:move-failed": null,
153
+ // { fromUri } & CommandError
154
+ "yield:clone-token-generated": null,
155
+ // { correlationId; response: CloneResourceWithTokenResponse }
156
+ "yield:clone-token-failed": null,
157
+ // { correlationId } & CommandError
158
+ "yield:clone-resource-result": null,
159
+ // { correlationId; response: GetResourceByTokenResponse }
160
+ "yield:clone-resource-failed": null,
161
+ // { correlationId } & CommandError
162
+ "yield:clone-created": "YieldCloneCreated",
163
+ "yield:clone-create-failed": null,
164
+ // { correlationId } & CommandError
165
+ // ── MARK FLOW ───────────────────────────────────────────────────
166
+ "mark:added": null,
167
+ // StoredEvent
168
+ "mark:removed": null,
169
+ "mark:body-updated": null,
170
+ "mark:entity-tag-added": null,
171
+ "mark:entity-tag-removed": null,
172
+ "mark:entity-type-added": null,
173
+ "mark:archived": null,
174
+ "mark:unarchived": null,
175
+ "mark:create-request": "MarkCreateRequest",
176
+ "mark:create": "MarkCreateCommand",
177
+ "mark:delete": "MarkDeleteCommand",
178
+ "mark:update-body": "MarkUpdateBodyCommand",
179
+ "mark:archive": "MarkArchiveCommand",
180
+ "mark:unarchive": "MarkUnarchiveCommand",
181
+ "mark:update-entity-types": "MarkUpdateEntityTypesCommand",
182
+ "mark:add-entity-type": "MarkAddEntityTypeCommand",
183
+ "mark:create-ok": "MarkCreateOk",
184
+ "mark:create-failed": "CommandError",
185
+ "mark:delete-ok": "MarkDeleteOk",
186
+ "mark:delete-failed": "CommandError",
187
+ "mark:body-update-failed": "CommandError",
188
+ "mark:entity-type-add-failed": "CommandError",
189
+ "mark:select-comment": "SelectionData",
190
+ "mark:select-tag": "SelectionData",
191
+ "mark:select-assessment": "SelectionData",
192
+ "mark:select-reference": "SelectionData",
193
+ "mark:requested": "MarkRequestedEvent",
194
+ "mark:cancel-pending": null,
195
+ // void
196
+ "mark:submit": "MarkSubmitEvent",
197
+ "mark:assist-request": "MarkAssistRequestEvent",
198
+ "mark:assist-cancelled": null,
199
+ // void
200
+ "mark:progress-dismiss": null,
201
+ // void
202
+ "mark:mode-toggled": null,
203
+ // void
204
+ "mark:selection-changed": "MarkSelectionChangedEvent",
205
+ "mark:click-changed": "MarkClickChangedEvent",
206
+ "mark:shape-changed": "MarkShapeChangedEvent",
207
+ // ── BIND FLOW ───────────────────────────────────────────────────
208
+ "bind:initiate": "BindInitiateCommand",
209
+ "bind:update-body": "BindUpdateBodyCommand",
210
+ "bind:body-updated": "BindBodyUpdated",
211
+ "bind:body-update-failed": "CommandError",
212
+ // ── MATCH FLOW ──────────────────────────────────────────────────
213
+ "match:search-requested": "MatchSearchRequest",
214
+ "match:search-results": "MatchSearchResult",
215
+ "match:search-failed": "MatchSearchFailed",
216
+ // ── GATHER FLOW ─────────────────────────────────────────────────
217
+ "gather:requested": "GatherAnnotationRequest",
218
+ "gather:complete": "GatherAnnotationComplete",
219
+ "gather:failed": null,
220
+ // { correlationId; annotationId } & CommandError
221
+ "gather:resource-requested": "GatherResourceRequest",
222
+ "gather:resource-complete": "GatherResourceComplete",
223
+ "gather:resource-failed": null,
224
+ // { correlationId; resourceId } & CommandError
225
+ "gather:summary-requested": "GatherSummaryRequest",
226
+ "gather:summary-result": null,
227
+ // { correlationId; response: Record<string, unknown> }
228
+ "gather:summary-failed": null,
229
+ // { correlationId } & CommandError
230
+ "gather:annotation-progress": "GatherProgress",
231
+ "gather:annotation-finished": "GatherAnnotationFinished",
232
+ "gather:progress": "GatherProgress",
233
+ "gather:finished": "GatherFinished",
234
+ // ── BROWSE FLOW ─────────────────────────────────────────────────
235
+ "browse:resource-requested": "BrowseResourceRequest",
236
+ "browse:resource-result": "BrowseResourceResult",
237
+ "browse:resource-failed": null,
238
+ // { correlationId } & CommandError
239
+ "browse:resources-requested": "BrowseResourcesRequest",
240
+ "browse:resources-result": "BrowseResourcesResult",
241
+ "browse:resources-failed": null,
242
+ "browse:annotations-requested": "BrowseAnnotationsRequest",
243
+ "browse:annotations-result": "BrowseAnnotationsResult",
244
+ "browse:annotations-failed": null,
245
+ "browse:annotation-requested": "BrowseAnnotationRequest",
246
+ "browse:annotation-result": "BrowseAnnotationResult",
247
+ "browse:annotation-failed": null,
248
+ "browse:events-requested": "BrowseEventsRequest",
249
+ "browse:events-result": "BrowseEventsResult",
250
+ "browse:events-failed": null,
251
+ "browse:annotation-history-requested": "BrowseAnnotationHistoryRequest",
252
+ "browse:annotation-history-result": "BrowseAnnotationHistoryResult",
253
+ "browse:annotation-history-failed": null,
254
+ "browse:annotation-context-requested": "BrowseAnnotationContextRequest",
255
+ "browse:annotation-context-result": null,
256
+ // { correlationId; response: Record<string, unknown> }
257
+ "browse:annotation-context-failed": null,
258
+ "browse:referenced-by-requested": "BrowseReferencedByRequest",
259
+ "browse:referenced-by-result": "BrowseReferencedByResult",
260
+ "browse:referenced-by-failed": null,
261
+ "browse:entity-types-requested": "BrowseEntityTypesRequest",
262
+ "browse:entity-types-result": "BrowseEntityTypesResult",
263
+ "browse:entity-types-failed": null,
264
+ "browse:directory-requested": "BrowseDirectoryRequest",
265
+ "browse:directory-result": "BrowseDirectoryResult",
266
+ "browse:directory-failed": null,
267
+ // { correlationId; path } & CommandError
268
+ "browse:click": "BrowseClickEvent",
269
+ "browse:reference-navigate": "BrowseReferenceNavigateEvent",
270
+ "browse:entity-type-clicked": "BrowseEntityTypeClickedEvent",
271
+ // ── SHELL (app-scoped UI events, fire on SemiontBrowser bus) ────
272
+ "panel:toggle": "BrowsePanelToggleEvent",
273
+ "panel:open": "BrowsePanelOpenEvent",
274
+ "panel:close": null,
275
+ // void
276
+ "shell:sidebar-toggle": null,
277
+ // void
278
+ "tabs:close": "BrowseResourceCloseEvent",
279
+ "tabs:reorder": "BrowseResourceReorderEvent",
280
+ "nav:link-clicked": "BrowseLinkClickedEvent",
281
+ "nav:push": "BrowseRouterPushEvent",
282
+ "nav:external": null,
283
+ // includes runtime `cancelFallback: () => void`
284
+ // ── BECKON FLOW ─────────────────────────────────────────────────
285
+ "beckon:hover": "BeckonHoverEvent",
286
+ "beckon:focus": "BeckonFocusEvent",
287
+ "beckon:sparkle": "BeckonSparkleEvent",
288
+ // ── JOB FLOW ────────────────────────────────────────────────────
289
+ "job:started": null,
290
+ // StoredEvent
291
+ "job:progress": null,
292
+ "job:completed": null,
293
+ "job:failed": null,
294
+ "job:start": "JobStartCommand",
295
+ "job:report-progress": "JobReportProgressCommand",
296
+ "job:complete": "JobCompleteCommand",
297
+ "job:fail": "JobFailCommand",
298
+ "job:queued": "JobQueuedEvent",
299
+ "job:cancel-requested": "JobCancelRequest",
300
+ "job:status-requested": "JobStatusRequest",
301
+ "job:create": "JobCreateCommand",
302
+ "job:claim": "JobClaimCommand",
303
+ "job:status-result": "JobStatusResult",
304
+ "job:status-failed": null,
305
+ // { correlationId } & CommandError
306
+ "job:created": "JobCreatedResult",
307
+ "job:create-failed": null,
308
+ "job:claimed": null,
309
+ // { correlationId; response: Record<string, unknown> }
310
+ "job:claim-failed": null,
311
+ // ── SETTINGS (frontend-only) ────────────────────────────────────
312
+ "settings:theme-changed": "SettingsThemeChangedEvent",
313
+ "settings:line-numbers-toggled": null,
314
+ // void
315
+ "settings:locale-changed": "SettingsLocaleChangedEvent",
316
+ "settings:hover-delay-changed": "SettingsHoverDelayChangedEvent",
317
+ // ── SSE infrastructure ──────────────────────────────────────────
318
+ "stream-connected": null,
319
+ // Record<string, never>
320
+ "replay-window-exceeded": null,
321
+ // inline payload
322
+ "bus:resume-gap": null
323
+ // inline payload
324
+ };
137
325
 
138
326
  // src/event-utils.ts
139
327
  function getAnnotationUriFromEvent(event) {
@@ -372,6 +560,38 @@ function burstBuffer(options) {
372
560
  });
373
561
  }
374
562
 
563
+ // src/serialize-per-key.ts
564
+ async function serializePerKey(key, chains, work) {
565
+ const prev = chains.get(key) ?? Promise.resolve();
566
+ let result;
567
+ const next = prev.catch(() => {
568
+ }).then(async () => {
569
+ result = await work();
570
+ });
571
+ chains.set(key, next);
572
+ try {
573
+ await next;
574
+ return result;
575
+ } finally {
576
+ if (chains.get(key) === next) {
577
+ chains.delete(key);
578
+ }
579
+ }
580
+ }
581
+
582
+ // src/logger.ts
583
+ function errField(error) {
584
+ if (error instanceof Error) {
585
+ return {
586
+ name: error.name,
587
+ message: error.message,
588
+ stack: error.stack,
589
+ ...error.cause !== void 0 && { cause: errField(error.cause) }
590
+ };
591
+ }
592
+ return error;
593
+ }
594
+
375
595
  // src/annotation-utils.ts
376
596
  function findBodyItem(body, identity) {
377
597
  if (!Array.isArray(body)) {
@@ -603,6 +823,9 @@ function userToAgent(user) {
603
823
  };
604
824
  }
605
825
  function didToAgent(did) {
826
+ if (!did) {
827
+ return { type: "Person", id: "unknown", name: "unknown" };
828
+ }
606
829
  const parts = did.split(":");
607
830
  const encoded = parts[parts.length - 1] || "unknown";
608
831
  const name = decodeURIComponent(encoded);
@@ -627,11 +850,14 @@ function deepMerge(base, override) {
627
850
  }
628
851
  function resolveEnvVars(obj, env) {
629
852
  if (typeof obj === "string") {
630
- return obj.replace(/\$\{([^}]+)\}/g, (match, varName) => {
631
- if (env[varName] === void 0) {
632
- throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);
633
- }
634
- return env[varName];
853
+ return obj.replace(/\$\{([^}]+)\}/g, (match, expr) => {
854
+ const sepIdx = expr.indexOf(":-");
855
+ const varName = sepIdx >= 0 ? expr.slice(0, sepIdx) : expr;
856
+ const defaultValue = sepIdx >= 0 ? expr.slice(sepIdx + 2) : void 0;
857
+ const value = env[varName];
858
+ if (value !== void 0) return value;
859
+ if (defaultValue !== void 0) return defaultValue;
860
+ throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);
635
861
  });
636
862
  }
637
863
  if (Array.isArray(obj)) {
@@ -949,6 +1175,6 @@ function getAllPlatformTypes() {
949
1175
  var CORE_TYPES_VERSION = "0.1.0";
950
1176
  var SDK_VERSION = "0.1.0";
951
1177
 
952
- export { APIError, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, EventBus, NotFoundError, PERSISTED_EVENT_TYPES, SDK_VERSION, STREAM_COMMAND_RESULT_TYPES, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, annotationId, annotationUri, applyBodyOperations, assembleAnnotation, authCode, baseUrl, burstBuffer, cloneToken, createTomlConfigLoader, didToAgent, email, entityType, findBodyItem, generateUuid, getAllPlatformTypes, getAnnotationUriFromEvent, getFragmentSelector, getSvgSelector, getTextPositionSelector, googleCredential, isAnnotationId, isArray, isBoolean, isDefined, isEventRelatedToAnnotation, isFunction, isNull, isNullish, isNumber, isObject, isResourceId, isStoredEvent, isString, isUndefined, isValidPlatformType, jobId, loadTomlConfig, mcpToken, parseEnvironment, refreshToken, resourceAnnotationUri, resourceId, resourceUri, searchQuery, userDID, userId, userToAgent, userToDid, validateEnvironment, validateSvgMarkup };
1178
+ export { APIError, CHANNEL_SCHEMAS, CORE_TYPES_VERSION, CREATION_METHODS, ConfigurationError, ConflictError, EventBus, NotFoundError, PERSISTED_EVENT_TYPES, RESOURCE_BROADCAST_TYPES, SDK_VERSION, ScopedEventBus, ScriptError, SemiontError, UnauthorizedError, ValidationError, accessToken, annotationId, annotationUri, applyBodyOperations, assembleAnnotation, authCode, baseUrl, burstBuffer, cloneToken, createTomlConfigLoader, didToAgent, email, entityType, errField, findBodyItem, generateUuid, getAllPlatformTypes, getAnnotationUriFromEvent, getFragmentSelector, getSvgSelector, getTextPositionSelector, googleCredential, isAnnotationId, isArray, isBoolean, isDefined, isEventRelatedToAnnotation, isFunction, isNull, isNullish, isNumber, isObject, isResourceId, isStoredEvent, isString, isUndefined, isValidPlatformType, jobId, loadTomlConfig, mcpToken, parseEnvironment, refreshToken, resourceAnnotationUri, resourceId, resourceUri, searchQuery, serializePerKey, userDID, userId, userToAgent, userToDid, validateEnvironment, validateSvgMarkup };
953
1179
  //# sourceMappingURL=index.js.map
954
1180
  //# sourceMappingURL=index.js.map