@principal-ai/subsystems-core 0.51.5 → 0.51.7

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.
Files changed (48) hide show
  1. package/dist/index.d.ts +3 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/infra/c4.d.ts +59 -0
  6. package/dist/infra/c4.d.ts.map +1 -0
  7. package/dist/infra/c4.js +101 -0
  8. package/dist/infra/c4.js.map +1 -0
  9. package/dist/infra/index.d.ts +13 -0
  10. package/dist/infra/index.d.ts.map +1 -0
  11. package/dist/infra/index.js +22 -0
  12. package/dist/infra/index.js.map +1 -0
  13. package/dist/infra/jsonc.d.ts +10 -0
  14. package/dist/infra/jsonc.d.ts.map +1 -0
  15. package/dist/infra/jsonc.js +77 -0
  16. package/dist/infra/jsonc.js.map +1 -0
  17. package/dist/infra/terraform.d.ts +41 -0
  18. package/dist/infra/terraform.d.ts.map +1 -0
  19. package/dist/infra/terraform.js +208 -0
  20. package/dist/infra/terraform.js.map +1 -0
  21. package/dist/infra/types.d.ts +107 -0
  22. package/dist/infra/types.d.ts.map +1 -0
  23. package/dist/infra/types.js +47 -0
  24. package/dist/infra/types.js.map +1 -0
  25. package/dist/infra/wrangler.d.ts +24 -0
  26. package/dist/infra/wrangler.d.ts.map +1 -0
  27. package/dist/infra/wrangler.js +116 -0
  28. package/dist/infra/wrangler.js.map +1 -0
  29. package/dist/node.d.ts +2 -0
  30. package/dist/node.d.ts.map +1 -1
  31. package/dist/node.js +3 -1
  32. package/dist/node.js.map +1 -1
  33. package/dist/storage/topic-share.d.ts +57 -0
  34. package/dist/storage/topic-share.d.ts.map +1 -0
  35. package/dist/storage/topic-share.js +55 -0
  36. package/dist/storage/topic-share.js.map +1 -0
  37. package/package.json +1 -1
  38. package/src/index.ts +6 -0
  39. package/src/infra/c4.ts +141 -0
  40. package/src/infra/index.ts +21 -0
  41. package/src/infra/infra.test.ts +300 -0
  42. package/src/infra/jsonc.ts +70 -0
  43. package/src/infra/terraform.ts +251 -0
  44. package/src/infra/types.ts +136 -0
  45. package/src/infra/wrangler.ts +148 -0
  46. package/src/node.ts +2 -0
  47. package/src/storage/topic-share.test.ts +71 -0
  48. package/src/storage/topic-share.ts +91 -0
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Infrastructure-as-code read side — what a config file *declares* and what a
3
+ * live account was *observed* to be running.
4
+ *
5
+ * Two facts, kept apart on purpose:
6
+ *
7
+ * - **Configured** ({@link InfraManifest}) is a static parse of a file at a
8
+ * commit. No credentials, always available, verifiable like source.
9
+ * - **Deployed** ({@link InfraDeploymentObservation}) is an observation of
10
+ * the live account. It needs credentials, carries a timestamp, and goes
11
+ * stale. Nothing here fetches one; the tooling that does is separate and
12
+ * only has to produce this shape.
13
+ *
14
+ * Everything in this folder is pure and browser-safe: extractors take text or
15
+ * parsed JSON, never a path.
16
+ */
17
+ /** The tool whose file declared a resource. */
18
+ export type InfraTool = 'wrangler' | 'terraform';
19
+ /** Where a declaration lives — the infra analogue of `file` + `symbol`. */
20
+ export interface InfraResourceSource {
21
+ tool: InfraTool;
22
+ /** Repo-root-relative path of the file the caller parsed. */
23
+ file: string;
24
+ /**
25
+ * Location inside that file. A JSON pointer for wrangler
26
+ * (`/r2_buckets/0`), a resource address for terraform
27
+ * (`cloudflare_r2_bucket.blobs`).
28
+ */
29
+ pointer: string;
30
+ }
31
+ /** One declared piece of infrastructure. */
32
+ export interface InfraResource {
33
+ /**
34
+ * Stable identity, `<provider>:<resourceType>:<identifier>` — e.g.
35
+ * `cloudflare:worker:topic-share`. Chosen so the same resource declared by
36
+ * two tools yields the same key; observations join on it.
37
+ */
38
+ key: string;
39
+ /** Hosting provider, lowercase: `cloudflare`. */
40
+ provider: string;
41
+ /** Provider-neutral-ish type: `worker`, `r2_bucket`, `d1_database`, `kv_namespace`, `queue`. */
42
+ resourceType: string;
43
+ /** The provider's own name or id for the resource. */
44
+ name: string;
45
+ /** What to show a reader. Falls back to the binding name when the provider name is an opaque id. */
46
+ label: string;
47
+ source: InfraResourceSource;
48
+ /** Small declared facts worth showing (`crons`, `assets`, `id`). Never secrets or env values. */
49
+ attributes?: Record<string, string>;
50
+ }
51
+ /** A declared access path from one resource to another — a Worker's binding. */
52
+ export interface InfraBinding {
53
+ /** Key of the resource that holds the binding (the Worker). */
54
+ from: string;
55
+ /** Key of the resource it reaches. May name a resource no parsed file declares. */
56
+ to: string;
57
+ /** The name code uses, e.g. `TOPIC_BLOBS` for `env.TOPIC_BLOBS`. */
58
+ binding: string;
59
+ source: InfraResourceSource;
60
+ }
61
+ /** Everything one or more config files declare. */
62
+ export interface InfraManifest {
63
+ resources: InfraResource[];
64
+ bindings: InfraBinding[];
65
+ }
66
+ /**
67
+ * Whether a resource was found live.
68
+ *
69
+ * `unknown` means the check could not be made (no permission, network
70
+ * failure). It is deliberately not `not-found`: a failed check must never read
71
+ * as "not deployed".
72
+ */
73
+ export type InfraDeploymentStatus = 'deployed' | 'not-found' | 'unknown';
74
+ /**
75
+ * One observation of one resource in a live account.
76
+ *
77
+ * Produced by credentialed tooling outside this package. Carries no
78
+ * credential, token, or environment value.
79
+ */
80
+ export interface InfraDeploymentObservation {
81
+ /** Joins to {@link InfraResource.key}. */
82
+ resourceKey: string;
83
+ status: InfraDeploymentStatus;
84
+ /** Provider id, e.g. a D1 database id. */
85
+ resourceId?: string;
86
+ /** Where the running thing answers — workers.dev, routes, custom domains. */
87
+ liveUrls?: string[];
88
+ /** The provider dashboard page for this resource. */
89
+ consoleUrl?: string;
90
+ /** Deployed version or deployment id, when the provider exposes one. */
91
+ version?: string;
92
+ /** When that version went live (ISO). */
93
+ deployedAt?: string;
94
+ /** When we looked (ISO). Required so a view can show staleness. */
95
+ observedAt: string;
96
+ /** Who said so: `cloudflare-api`, `terraform-state`, `authored`. */
97
+ source: string;
98
+ }
99
+ /** Build a resource key. Exported so observers produce the same string. */
100
+ export declare function infraResourceKey(provider: string, resourceType: string, identifier: string): string;
101
+ /**
102
+ * Merge manifests from several files. The first declaration of a key wins, so
103
+ * pass the more authoritative file first; bindings are de-duplicated on
104
+ * `from` + `to` + `binding`.
105
+ */
106
+ export declare function mergeInfraManifests(manifests: readonly InfraManifest[]): InfraManifest;
107
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/infra/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,+CAA+C;AAC/C,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;AAEjD,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,YAAY,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,oGAAoG;IACpG,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,mBAAmB,CAAC;IAC5B,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,0CAA0C;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,aAAa,EAAE,GAClC,aAAa,CAaf"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Infrastructure-as-code read side — what a config file *declares* and what a
4
+ * live account was *observed* to be running.
5
+ *
6
+ * Two facts, kept apart on purpose:
7
+ *
8
+ * - **Configured** ({@link InfraManifest}) is a static parse of a file at a
9
+ * commit. No credentials, always available, verifiable like source.
10
+ * - **Deployed** ({@link InfraDeploymentObservation}) is an observation of
11
+ * the live account. It needs credentials, carries a timestamp, and goes
12
+ * stale. Nothing here fetches one; the tooling that does is separate and
13
+ * only has to produce this shape.
14
+ *
15
+ * Everything in this folder is pure and browser-safe: extractors take text or
16
+ * parsed JSON, never a path.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.mergeInfraManifests = exports.infraResourceKey = void 0;
20
+ /** Build a resource key. Exported so observers produce the same string. */
21
+ function infraResourceKey(provider, resourceType, identifier) {
22
+ return `${provider}:${resourceType}:${identifier}`;
23
+ }
24
+ exports.infraResourceKey = infraResourceKey;
25
+ /**
26
+ * Merge manifests from several files. The first declaration of a key wins, so
27
+ * pass the more authoritative file first; bindings are de-duplicated on
28
+ * `from` + `to` + `binding`.
29
+ */
30
+ function mergeInfraManifests(manifests) {
31
+ const resources = new Map();
32
+ const bindings = new Map();
33
+ for (const manifest of manifests) {
34
+ for (const resource of manifest.resources) {
35
+ if (!resources.has(resource.key))
36
+ resources.set(resource.key, resource);
37
+ }
38
+ for (const binding of manifest.bindings) {
39
+ const id = `${binding.from}\u0000${binding.to}\u0000${binding.binding}`;
40
+ if (!bindings.has(id))
41
+ bindings.set(id, binding);
42
+ }
43
+ }
44
+ return { resources: [...resources.values()], bindings: [...bindings.values()] };
45
+ }
46
+ exports.mergeInfraManifests = mergeInfraManifests;
47
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/infra/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AA2FH,2EAA2E;AAC3E,SAAgB,gBAAgB,CAC9B,QAAgB,EAChB,YAAoB,EACpB,UAAkB;IAElB,OAAO,GAAG,QAAQ,IAAI,YAAY,IAAI,UAAU,EAAE,CAAC;AACrD,CAAC;AAND,4CAMC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CACjC,SAAmC;IAEnC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IACjD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC,SAAS,EAAE;YACzC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;SACzE;QACD,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE;YACvC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,SAAS,OAAO,CAAC,EAAE,SAAS,OAAO,CAAC,OAAO,EAAE,CAAC;YACxE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;SAClD;KACF;IACD,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;AAClF,CAAC;AAfD,kDAeC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Wrangler config → {@link InfraManifest}.
3
+ *
4
+ * A `wrangler.jsonc` declares one Worker and the resources it binds. That maps
5
+ * cleanly: the Worker is a resource, each bound store is a resource, and each
6
+ * binding is the access path between them — named exactly as code names it
7
+ * (`env.TOPIC_BLOBS`), which is what makes the binding a join to trail steps.
8
+ *
9
+ * Top-level config only. Named environments (`env.staging`) are not read yet.
10
+ */
11
+ import { type InfraManifest } from './types';
12
+ export interface ExtractWranglerOptions {
13
+ /** Repo-root-relative path of the config, recorded on every source. */
14
+ file: string;
15
+ }
16
+ /**
17
+ * Read a wrangler config. Accepts JSONC text or an already-parsed object, so a
18
+ * caller holding a `wrangler.toml` can parse it and pass the result.
19
+ *
20
+ * Returns an empty manifest when the config names no Worker. Malformed JSONC
21
+ * text throws `SyntaxError`.
22
+ */
23
+ export declare function extractWranglerManifest(config: string | unknown, options: ExtractWranglerOptions): InfraManifest;
24
+ //# sourceMappingURL=wrangler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../../src/infra/wrangler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,SAAS,CAAC;AA+CjB,MAAM,WAAW,sBAAsB;IACrC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,OAAO,EAAE,sBAAsB,GAC9B,aAAa,CAmEf"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ /**
3
+ * Wrangler config → {@link InfraManifest}.
4
+ *
5
+ * A `wrangler.jsonc` declares one Worker and the resources it binds. That maps
6
+ * cleanly: the Worker is a resource, each bound store is a resource, and each
7
+ * binding is the access path between them — named exactly as code names it
8
+ * (`env.TOPIC_BLOBS`), which is what makes the binding a join to trail steps.
9
+ *
10
+ * Top-level config only. Named environments (`env.staging`) are not read yet.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.extractWranglerManifest = void 0;
14
+ const jsonc_1 = require("./jsonc");
15
+ const types_1 = require("./types");
16
+ const PROVIDER = 'cloudflare';
17
+ function isObject(value) {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ }
20
+ function str(value) {
21
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
22
+ }
23
+ const BINDING_FAMILIES = [
24
+ { path: ['kv_namespaces'], resourceType: 'kv_namespace', bindingField: 'binding', identifierField: 'id' },
25
+ { path: ['r2_buckets'], resourceType: 'r2_bucket', bindingField: 'binding', identifierField: 'bucket_name' },
26
+ {
27
+ path: ['d1_databases'],
28
+ resourceType: 'd1_database',
29
+ bindingField: 'binding',
30
+ identifierField: 'database_name',
31
+ idField: 'database_id',
32
+ },
33
+ { path: ['queues', 'producers'], resourceType: 'queue', bindingField: 'binding', identifierField: 'queue' },
34
+ { path: ['services'], resourceType: 'worker', bindingField: 'binding', identifierField: 'service' },
35
+ ];
36
+ /** A KV namespace is declared by opaque id only, so the binding names it. */
37
+ const OPAQUE_IDENTIFIER = new Set(['kv_namespace']);
38
+ /**
39
+ * Read a wrangler config. Accepts JSONC text or an already-parsed object, so a
40
+ * caller holding a `wrangler.toml` can parse it and pass the result.
41
+ *
42
+ * Returns an empty manifest when the config names no Worker. Malformed JSONC
43
+ * text throws `SyntaxError`.
44
+ */
45
+ function extractWranglerManifest(config, options) {
46
+ const root = typeof config === 'string' ? (0, jsonc_1.parseJsonc)(config) : config;
47
+ if (!isObject(root))
48
+ return { resources: [], bindings: [] };
49
+ const workerName = str(root.name);
50
+ if (!workerName)
51
+ return { resources: [], bindings: [] };
52
+ const source = (pointer) => ({
53
+ tool: 'wrangler',
54
+ file: options.file,
55
+ pointer,
56
+ });
57
+ const workerKey = (0, types_1.infraResourceKey)(PROVIDER, 'worker', workerName);
58
+ const workerAttributes = {};
59
+ const main = str(root.main);
60
+ if (main)
61
+ workerAttributes.main = main;
62
+ if (isObject(root.assets))
63
+ workerAttributes.assets = 'true';
64
+ const crons = isObject(root.triggers) ? root.triggers.crons : undefined;
65
+ if (Array.isArray(crons) && crons.length > 0) {
66
+ workerAttributes.crons = crons.filter((c) => typeof c === 'string').join(', ');
67
+ }
68
+ const resources = [
69
+ {
70
+ key: workerKey,
71
+ provider: PROVIDER,
72
+ resourceType: 'worker',
73
+ name: workerName,
74
+ label: workerName,
75
+ source: source(''),
76
+ ...(Object.keys(workerAttributes).length > 0 ? { attributes: workerAttributes } : {}),
77
+ },
78
+ ];
79
+ const bindings = [];
80
+ for (const family of BINDING_FAMILIES) {
81
+ let entries = root;
82
+ for (const segment of family.path) {
83
+ entries = isObject(entries) ? entries[segment] : undefined;
84
+ }
85
+ if (!Array.isArray(entries))
86
+ continue;
87
+ entries.forEach((entry, index) => {
88
+ if (!isObject(entry))
89
+ return;
90
+ const binding = str(entry[family.bindingField]);
91
+ const identifier = str(entry[family.identifierField]);
92
+ if (!binding || !identifier)
93
+ return;
94
+ const pointer = `/${family.path.join('/')}/${index}`;
95
+ const key = (0, types_1.infraResourceKey)(PROVIDER, family.resourceType, identifier);
96
+ const id = family.idField ? str(entry[family.idField]) : undefined;
97
+ // A service binding points at another Worker, which its own config
98
+ // declares; emit the access path but not a second declaration of it.
99
+ if (family.resourceType !== 'worker') {
100
+ resources.push({
101
+ key,
102
+ provider: PROVIDER,
103
+ resourceType: family.resourceType,
104
+ name: identifier,
105
+ label: OPAQUE_IDENTIFIER.has(family.resourceType) ? binding : identifier,
106
+ source: source(pointer),
107
+ ...(id ? { attributes: { id } } : {}),
108
+ });
109
+ }
110
+ bindings.push({ from: workerKey, to: key, binding, source: source(pointer) });
111
+ });
112
+ }
113
+ return { resources, bindings };
114
+ }
115
+ exports.extractWranglerManifest = extractWranglerManifest;
116
+ //# sourceMappingURL=wrangler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrangler.js","sourceRoot":"","sources":["../../src/infra/wrangler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAqC;AACrC,mCAMiB;AAEjB,MAAM,QAAQ,GAAG,YAAY,CAAC;AAI9B,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAkBD,MAAM,gBAAgB,GAA6B;IACjD,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE;IAC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AY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU;oBACxE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;oBACvB,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACtC,CAAC,CAAC;aACJ;YACD,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAChF,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC;AAtED,0DAsEC"}
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,CAA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b,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.7",
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,12 @@ 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';
26
+
27
+ // Infrastructure-as-code read side: what wrangler / terraform declare, and the
28
+ // shape a live-deployment observation takes. Pure — text and JSON in.
29
+ export * from './infra';
24
30
 
