@principal-ai/subsystems-core 0.51.5 → 0.51.6

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.d.ts CHANGED
@@ -13,6 +13,8 @@
13
13
  export * from './types';
14
14
  export type { DraftTopic, TopicAsset, TopicCreator, TopicSubsystemModelRef, TopicReference, } from './storage/topic-types';
15
15
  export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
16
+ export { toSharedTopic } from './storage/topic-share';
17
+ export type { SharedTopic, SharedTopicAsset, SharedTopicProjection } from './storage/topic-share';
16
18
  export { validateSubsystemModelCrossField } from './validation';
17
19
  export type { SubsystemValidationProblem } from './validation';
18
20
  export * from './audit/pure';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,SAAS,CAAC;AAExB,YAAY,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAKpG,OAAO,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAI/D,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,cAAc,SAAS,CAAC;AAExB,YAAY,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAKlG,OAAO,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAI/D,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -26,11 +26,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.validateSubsystemModelCrossField = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = void 0;
29
+ exports.validateSubsystemModelCrossField = exports.toSharedTopic = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = void 0;
30
30
  __exportStar(require("./types"), exports);
31
31
  var topic_reference_links_1 = require("./storage/topic-reference-links");
32
32
  Object.defineProperty(exports, "formatTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.formatTopicReferenceLink; } });
33
33
  Object.defineProperty(exports, "parseTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.parseTopicReferenceLink; } });
34
+ var topic_share_1 = require("./storage/topic-share");
35
+ Object.defineProperty(exports, "toSharedTopic", { enumerable: true, get: function () { return topic_share_1.toSharedTopic; } });
34
36
  // Cross-field validation (the rules the JSON Schema can't express). Structural
35
37
  // (schema) validation is enforced per surface against
36
38
  // `schemas/subsystem-model.schema.json`.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AASxB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAE1D,+EAA+E;AAC/E,sDAAsD;AACtD,yCAAyC;AACzC,2CAAgE;AAAvD,8HAAA,gCAAgC,OAAA;AAGzC,gFAAgF;AAChF,uEAAuE;AACvE,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AASxB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAC1D,qDAAsD;AAA7C,4GAAA,aAAa,OAAA;AAGtB,+EAA+E;AAC/E,sDAAsD;AACtD,yCAAyC;AACzC,2CAAgE;AAAvD,8HAAA,gCAAgC,OAAA;AAGzC,gFAAgF;AAChF,uEAAuE;AACvE,+CAA6B"}
package/dist/node.d.ts CHANGED
@@ -12,6 +12,8 @@ export { TopicStore, PRINCIPAL_DIR, TOPICS_DIR, LEGACY_TOPICS_BLOB, } from './st
12
12
  export type { TopicIndexEntry, TopicCreate, TopicUpdate, MigrationResult, } from './storage/topicStore';
13
13
  export type { DraftTopic, TopicAsset, TopicCreator, TopicSubsystemModelRef, TopicReference, } from './storage/topic-types';
14
14
  export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
15
+ export { toSharedTopic } from './storage/topic-share';
16
+ export type { SharedTopic, SharedTopicAsset, SharedTopicProjection } from './storage/topic-share';
15
17
  export { OpenCodeEventStore, defaultOpenCodeDBPath } from './opencode/OpenCodeEventStore';
16
18
  export type { OpenCodeRawEvent, OpenCodeSessionEvents, OpenCodeEventRetriever, OpenCodeStoreOptions, SessionSummary, SessionListResult, } from './opencode/types';
17
19
  export { listAgentSessions, detectAgent, fetchRawEvents } from './opencode/agent-sessions';
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAGpG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1F,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3F,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,eAAe,EACf,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAGlG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1F,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3F,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,0BAA0B,EAC1B,gBAAgB,EAChB,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/node.js CHANGED
@@ -22,7 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
22
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.opencodeRowsToUniversalEvents = exports.collectRepositories = exports.accumulateEvents = exports.normalizeEventsWithAdapter = exports.normalizeEvents = exports.NodePathNormalizationAdapter = exports.buildAgentSessionFixture = exports.fetchRawEvents = exports.detectAgent = exports.listAgentSessions = exports.defaultOpenCodeDBPath = exports.OpenCodeEventStore = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = exports.LEGACY_TOPICS_BLOB = exports.TOPICS_DIR = exports.PRINCIPAL_DIR = exports.TopicStore = void 0;
25
+ exports.opencodeRowsToUniversalEvents = exports.collectRepositories = exports.accumulateEvents = exports.normalizeEventsWithAdapter = exports.normalizeEvents = exports.NodePathNormalizationAdapter = exports.buildAgentSessionFixture = exports.fetchRawEvents = exports.detectAgent = exports.listAgentSessions = exports.defaultOpenCodeDBPath = exports.OpenCodeEventStore = exports.toSharedTopic = exports.parseTopicReferenceLink = exports.formatTopicReferenceLink = exports.LEGACY_TOPICS_BLOB = exports.TOPICS_DIR = exports.PRINCIPAL_DIR = exports.TopicStore = void 0;
26
26
  __exportStar(require("./types"), exports);
27
27
  __exportStar(require("./audit"), exports);
28
28
  // File-per-topic store (~/.principal/topics) — node:fs only
@@ -34,6 +34,8 @@ Object.defineProperty(exports, "LEGACY_TOPICS_BLOB", { enumerable: true, get: fu
34
34
  var topic_reference_links_1 = require("./storage/topic-reference-links");
35
35
  Object.defineProperty(exports, "formatTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.formatTopicReferenceLink; } });
36
36
  Object.defineProperty(exports, "parseTopicReferenceLink", { enumerable: true, get: function () { return topic_reference_links_1.parseTopicReferenceLink; } });
37
+ var topic_share_1 = require("./storage/topic-share");
38
+ Object.defineProperty(exports, "toSharedTopic", { enumerable: true, get: function () { return topic_share_1.toSharedTopic; } });
37
39
  // OpenCode event retrieval (Node.js only - SQLite)
38
40
  var OpenCodeEventStore_1 = require("./opencode/OpenCodeEventStore");
39
41
  Object.defineProperty(exports, "OpenCodeEventStore", { enumerable: true, get: function () { return OpenCodeEventStore_1.OpenCodeEventStore; } });
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,0CAAwB;AAExB,4DAA4D;AAC5D,mDAK8B;AAJ5B,wGAAA,UAAU,OAAA;AACV,2GAAA,aAAa,OAAA;AACb,wGAAA,UAAU,OAAA;AACV,gHAAA,kBAAkB,OAAA;AAepB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAE1D,mDAAmD;AACnD,oEAA0F;AAAjF,wHAAA,kBAAkB,OAAA;AAAE,2HAAA,qBAAqB,OAAA;AAUlD,iEAAiE;AACjE,4DAA2F;AAAlF,mHAAA,iBAAiB,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,gHAAA,cAAc,OAAA;AAOvD,mDAAmD;AACnD,oDAAoE;AAA3D,mHAAA,wBAAwB,OAAA;AAWjC,sEAAsE;AACtE,gDAO6B;AAN3B,wHAAA,4BAA4B,OAAA;AAC5B,2GAAA,eAAe,OAAA;AACf,sHAAA,0BAA0B,OAAA;AAC1B,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,yHAAA,6BAA6B,OAAA"}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,0CAAwB;AAExB,4DAA4D;AAC5D,mDAK8B;AAJ5B,wGAAA,UAAU,OAAA;AACV,2GAAA,aAAa,OAAA;AACb,wGAAA,UAAU,OAAA;AACV,gHAAA,kBAAkB,OAAA;AAepB,yEAAoG;AAA3F,iIAAA,wBAAwB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAC1D,qDAAsD;AAA7C,4GAAA,aAAa,OAAA;AAGtB,mDAAmD;AACnD,oEAA0F;AAAjF,wHAAA,kBAAkB,OAAA;AAAE,2HAAA,qBAAqB,OAAA;AAUlD,iEAAiE;AACjE,4DAA2F;AAAlF,mHAAA,iBAAiB,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,gHAAA,cAAc,OAAA;AAOvD,mDAAmD;AACnD,oDAAoE;AAA3D,mHAAA,wBAAwB,OAAA;AAWjC,sEAAsE;AACtE,gDAO6B;AAN3B,wHAAA,4BAA4B,OAAA;AAC5B,2GAAA,eAAe,OAAA;AACf,sHAAA,0BAA0B,OAAA;AAC1B,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,yHAAA,6BAA6B,OAAA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Portable projection of a topic for sharing outside the machine that authored
3
+ * it. Browser-safe (no `node:*`).
4
+ *
5
+ * A {@link DraftTopic} carries fields that only mean something locally: store
6
+ * ids of subsystem models, references to sketches/drawings/topics on disk, and
7
+ * inline image bytes. {@link toSharedTopic} drops the local-only fields and
8
+ * splits image bytes out so a host can upload each one separately.
9
+ */
10
+ import type { DraftTopic, TopicCreator } from './topic-types';
11
+ /** An image a shared topic refers to. Bytes travel separately, keyed by `id`. */
12
+ export interface SharedTopicAsset {
13
+ /** Content hash; the `asset://<id>` target in the description. */
14
+ id: string;
15
+ /** MIME type, e.g. "image/png". */
16
+ mime: string;
17
+ /** Resolvable URL, when the bytes already live somewhere public. */
18
+ url?: string;
19
+ /** Markdown alt text. */
20
+ alt?: string;
21
+ }
22
+ /**
23
+ * A topic as it leaves the authoring machine. No local store ids and no inline
24
+ * bytes; `description` is unchanged, so `asset://<id>` links still resolve
25
+ * against `assets`.
26
+ */
27
+ export interface SharedTopic {
28
+ id: string;
29
+ title: string;
30
+ description?: string;
31
+ /** Repositories as PURL strings. */
32
+ repos?: string[];
33
+ /** ISO 8601. */
34
+ createdAt: string;
35
+ /** ISO 8601. */
36
+ updatedAt: string;
37
+ createdBy?: TopicCreator;
38
+ assets?: SharedTopicAsset[];
39
+ }
40
+ export interface SharedTopicProjection {
41
+ topic: SharedTopic;
42
+ /** Assets whose bytes must be uploaded alongside the topic (those with `data`). */
43
+ uploads: Array<{
44
+ id: string;
45
+ mime: string;
46
+ data: string;
47
+ }>;
48
+ }
49
+ /**
50
+ * Project a local topic into its shared form.
51
+ *
52
+ * Dropped: `subsystemModels` and `references` (local store ids), each asset's
53
+ * `source` (local Storybook origin) and inline `data`. Assets with neither
54
+ * `data` nor `url` cannot be resolved by a reader and are omitted.
55
+ */
56
+ export declare function toSharedTopic(topic: DraftTopic): SharedTopicProjection;
57
+ //# sourceMappingURL=topic-share.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic-share.d.ts","sourceRoot":"","sources":["../../src/storage/topic-share.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAc,YAAY,EAAE,MAAM,eAAe,CAAC;AAE1E,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,EAAE,EAAE,MAAM,CAAC;IACX,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,WAAW,CAAC;IACnB,mFAAmF;IACnF,OAAO,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,qBAAqB,CA8BtE"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Portable projection of a topic for sharing outside the machine that authored
4
+ * it. Browser-safe (no `node:*`).
5
+ *
6
+ * A {@link DraftTopic} carries fields that only mean something locally: store
7
+ * ids of subsystem models, references to sketches/drawings/topics on disk, and
8
+ * inline image bytes. {@link toSharedTopic} drops the local-only fields and
9
+ * splits image bytes out so a host can upload each one separately.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.toSharedTopic = void 0;
13
+ /**
14
+ * Project a local topic into its shared form.
15
+ *
16
+ * Dropped: `subsystemModels` and `references` (local store ids), each asset's
17
+ * `source` (local Storybook origin) and inline `data`. Assets with neither
18
+ * `data` nor `url` cannot be resolved by a reader and are omitted.
19
+ */
20
+ function toSharedTopic(topic) {
21
+ const assets = [];
22
+ const uploads = [];
23
+ const seen = new Set();
24
+ for (const asset of topic.assets ?? []) {
25
+ if (seen.has(asset.id) || !isResolvable(asset))
26
+ continue;
27
+ seen.add(asset.id);
28
+ assets.push({
29
+ id: asset.id,
30
+ mime: asset.mime,
31
+ ...(asset.url ? { url: asset.url } : {}),
32
+ ...(asset.alt ? { alt: asset.alt } : {}),
33
+ });
34
+ if (asset.data)
35
+ uploads.push({ id: asset.id, mime: asset.mime, data: asset.data });
36
+ }
37
+ return {
38
+ topic: {
39
+ id: topic.id,
40
+ title: topic.title,
41
+ ...(topic.description !== undefined ? { description: topic.description } : {}),
42
+ ...(topic.repos?.length ? { repos: [...topic.repos] } : {}),
43
+ createdAt: topic.createdAt,
44
+ updatedAt: topic.updatedAt,
45
+ ...(topic.createdBy ? { createdBy: { ...topic.createdBy } } : {}),
46
+ ...(assets.length ? { assets } : {}),
47
+ },
48
+ uploads,
49
+ };
50
+ }
51
+ exports.toSharedTopic = toSharedTopic;
52
+ function isResolvable(asset) {
53
+ return Boolean(asset.data || asset.url);
54
+ }
55
+ //# sourceMappingURL=topic-share.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topic-share.js","sourceRoot":"","sources":["../../src/storage/topic-share.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAyCH;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,KAAiB;IAC7C,MAAM,MAAM,GAAuB,EAAE,CAAC;IACtC,MAAM,OAAO,GAAqC,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,EAAE;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;YAAE,SAAS;QACzD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC;YACV,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACxC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzC,CAAC,CAAC;QACH,IAAI,KAAK,CAAC,IAAI;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;KACpF;IAED,OAAO;QACL,KAAK,EAAE;YACL,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9E,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrC;QACD,OAAO;KACR,CAAC;AACJ,CAAC;AA9BD,sCA8BC;AAED,SAAS,YAAY,CAAC,KAAiB;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principal-ai/subsystems-core",
3
- "version": "0.51.5",
3
+ "version": "0.51.6",
4
4
  "description": "Subsystem model types and agent-session tooling for Principal AI",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -21,6 +21,8 @@ export type {
21
21
  TopicReference,
22
22
  } from './storage/topic-types';
23
23
  export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
24
+ export { toSharedTopic } from './storage/topic-share';
25
+ export type { SharedTopic, SharedTopicAsset, SharedTopicProjection } from './storage/topic-share';
24
26
 
25
27
  // Cross-field validation (the rules the JSON Schema can't express). Structural
26
28
  // (schema) validation is enforced per surface against
package/src/node.ts CHANGED
@@ -31,6 +31,8 @@ export type {
31
31
  TopicReference,
32
32
  } from './storage/topic-types';
33
33
  export { formatTopicReferenceLink, parseTopicReferenceLink } from './storage/topic-reference-links';
34
+ export { toSharedTopic } from './storage/topic-share';
35
+ export type { SharedTopic, SharedTopicAsset, SharedTopicProjection } from './storage/topic-share';
34
36
 
35
37
  // OpenCode event retrieval (Node.js only - SQLite)
36
38
  export { OpenCodeEventStore, defaultOpenCodeDBPath } from './opencode/OpenCodeEventStore';
@@ -0,0 +1,71 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { toSharedTopic } from './topic-share';
3
+ import type { DraftTopic } from './topic-types';
4
+
5
+ const base: DraftTopic = {
6
+ id: 'topic-1-abc',
7
+ title: 'Sharing',
8
+ description: 'Brief with ![shot](asset://hash-a)',
9
+ repos: ['pkg:github/principal-ai/subsystem-modeling'],
10
+ createdAt: '2026-11-01T00:00:00.000Z',
11
+ updatedAt: '2026-11-02T00:00:00.000Z',
12
+ createdBy: { githubId: 1, githubLogin: 'octocat' },
13
+ };
14
+
15
+ describe('toSharedTopic', () => {
16
+ test('keeps the portable fields unchanged', () => {
17
+ const { topic, uploads } = toSharedTopic(base);
18
+ expect(topic).toEqual(base);
19
+ expect(uploads).toEqual([]);
20
+ });
21
+
22
+ test('drops local store ids and references', () => {
23
+ const { topic } = toSharedTopic({
24
+ ...base,
25
+ subsystemModels: [{ modelId: 'sg-1', trailIds: ['wt-a'] }],
26
+ references: [{ kind: 'c4-sketch', sketchId: 'c4s-1' }, { kind: 'topic', topicId: 'topic-2' }],
27
+ });
28
+ expect(topic).not.toHaveProperty('subsystemModels');
29
+ expect(topic).not.toHaveProperty('references');
30
+ });
31
+
32
+ test('splits inline bytes into uploads and strips local asset origin', () => {
33
+ const { topic, uploads } = toSharedTopic({
34
+ ...base,
35
+ assets: [
36
+ {
37
+ id: 'hash-a',
38
+ mime: 'image/png',
39
+ data: 'AAAA',
40
+ alt: 'shot',
41
+ source: { storyId: 's', storybookUrl: 'http://localhost:6006' },
42
+ },
43
+ { id: 'hash-b', mime: 'image/jpeg', url: 'https://example.com/b.jpg' },
44
+ ],
45
+ });
46
+ expect(topic.assets).toEqual([
47
+ { id: 'hash-a', mime: 'image/png', alt: 'shot' },
48
+ { id: 'hash-b', mime: 'image/jpeg', url: 'https://example.com/b.jpg' },
49
+ ]);
50
+ expect(uploads).toEqual([{ id: 'hash-a', mime: 'image/png', data: 'AAAA' }]);
51
+ });
52
+
53
+ test('omits unresolvable and duplicate assets', () => {
54
+ const { topic, uploads } = toSharedTopic({
55
+ ...base,
56
+ assets: [
57
+ { id: 'hash-a', mime: 'image/png', data: 'AAAA' },
58
+ { id: 'hash-a', mime: 'image/png', data: 'AAAA' },
59
+ { id: 'hash-c', mime: 'image/png' },
60
+ ],
61
+ });
62
+ expect(topic.assets).toEqual([{ id: 'hash-a', mime: 'image/png' }]);
63
+ expect(uploads).toHaveLength(1);
64
+ });
65
+
66
+ test('does not alias the source arrays', () => {
67
+ const { topic } = toSharedTopic(base);
68
+ expect(topic.repos).not.toBe(base.repos);
69
+ expect(topic.createdBy).not.toBe(base.createdBy);
70
+ });
71
+ });
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Portable projection of a topic for sharing outside the machine that authored
3
+ * it. Browser-safe (no `node:*`).
4
+ *
5
+ * A {@link DraftTopic} carries fields that only mean something locally: store
6
+ * ids of subsystem models, references to sketches/drawings/topics on disk, and
7
+ * inline image bytes. {@link toSharedTopic} drops the local-only fields and
8
+ * splits image bytes out so a host can upload each one separately.
9
+ */
10
+
11
+ import type { DraftTopic, TopicAsset, TopicCreator } from './topic-types';
12
+
13
+ /** An image a shared topic refers to. Bytes travel separately, keyed by `id`. */
14
+ export interface SharedTopicAsset {
15
+ /** Content hash; the `asset://<id>` target in the description. */
16
+ id: string;
17
+ /** MIME type, e.g. "image/png". */
18
+ mime: string;
19
+ /** Resolvable URL, when the bytes already live somewhere public. */
20
+ url?: string;
21
+ /** Markdown alt text. */
22
+ alt?: string;
23
+ }
24
+
25
+ /**
26
+ * A topic as it leaves the authoring machine. No local store ids and no inline
27
+ * bytes; `description` is unchanged, so `asset://<id>` links still resolve
28
+ * against `assets`.
29
+ */
30
+ export interface SharedTopic {
31
+ id: string;
32
+ title: string;
33
+ description?: string;
34
+ /** Repositories as PURL strings. */
35
+ repos?: string[];
36
+ /** ISO 8601. */
37
+ createdAt: string;
38
+ /** ISO 8601. */
39
+ updatedAt: string;
40
+ createdBy?: TopicCreator;
41
+ assets?: SharedTopicAsset[];
42
+ }
43
+
44
+ export interface SharedTopicProjection {
45
+ topic: SharedTopic;
46
+ /** Assets whose bytes must be uploaded alongside the topic (those with `data`). */
47
+ uploads: Array<{ id: string; mime: string; data: string }>;
48
+ }
49
+
50
+ /**
51
+ * Project a local topic into its shared form.
52
+ *
53
+ * Dropped: `subsystemModels` and `references` (local store ids), each asset's
54
+ * `source` (local Storybook origin) and inline `data`. Assets with neither
55
+ * `data` nor `url` cannot be resolved by a reader and are omitted.
56
+ */
57
+ export function toSharedTopic(topic: DraftTopic): SharedTopicProjection {
58
+ const assets: SharedTopicAsset[] = [];
59
+ const uploads: SharedTopicProjection['uploads'] = [];
60
+ const seen = new Set<string>();
61
+
62
+ for (const asset of topic.assets ?? []) {
63
+ if (seen.has(asset.id) || !isResolvable(asset)) continue;
64
+ seen.add(asset.id);
65
+ assets.push({
66
+ id: asset.id,
67
+ mime: asset.mime,
68
+ ...(asset.url ? { url: asset.url } : {}),
69
+ ...(asset.alt ? { alt: asset.alt } : {}),
70
+ });
71
+ if (asset.data) uploads.push({ id: asset.id, mime: asset.mime, data: asset.data });
72
+ }
73
+
74
+ return {
75
+ topic: {
76
+ id: topic.id,
77
+ title: topic.title,
78
+ ...(topic.description !== undefined ? { description: topic.description } : {}),
79
+ ...(topic.repos?.length ? { repos: [...topic.repos] } : {}),
80
+ createdAt: topic.createdAt,
81
+ updatedAt: topic.updatedAt,
82
+ ...(topic.createdBy ? { createdBy: { ...topic.createdBy } } : {}),
83
+ ...(assets.length ? { assets } : {}),
84
+ },
85
+ uploads,
86
+ };
87
+ }
88
+
89
+ function isResolvable(asset: TopicAsset): boolean {
90
+ return Boolean(asset.data || asset.url);
91
+ }