25
31
  // Cross-field validation (the rules the JSON Schema can't express). Structural
26
32
  // (schema) validation is enforced per surface against
@@ -0,0 +1,141 @@
1
+ /**
2
+ * {@link InfraManifest} → proposed C4 containers and edges.
3
+ *
4
+ * The full C4 model lives in the viewer package, which depends on this one, so
5
+ * the shapes here are structural: they are assignable to the viewer's
6
+ * `C4Container` / `C4Edge` without this package importing them (the same
7
+ * arrangement as `audit/c4.ts`).
8
+ *
9
+ * Everything produced is `proposed`. A config file is evidence that a
10
+ * deployable unit exists, not a reviewer's acceptance of it as architecture.
11
+ */
12
+
13
+ import type { InfraManifest, InfraResource, InfraResourceSource } from './types';
14
+
15
+ /**
16
+ * The configured anchor a container carries — which declared resource it is.
17
+ * Holds no live fact: whether it is running is a separate observation, joined
18
+ * on `resourceKey`.
19
+ */
20
+ export interface InfraC4Deployment {
21
+ resourceKey: string;
22
+ provider: string;
23
+ resourceType: string;
24
+ name: string;
25
+ source: InfraResourceSource;
26
+ }
27
+
28
+ export interface InfraC4Container {
29
+ id: string;
30
+ kind: 'container';
31
+ containerKind: 'application' | 'data-store';
32
+ label: string;
33
+ technology: string;
34
+ state: 'proposed';
35
+ rationale: string;
36
+ deployment: InfraC4Deployment;
37
+ }
38
+
39
+ export interface InfraC4Edge {
40
+ id: string;
41
+ source: string;
42
+ target: string;
43
+ label: string;
44
+ draft: true;
45
+ mechanisms: string[];
46
+ count: number;
47
+ }
48
+
49
+ const TECHNOLOGY: Record<string, string> = {
50
+ 'cloudflare:worker': 'Cloudflare Worker',
51
+ 'cloudflare:r2_bucket': 'Cloudflare R2',
52
+ 'cloudflare:d1_database': 'Cloudflare D1',
53
+ 'cloudflare:kv_namespace': 'Cloudflare KV',
54
+ 'cloudflare:queue': 'Cloudflare Queue',
55
+ };
56
+
57
+ /** Resource types that run code. Everything else is something code reads or writes. */
58
+ const APPLICATION_TYPES = new Set(['worker']);
59
+
60
+ /** Short suffix that keeps a store's id distinct from a same-named Worker. */
61
+ const ID_SUFFIX: Record<string, string> = {
62
+ r2_bucket: 'r2',
63
+ d1_database: 'd1',
64
+ kv_namespace: 'kv',
65
+ queue: 'queue',
66
+ };
67
+
68
+ function slug(text: string): string {
69
+ return text
70
+ .toLowerCase()
71
+ .replace(/[^a-z0-9]+/g, '-')
72
+ .replace(/^-+|-+$/g, '');
73
+ }
74
+
75
+ /** The stable C4 element id for a declared resource. */
76
+ export function infraContainerId(resource: Pick<InfraResource, 'resourceType' | 'label'>): string {
77
+ const suffix = ID_SUFFIX[resource.resourceType];
78
+ const base = slug(resource.label) || 'resource';
79
+ return `container:${suffix ? `${base}-${suffix}` : base}`;
80
+ }
81
+
82
+ /** The configured anchor for one resource. */
83
+ export function infraDeploymentRef(resource: InfraResource): InfraC4Deployment {
84
+ return {
85
+ resourceKey: resource.key,
86
+ provider: resource.provider,
87
+ resourceType: resource.resourceType,
88
+ name: resource.name,
89
+ source: resource.source,
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Propose one container per declared resource and one edge per binding.
95
+ *
96
+ * A binding whose target no parsed file declares (a service binding to a
97
+ * Worker configured elsewhere) is dropped rather than drawn to nothing; merge
98
+ * the other config's manifest in first to keep it.
99
+ */
100
+ export function infraToC4(manifest: InfraManifest): {
101
+ nodes: InfraC4Container[];
102
+ edges: InfraC4Edge[];
103
+ } {
104
+ const idByKey = new Map<string, string>();
105
+ const nodes = manifest.resources.map((resource): InfraC4Container => {
106
+ const id = infraContainerId(resource);
107
+ idByKey.set(resource.key, id);
108
+ const where = resource.source.pointer
109
+ ? `${resource.source.file} at ${resource.source.pointer}`
110
+ : resource.source.file;
111
+ return {
112
+ id,
113
+ kind: 'container',
114
+ containerKind: APPLICATION_TYPES.has(resource.resourceType) ? 'application' : 'data-store',
115
+ label: resource.label,
116
+ technology:
117
+ TECHNOLOGY[`${resource.provider}:${resource.resourceType}`] ??
118
+ `${resource.provider} ${resource.resourceType}`,
119
+ state: 'proposed',
120
+ rationale: `Declared by ${resource.source.tool} in ${where}.`,
121
+ deployment: infraDeploymentRef(resource),
122
+ };
123
+ });
124
+
125
+ const edges: InfraC4Edge[] = [];
126
+ for (const binding of manifest.bindings) {
127
+ const source = idByKey.get(binding.from);
128
+ const target = idByKey.get(binding.to);
129
+ if (!source || !target) continue;
130
+ edges.push({
131
+ id: `edge:${source}->${target}:${binding.binding}`,
132
+ source,
133
+ target,
134
+ label: `env.${binding.binding}`,
135
+ draft: true,
136
+ mechanisms: [],
137
+ count: 0,
138
+ });
139
+ }
140
+ return { nodes, edges };
141
+ }