@synap-core/workspace-templates 0.5.0 → 0.6.1

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
@@ -1,24 +1,741 @@
1
1
  /**
2
- * @synap-core/workspace-templates
2
+ * @synap-core/workspace-templates — Types
3
3
  *
4
- * Canonical workspace template definitions.
5
- * ==========================================
4
+ * Canonical shape of a workspace template.
5
+ * YAML source files validate against these types.
6
+ * Every consumer (browser, backend, CLI, marketplace) imports from here.
7
+ */
8
+ type TemplateAppKind = 'native' | 'stored' | 'url';
9
+ interface TemplateAppRef {
10
+ kind: TemplateAppKind;
11
+ /** For kind='native': the appId registered in the browser manifest */
12
+ appId?: string;
13
+ /** For kind='native': how the platform renders the app */
14
+ rendererType?: 'native' | 'external' | 'iframe-srcdoc';
15
+ /** For kind='stored': the cell key registered in the cell registry */
16
+ cellKey?: string;
17
+ /** For kind='stored': default props passed to the cell */
18
+ props?: Record<string, unknown>;
19
+ /** For kind='url': external URL to open */
20
+ url?: string;
21
+ /** Human label */
22
+ title?: string;
23
+ }
24
+ interface TemplateProperty {
25
+ slug: string;
26
+ label: string;
27
+ valueType: string;
28
+ inputType?: string;
29
+ placeholder?: string;
30
+ enumValues?: string[];
31
+ constraints?: Record<string, unknown>;
32
+ targetProfileSlug?: string;
33
+ }
34
+ interface TemplateProfile {
35
+ slug: string;
36
+ displayName: string;
37
+ icon?: string;
38
+ color?: string;
39
+ description?: string;
40
+ /** Visibility scope. Omit or "WORKSPACE" for workspace-scoped. */
41
+ scope?: string;
42
+ /** Semantic slug for system profiles. */
43
+ semanticSlug?: string;
44
+ /** Kind vs role profile. Omit for default ('kind'). */
45
+ profileKind?: "kind" | "role";
46
+ /** For profileKind='role': which base-kind profile slugs this role can attach to. */
47
+ applicableKinds?: string[];
48
+ properties: TemplateProperty[];
49
+ }
50
+ interface TemplateView {
51
+ name: string;
52
+ slug?: string;
53
+ type: string;
54
+ scopeProfileSlug?: string;
55
+ scopeProfileSlugs?: string[];
56
+ config?: Record<string, unknown>;
57
+ /** If true, this view auto-selected as the default view for this workspace */
58
+ defaultView?: boolean;
59
+ description?: string;
60
+ groupBy?: string;
61
+ }
62
+ interface TemplateEntityLink {
63
+ sourceProfileSlug: string;
64
+ targetProfileSlug: string;
65
+ type: string;
66
+ label?: string;
67
+ }
68
+ interface TemplateSeedEntity {
69
+ profileSlug: string;
70
+ title: string;
71
+ properties?: Record<string, unknown>;
72
+ content?: string;
73
+ }
74
+ /**
75
+ * Relations between seed entities, created on provisioning. `sourceRef`/
76
+ * `targetRef` reference seed-entity titles (or refs) defined in `seedEntities`.
77
+ * Mirrors `suggestedRelations` in synap-backend `create-workspace-from-definition.ts`.
78
+ */
79
+ interface TemplateSuggestedRelation {
80
+ sourceRef: string;
81
+ targetRef: string;
82
+ type: string;
83
+ metadata?: Record<string, unknown>;
84
+ }
85
+ /**
86
+ * Entity-card display templates. Mirrors `displayTemplates` in synap-backend
87
+ * `create-workspace-from-definition.ts`.
88
+ */
89
+ interface TemplateDisplayTemplate {
90
+ name: string;
91
+ description?: string;
92
+ entityType?: string;
93
+ targetType?: string;
94
+ isDefault?: boolean;
95
+ config: Record<string, unknown>;
96
+ }
97
+ interface TemplateSidebarSurface {
98
+ kind: 'cell' | 'view' | 'entity' | 'document' | 'channel' | 'app' | 'url';
99
+ cellKey?: string;
100
+ viewId?: string;
101
+ viewName?: string;
102
+ appId?: string;
103
+ url?: string;
104
+ rendererType?: 'native' | 'external' | 'iframe-srcdoc';
105
+ placement?: 'main' | 'side' | 'floating' | 'modal' | 'popover' | 'embed';
106
+ displayMode?: 'compact' | 'medium' | 'full';
107
+ props?: Record<string, unknown>;
108
+ title?: string;
109
+ meta?: Record<string, unknown>;
110
+ }
111
+ interface TemplateSidebarItem {
112
+ kind: 'app' | 'view' | 'profile' | 'external' | 'cell';
113
+ appId?: string;
114
+ viewName?: string;
115
+ viewId?: string;
116
+ profileSlug?: string;
117
+ url?: string;
118
+ cellKey?: string;
119
+ cellProps?: Record<string, unknown>;
120
+ /** When present, bypasses kind-based dispatch — full surface control */
121
+ surface?: TemplateSidebarSurface;
122
+ label?: string;
123
+ icon?: string;
124
+ section?: string;
125
+ matchUrls?: string[];
126
+ }
127
+ interface TemplateLayoutConfig {
128
+ pinnedApps?: string[];
129
+ defaultView?: string;
130
+ /** The first-screen app — auto-opened on workspace switch */
131
+ defaultApp?: string | null;
132
+ theme?: string;
133
+ sidebarItems?: TemplateSidebarItem[];
134
+ }
135
+ interface TemplateBentoBlock {
136
+ kind: 'view' | 'widget';
137
+ viewName?: string;
138
+ widgetType?: string;
139
+ pos: {
140
+ x: number;
141
+ y: number;
142
+ w: number;
143
+ h: number;
144
+ };
145
+ config?: Record<string, unknown>;
146
+ overrides?: Record<string, unknown>;
147
+ }
148
+ interface TemplateProfileEntityBentoTemplates {
149
+ [profileSlug: string]: {
150
+ blocks: Array<Record<string, unknown>>;
151
+ };
152
+ }
153
+ interface TemplateAutomation {
154
+ name: string;
155
+ description?: string;
156
+ trigger: string;
157
+ action: string;
158
+ config?: Record<string, unknown>;
159
+ }
160
+ /** Mirrors `WorkspaceSourceRole` in synap-backend `schema/workspaces.ts`. */
161
+ type TemplateSourceRole = 'provider' | 'consumer' | 'provider-consumer';
162
+ /** Mirrors `WorkspaceDefaultSource` in synap-backend `schema/workspaces.ts`. */
163
+ interface TemplateDefaultSource {
164
+ /** The workspace id that supplies this capability domain. */
165
+ workspaceId: string;
166
+ /** The capability domain this source satisfies (e.g. "brand", "strategy"). */
167
+ capability?: string;
168
+ /** Optional profile slug the source resolves to. */
169
+ profileSlug?: string;
170
+ /** Human label for the source. */
171
+ label?: string;
172
+ }
173
+ interface TemplateOnboardingCollectTarget {
174
+ /** Profile slug to populate (e.g. "audience", "competitor"). */
175
+ profileSlug: string;
176
+ /** Human description of what to capture for this target. */
177
+ what: string;
178
+ /** Roughly how many to expect — guides interview depth. */
179
+ cardinality?: 'one' | 'few' | 'several';
180
+ /** Key fields the agent should make sure to fill. */
181
+ keyFields?: string[];
182
+ }
183
+ interface TemplateOnboardingExpertise {
184
+ /**
185
+ * Concrete starting points the agent PROPOSES instead of asking blank —
186
+ * "most X do Y, want that as a starting point?". Grounds the agent's
187
+ * proposals in real domain knowledge (never fabricates strategy — for
188
+ * mission/positioning these FRAME, they don't invent the answer).
189
+ */
190
+ starters?: string[];
191
+ /**
192
+ * Blind spots founders in this domain commonly miss. The agent proactively
193
+ * surfaces these if the founder hasn't — catching what they don't say.
194
+ */
195
+ blindSpots?: string[];
196
+ /** What a GREAT result looks like here — the bar the agent pushes toward. */
197
+ bar?: string;
198
+ }
199
+ interface TemplateOnboarding {
200
+ /** The outcome this onboarding achieves, in one sentence. */
201
+ goal: string;
202
+ /** Domain framing/voice the agent adopts for THIS workspace (the persona). */
203
+ framing: string;
204
+ /**
205
+ * Authored domain expertise the agent leads with (optional). Turns the
206
+ * interview from "extract what the founder knows" into "resolve what they
207
+ * lack". See the `onboard` skill's "Lead with your expertise" step.
208
+ */
209
+ expertise?: TemplateOnboardingExpertise;
210
+ /** What structured data to collect (entities to create + their key fields). */
211
+ collect: TemplateOnboardingCollectTarget[];
212
+ /** A few opening questions — the agent adapts from here, never rigid. */
213
+ openingQuestions?: string[];
214
+ /** "Done" signal the agent self-evaluates against. */
215
+ doneWhen?: string;
216
+ }
217
+ interface TemplatePlaybookParam {
218
+ name: string;
219
+ type: 'text' | 'number' | 'entity' | 'choice' | 'boolean';
220
+ label?: string;
221
+ required?: boolean;
222
+ defaultValue?: unknown;
223
+ }
224
+ interface TemplatePlaybook {
225
+ name: string;
226
+ description?: string;
227
+ goalTemplate: string;
228
+ params?: TemplatePlaybookParam[];
229
+ executor?: 'is-agent' | 'external-agent' | 'hybrid';
230
+ inputStrategy?: 'none' | 'static' | 'rotating' | 'query';
231
+ channelSpec?: {
232
+ type: 'GROUP' | 'AGENT_COLLAB' | 'THREAD';
233
+ members?: string[];
234
+ aiReactionMode?: 'on_mention' | 'always' | 'never';
235
+ };
236
+ schedule?: {
237
+ cron: string;
238
+ } | null;
239
+ /** tool/skill keys this playbook grants. */
240
+ grants?: string[];
241
+ status?: 'draft' | 'active' | 'paused';
242
+ }
243
+ interface TemplateIntegration {
244
+ /** Capability template key to install (matches a capability template). */
245
+ templateKey: string;
246
+ /** Override default params with {{var}} interpolation. */
247
+ params?: Record<string, string>;
248
+ /** "apply" (create+update) or "install" (create only). */
249
+ mode?: 'apply' | 'install';
250
+ }
251
+ interface TemplateExtendsRef {
252
+ source: string;
253
+ import?: {
254
+ profiles?: string[];
255
+ views?: string[];
256
+ };
257
+ }
258
+ /**
259
+ * A dependency this template declares on ANOTHER template/package. The install
260
+ * resolver (backend `POST /api/hub/packages/apply`) reads these to build the
261
+ * pod's template graph: every dependency is ensured present before this
262
+ * template is applied — missing ones install first (topologically) — and a
263
+ * `compose` dependency LAYERS this template's schema additively onto the
264
+ * dependency's workspace instead of creating a second workspace.
265
+ *
266
+ * This is the general composition primitive: a BASE template carries the
267
+ * agnostic data model; an OVERLAY template `compose`s onto it and adds the
268
+ * use-case-specific data (e.g. `blockchain-ecosystem` → `ecosystem`,
269
+ * `grants` → `operations`). Distinct from `extends` (which imports from a live
270
+ * workspace, tRPC-only) — `dependencies` is template→template.
271
+ */
272
+ /**
273
+ * PACKAGE_DEPENDENCY_KINDS — the dependency-kind vocabulary, declared ONCE.
274
+ *
275
+ * This tuple exists so consumers can IMPORT the vocabulary instead of
276
+ * hand-copying it. `TemplateDependency` is currently mirrored by hand in six
277
+ * other places, four of which carry a comment promising they match "VERBATIM so
278
+ * the wire shape never drifts" — a comment doing a type's job. A comment cannot
279
+ * fail a build; an import can. Those mirrors live in repos this package does not
280
+ * own, so this tuple does not fix them by existing — it makes the fix possible:
281
+ *
282
+ * - marketplace `types.ts:102`
283
+ * - onboarding `workspace-templates.ts:27`
284
+ * - synap-backend `package-definition.ts:204` (exports its own
285
+ * `PackageDependencyKind` — the closest peer)
286
+ * - hub-protocol REST `rest/packages.ts:140` (zod enum)
287
+ * - browser `InstallPackageDialog.tsx:262`
288
+ * - control-plane-api `routes/packages.ts:436` (zod enum)
289
+ *
290
+ * ⚠️ `'automation'` IS RETIRED VOCABULARY, deliberately still listed here.
291
+ * CP migration `0049_package_vocabulary` retired the `automation` package
292
+ * category in favour of `workflow` ("workflow — a triggered/sequenced run
293
+ * (absorbs 'automation' + 'playbook')", `PACKAGE_TYPES` in CP
294
+ * `db/schema/packages.ts`). A dependency's `kind` names the TYPE of package it
295
+ * points at, so this vocabulary should track `PACKAGE_TYPES` — meaning the live
296
+ * spelling is `workflow`, not `automation`.
297
+ *
298
+ * It is NOT renamed here, on purpose. This is latent, not live: 0/21 templates
299
+ * declare any `kind` other than the default `'workspace'`. And all four wire
300
+ * enums (CP + hub zod, above) still accept `'automation'` and do NOT accept
301
+ * `'workflow'` — so emitting `'workflow'` today would be rejected with a 400 at
302
+ * both doors, and dropping `'automation'` from this tuple would make any
303
+ * consumer that derives a zod enum from it start rejecting a value the wire
304
+ * still legally accepts (a published third-party package may carry it; CP's own
305
+ * schema permits it). Narrowing must therefore follow the wire, not lead it.
306
+ *
307
+ * ORDERED FIX (each step deployable alone, no flag day):
308
+ * 1. Widen the CP + hub zod enums to accept BOTH `'automation'` and `'workflow'`.
309
+ * 2. Add `'workflow'` here; mark `'automation'` deprecated; migrate any authored use.
310
+ * 3. Once no payload carries `'automation'`, drop it from the wire enums and this tuple.
311
+ */
312
+ declare const PACKAGE_DEPENDENCY_KINDS: readonly ["workspace", "capability", "automation"];
313
+ /** What a `TemplateDependency` points at. Derived — never re-declare the list. */
314
+ type PackageDependencyKind = (typeof PACKAGE_DEPENDENCY_KINDS)[number];
315
+ interface TemplateDependency {
316
+ /** Slug of the template/package this one depends on. */
317
+ slug: string;
318
+ /**
319
+ * What the dependency is. Default `'workspace'`. Only `'workspace'`
320
+ * dependencies can be `compose`d; `'capability'`/`'automation'` are always
321
+ * `require`d present without merging.
322
+ */
323
+ kind?: PackageDependencyKind;
324
+ /**
325
+ * How this template relates to the dependency:
326
+ * - `'compose'`: this template is an OVERLAY on the dependency's workspace.
327
+ * The base is installed first if absent, then this template's profiles /
328
+ * roles / relations / views are applied ADDITIVELY onto the base workspace
329
+ * — no separate workspace is created for this template.
330
+ * - `'require'` (default): the dependency must be present on the pod as its
331
+ * own artifact, but this template does not merge into it.
332
+ */
333
+ relation?: 'compose' | 'require';
334
+ /**
335
+ * Short human reason shown in the install-time "this also installs…" prompt.
336
+ */
337
+ reason?: string;
338
+ }
339
+ interface TemplateMeta {
340
+ slug: string;
341
+ name: string;
342
+ description: string;
343
+ icon: string;
344
+ color: string;
345
+ tags?: string[];
346
+ isPublic?: boolean;
347
+ }
348
+ interface WorkspaceYaml {
349
+ /** Template metadata — not sent to backend, used for listing/UI */
350
+ meta: TemplateMeta;
351
+ /** The workspace definition sent to createFromDefinition */
352
+ workspace: {
353
+ name: string;
354
+ description: string;
355
+ proposalId?: string;
356
+ subtype?: string;
357
+ /**
358
+ * Workspace classifier — consumed by createFromDefinition (settings.workspaceType,
359
+ * creator-role + agent-workspace behavior). Mirrors the backend union.
360
+ */
361
+ workspaceType?: 'personal' | 'agent' | 'project' | 'operational';
362
+ visibility?: string;
363
+ /** Capabilities this workspace provides (e.g. "brand.library", "content.pipeline") */
364
+ capabilities?: string[];
365
+ /**
366
+ * Cross-workspace dependency roles.
367
+ * E.g. { brand: "consumer", content: "provider" }
368
+ * "consumer" = this workspace reads from another workspace of that capability
369
+ * "provider" = this workspace provides that capability to others
370
+ */
371
+ sourceRoles?: Record<string, TemplateSourceRole>;
372
+ /**
373
+ * Pins which workspace supplies each capability domain for this workspace.
374
+ * E.g. { brand: { workspaceId: "..." } } — read by the IS source resolver
375
+ * (resolveBrandWorkspaceId / resolveFoundationWorkspaceId) before falling
376
+ * back to provider role. Usually set at runtime, not in a template, but
377
+ * carried here so it round-trips through the canonical seam.
378
+ */
379
+ defaultSources?: Record<string, TemplateDefaultSource>;
380
+ };
381
+ /** Entity profiles — the data schema */
382
+ profiles: TemplateProfile[];
383
+ /** Curated views — only the ones that add value */
384
+ views?: TemplateView[];
385
+ /** Schema-level links between entity types */
386
+ entityLinks?: TemplateEntityLink[];
387
+ /** Initial data to seed on workspace creation */
388
+ seedEntities?: TemplateSeedEntity[];
389
+ /** Relations between seed entities, created on provisioning */
390
+ suggestedRelations?: TemplateSuggestedRelation[];
391
+ /** Entity-card display templates */
392
+ displayTemplates?: TemplateDisplayTemplate[];
393
+ /** App reference — what opens as first screen */
394
+ app?: TemplateAppRef;
395
+ /** Browser sidebar + layout config */
396
+ layout?: TemplateLayoutConfig;
397
+ /** Bento dashboard */
398
+ bento?: {
399
+ viewName?: string;
400
+ blocks?: TemplateBentoBlock[];
401
+ };
402
+ /** Per-profile entity bento layouts */
403
+ profileEntityBentoTemplates?: TemplateProfileEntityBentoTemplates;
404
+ /** Automations to install on workspace creation */
405
+ automations?: TemplateAutomation[];
406
+ /** Playbooks (session templates) seeded with the workspace */
407
+ playbooks?: TemplatePlaybook[];
408
+ /** Capability templates (tools/connectors) to install on provisioning */
409
+ integrations?: TemplateIntegration[];
410
+ /**
411
+ * Per-workspace onboarding context. Written to workspace.settings.onboarding
412
+ * and read by the shared `onboard` skill to run a domain-specific adaptive
413
+ * interview — no per-domain skill file needed.
414
+ */
415
+ onboarding?: TemplateOnboarding;
416
+ /** Inherit profiles/views from other workspaces */
417
+ extends?: TemplateExtendsRef[];
418
+ /**
419
+ * Template-composition dependencies — other templates this one needs. The
420
+ * install resolver installs missing dependencies first and, for a `compose`
421
+ * dependency, layers this template additively onto the dependency's
422
+ * workspace. See {@link TemplateDependency}.
423
+ */
424
+ dependencies?: TemplateDependency[];
425
+ }
426
+
427
+ declare const WORKSPACE_TEMPLATES: Record<string, WorkspaceYaml>;
428
+ type WorkspaceTemplateSlug = keyof typeof WORKSPACE_TEMPLATES;
429
+ declare function getWorkspaceTemplate(slug: string): WorkspaceYaml | undefined;
430
+ declare function listWorkspaceTemplates(): WorkspaceYaml[];
431
+ /**
432
+ * Public templates only (`meta.isPublic !== false`). This is a CONVENIENCE
433
+ * filter for the default picker — NOT a security boundary: the private YAML
434
+ * still ships in the published tarball, so anything that must not leak cannot
435
+ * rely on this. `listWorkspaceTemplates()` returns all of them (CLI, seeder,
436
+ * tripwire need the full set). Publicity is also expressed per-entry as
437
+ * `CatalogEntry.isPrivate` by `mergeCatalog()`, so a caller can pass ALL
438
+ * templates and filter at the presentation layer instead of choosing a list
439
+ * function up front — the merge door itself never filters (it stays pure).
440
+ */
441
+ declare function listPublicTemplates(): WorkspaceYaml[];
442
+
443
+ /**
444
+ * mergeCatalog — the ONE merge door for the workspace-template catalog.
445
+ * ====================================================================
446
+ *
447
+ * Both marketplace entry points (browser + CLI) and the pod need to show ONE
448
+ * list of installable workspace templates drawn from TWO sources:
6
449
  *
7
- * Usage (browser / backend / CLI):
450
+ * 1. BUNDLED — the canonical `@synap-core/workspace-templates` package that
451
+ * ships inside every client (this package). Always present, zero network.
452
+ * 2. REMOTE — rows in the control-plane package registry (`GET /api/packages`),
453
+ * which includes both the official templates re-published by
454
+ * `seed-templates.ts` AND private / third-party packages that never shipped
455
+ * in the bundle.
8
456
  *
9
- * import { getWorkspaceTemplate, listPublicTemplates } from '@synap-core/workspace-templates';
457
+ * The two overlap: every official template exists in BOTH sources (once bundled,
458
+ * once seeded to the CP). Naively concatenating them shows 21 duplicate cards.
459
+ * `mergeCatalog` de-dupes them into ONE catalog with a deterministic winner.
10
460
  *
11
- * const template = getWorkspaceTemplate('brand-library');
12
- * // template.workspace.name === 'Brand Library'
13
- * // template.app.kind === 'native'
14
- * // template.layout.defaultApp === 'brandLibrary'
461
+ * WHY THIS LIVES HERE (and is PURE):
462
+ * This is the ONLY module the root `pnpm-workspace.yaml` lets `synap-cli`,
463
+ * `browser`, `synap-control-plane-api`, AND `synap-backend/packages/api` all
464
+ * resolve. `@synap-core/marketplace` pulls React and is `private: true`, so the
465
+ * Node CLI cannot import it. Keep this file pure data — no fetch, no auth, no
466
+ * React, no Node-only APIs. Each entry point has a DIFFERENT transport (browser
467
+ * cookie/`cpFetch`, CLI Bearer, pod anonymous); a door that fetched would force
468
+ * ONE auth model on all three and become the next lossy seam. Transport lives
469
+ * in the consumers; this door only merges arrays they already fetched.
470
+ */
471
+
472
+ /**
473
+ * A bundled template — the canonical `WorkspaceYaml` this package ships. Callers
474
+ * pass `listPublicTemplates()` (18) or `listWorkspaceTemplates()` (21); the door
475
+ * merges whatever it is given and does NOT filter (see the publicity note below).
476
+ */
477
+ type BundledEntry = WorkspaceYaml;
478
+ /**
479
+ * A control-plane registry row, mapped into the minimal shape the door needs.
480
+ * Consumers build this from a `MarketplacePackage` (browser) / the CP
481
+ * `GET /api/packages` JSON (CLI) — a thin, transport-specific projection.
482
+ *
483
+ * `definition` is carried OPAQUE: it is both (a) the install payload the consumer
484
+ * feeds back to the pod, and (b) the home of the ONE comparable version signal,
485
+ * `definition.sourcePackage.version` — the real npm semver of the published
486
+ * `@synap-core/workspace-templates` build that generated an official row
487
+ * (`seed-templates.ts` stamps it). The door only reads that one nested field; the
488
+ * rest of `definition` is passed through untouched.
489
+ */
490
+ interface RemoteEntry {
491
+ slug: string;
492
+ name: string;
493
+ description?: string;
494
+ /** CP package category / type (e.g. `"workspace"`, `"view"`). */
495
+ category?: string;
496
+ tags?: string[];
497
+ icon?: string | null;
498
+ /**
499
+ * `true` when the CP row is not publicly listed (`isPublic === false`). Browse
500
+ * rows leave this `undefined` BY CONSTRUCTION — the browse route hard-filters
501
+ * `WHERE is_public = true`, so every browse row is public; `undefined` ⇒ public,
502
+ * never "unknown-so-hide".
503
+ */
504
+ isPrivate?: boolean;
505
+ /**
506
+ * The CP `definition` jsonb — opaque install payload. The door reads only
507
+ * `definition.sourcePackage.version` (the winner signal). Absent on browse rows
508
+ * (the list route strips `definition`), which is fine: absence ⇒ bundle wins.
509
+ */
510
+ definition?: {
511
+ sourcePackage?: {
512
+ name?: string;
513
+ version?: string;
514
+ };
515
+ [k: string]: unknown;
516
+ };
517
+ }
518
+ /** Whether the caller could reach / authenticate against the remote source. */
519
+ type RemoteSourceStatus = "ok" | "unauthenticated" | "unreachable";
520
+ interface MergeCatalogInput {
521
+ /** Bundled templates (this package). Always "ok" — it is in-process data. */
522
+ bundled: BundledEntry[];
523
+ /** Already-fetched CP rows. Empty/omitted when the fetch failed. */
524
+ remote?: RemoteEntry[];
525
+ /**
526
+ * This client's bundled-package version (`package.json` `version`, live `0.6.0`).
527
+ * Compared against each remote row's `sourcePackage.version` to decide whether
528
+ * THIS client's bundle is stale. Callers pass the compiled-in package version.
529
+ */
530
+ bundleVersion: string;
531
+ /**
532
+ * The transport's verdict on the remote fetch. `"ok"` (default) ⇒ merge the
533
+ * `remote` array. `"unauthenticated"` / `"unreachable"` ⇒ ignore `remote` and
534
+ * surface the degradation in `sources.remote`, so the consumer can render
535
+ * "18 available — private ones need login" instead of FAILING OPEN EMPTY.
536
+ */
537
+ remoteStatus?: RemoteSourceStatus;
538
+ }
539
+ interface CatalogEntryBase {
540
+ slug: string;
541
+ name: string;
542
+ description?: string;
543
+ /** Package category / type. Bundled templates are always `"workspace"`. */
544
+ category?: string;
545
+ tags: string[];
546
+ icon?: string | null;
547
+ /** `true` ⇒ not publicly listed (internal bundled template, or private CP row). */
548
+ isPrivate: boolean;
549
+ }
550
+ /** A catalog entry backed by a bundled template. Install via `toWorkspaceDefinition()` / `toPackageDefinition()` on `template`. */
551
+ interface BundledCatalogEntry extends CatalogEntryBase {
552
+ source: "bundled";
553
+ template: WorkspaceYaml;
554
+ }
555
+ /** A catalog entry backed by a CP registry row. Install from `remote.definition`. */
556
+ interface RemoteCatalogEntry extends CatalogEntryBase {
557
+ source: "remote";
558
+ remote: RemoteEntry;
559
+ }
560
+ /** One merged card. `source` discriminates the install path; common fields feed a picker. */
561
+ type CatalogEntry = BundledCatalogEntry | RemoteCatalogEntry;
562
+ interface MergeCatalogResult {
563
+ entries: CatalogEntry[];
564
+ /**
565
+ * Per-source health. LOAD-BEARING, not decoration: it is what lets a consumer
566
+ * distinguish "remote returned nothing" from "remote unreachable" and avoid the
567
+ * FAILS-OPEN-EMPTY trap (agent sees empty catalog → thinks pod is empty → dupes).
568
+ */
569
+ sources: {
570
+ bundled: "ok";
571
+ remote: RemoteSourceStatus;
572
+ };
573
+ }
574
+ /**
575
+ * Merge bundled + remote template catalogs into ONE de-duplicated list.
576
+ *
577
+ * DEDUPE KEY = `slug` — NOT `slug@version`. This is forced by the live data, not
578
+ * a preference: every CP flagship row is hardcoded `version: "1.0.0"`
579
+ * (`seed-templates.ts`) and `TemplateMeta` carries NO version field at all, so a
580
+ * `slug@version` key would collide on nothing → 21 duplicate cards. The real
581
+ * per-build version lives only in `definition.sourcePackage.version`, which is
582
+ * the WINNER signal, never the identity key.
15
583
  *
16
- * YAML source files live in src/*.yaml — AI-friendly, commentable, mergeable.
17
- * Run `pnpm build` to regenerate src/templates.ts from YAML.
584
+ * CONFLICT RESOLUTION (remote slug already claimed by a bundled template):
585
+ * • remote `sourcePackage.version` strictly > `bundleVersion` → remote wins
586
+ * (this client is stale — the CP has a fresher official build).
587
+ * • otherwise (equal / older / no `sourcePackage`) → BUNDLE wins. The
588
+ * no-`sourcePackage` case is a third-party package SQUATTING an official slug;
589
+ * the bundle wins unconditionally (squatting defense).
590
+ *
591
+ * A remote slug that does NOT collide with any bundled template is a DISTINCT
592
+ * entry (a private or third-party package) and is always kept.
593
+ */
594
+ declare function mergeCatalog(input: MergeCatalogInput): MergeCatalogResult;
595
+
596
+ /**
597
+ * @synap-core/workspace-templates — Definition adapter
598
+ *
599
+ * Converts a YAML template (WorkspaceYaml) into the flat payload shape that
600
+ * the backend `workspaces.createFromDefinition` mutation + Hub REST
601
+ * `/workspaces/from-definition` endpoint expect.
602
+ *
603
+ * This is the single canonical seam: every consumer (browser app, onboarding,
604
+ * CLI, marketplace) provisions a workspace through this function so the wire
605
+ * shape never drifts per call-site.
606
+ */
607
+
608
+ /** A widget block as the wire expects it: `bentoLayout[]`, keyed by `widgetType`. */
609
+ interface BentoWidgetBlockWire {
610
+ widgetType: string;
611
+ pos: TemplateBentoBlock['pos'];
612
+ config?: Record<string, unknown>;
613
+ }
614
+ /** A view block as the wire expects it: `bentoViewBlocks[]`, keyed by `viewName`. */
615
+ interface BentoViewBlockWire {
616
+ kind: 'view';
617
+ viewName: string;
618
+ pos: TemplateBentoBlock['pos'];
619
+ overrides?: Record<string, unknown>;
620
+ }
621
+ interface SplitBentoBlocks {
622
+ bentoLayout: BentoWidgetBlockWire[];
623
+ bentoViewBlocks: BentoViewBlockWire[];
624
+ }
625
+ declare function splitBentoBlocks(blocks: TemplateBentoBlock[] | undefined): SplitBentoBlocks;
626
+ /** The flat definition object accepted by createFromDefinition. */
627
+ interface WorkspaceDefinitionInput {
628
+ workspaceName: string;
629
+ description: string;
630
+ proposalId?: string;
631
+ profiles: WorkspaceYaml['profiles'];
632
+ views: NonNullable<WorkspaceYaml['views']>;
633
+ entityLinks: NonNullable<WorkspaceYaml['entityLinks']>;
634
+ seedEntities: NonNullable<WorkspaceYaml['seedEntities']>;
635
+ suggestedRelations?: WorkspaceYaml['suggestedRelations'];
636
+ displayTemplates?: WorkspaceYaml['displayTemplates'];
637
+ layoutConfig: WorkspaceYaml['layout'] | undefined;
638
+ bentoViewName?: string;
639
+ /**
640
+ * WIDGET half of the authored bento union. The door declares this field
641
+ * (`workspaces.createFromDefinition` zod) and the pod maps it as widgets via
642
+ * `widget.widgetType`. It was missing from this interface entirely, which is
643
+ * why `toWorkspaceDefinition` had nowhere to put widgets and dumped the whole
644
+ * union into `bentoViewBlocks` — where every widget was silently filtered out.
645
+ */
646
+ bentoLayout?: BentoWidgetBlockWire[];
647
+ /** VIEW half of the authored bento union — resolved against the viewMap. */
648
+ bentoViewBlocks?: BentoViewBlockWire[];
649
+ profileEntityBentoTemplates?: WorkspaceYaml['profileEntityBentoTemplates'];
650
+ workspaceSubtype?: string;
651
+ workspaceType?: NonNullable<WorkspaceYaml['workspace']>['workspaceType'];
652
+ workspaceVisibility?: string;
653
+ workspaceCapabilities?: string[];
654
+ sourceRoles?: NonNullable<WorkspaceYaml['workspace']>['sourceRoles'];
655
+ defaultSources?: NonNullable<WorkspaceYaml['workspace']>['defaultSources'];
656
+ /** Per-workspace onboarding context — written to settings.onboarding. */
657
+ onboarding?: WorkspaceYaml['onboarding'];
658
+ /**
659
+ * Template-composition dependencies. MUST be forwarded: the backend resolves
660
+ * these BEFORE materializing this workspace (`workspaces.createFromDefinition`
661
+ * → `materializeWorkspaceCore` Step 0 → `resolvePackageDependencies`), which
662
+ * is what installs a `require`d base FIRST and makes shared-profile base
663
+ * seeding deterministic. Dropping this field silently de-orders provisioning
664
+ * on the tRPC/UI door — see the note in `toWorkspaceDefinition`.
665
+ */
666
+ dependencies?: WorkspaceYaml['dependencies'];
667
+ }
668
+ interface ToDefinitionResult {
669
+ definition: WorkspaceDefinitionInput;
670
+ /** Stable idempotency key — the template's proposalId or slug. */
671
+ proposalId: string;
672
+ /** Display name for the new workspace. */
673
+ workspaceName: string;
674
+ /** Template id for telemetry / dedup. */
675
+ templateId: string;
676
+ }
677
+ /**
678
+ * Resolve a template (by slug or YAML object) into the createFromDefinition
679
+ * payload. Pass `nameOverride` to rename the workspace at creation time.
680
+ */
681
+ declare function toWorkspaceDefinition(slugOrYaml: string | WorkspaceYaml, nameOverride?: string): ToDefinitionResult;
682
+ /**
683
+ * The unified `PackageDefinition` shape consumed by `POST /api/hub/packages/apply`
684
+ * (CLI `synap launch`) and the CP package registry seeder. It composes the
685
+ * workspace definition with the capability/playbook/onboarding layers. Mirrors
686
+ * `PackageDefinition` in synap-backend `package-definition.ts`. Typed loosely on
687
+ * the layered fields to avoid a backend import; the wire validation lives in the
688
+ * apply endpoint.
689
+ */
690
+ interface PackageDefinitionOutput {
691
+ _meta: {
692
+ slug: string;
693
+ icon?: string;
694
+ color?: string;
695
+ tags?: string[];
696
+ isPublic?: boolean;
697
+ requiredTier?: string | null;
698
+ };
699
+ workspaceName: string;
700
+ description: string;
701
+ workspaceType?: WorkspaceYaml['workspace']['workspaceType'];
702
+ workspaceSubtype?: string;
703
+ workspaceVisibility?: string;
704
+ workspaceCapabilities?: string[];
705
+ sourceRoles?: WorkspaceYaml['workspace']['sourceRoles'];
706
+ defaultSources?: WorkspaceYaml['workspace']['defaultSources'];
707
+ profiles: WorkspaceYaml['profiles'];
708
+ views: NonNullable<WorkspaceYaml['views']>;
709
+ suggestedEntities: NonNullable<WorkspaceYaml['seedEntities']>;
710
+ suggestedRelations?: WorkspaceYaml['suggestedRelations'];
711
+ displayTemplates?: WorkspaceYaml['displayTemplates'];
712
+ entityLinks?: WorkspaceYaml['entityLinks'];
713
+ /** WIDGET half of the authored bento union — mapped by the pod via `widgetType`. */
714
+ bentoLayout?: BentoWidgetBlockWire[];
715
+ /**
716
+ * VIEW half of the authored bento union. Widgets go to `bentoLayout`, views
717
+ * here — the pod splits by field (create-workspace-from-definition.ts:1373
718
+ * reads `bentoViewBlocks`), so both wire fields must be carried. The apply
719
+ * door's `PackageApplySchema` now declares this field (it is a plain
720
+ * `z.object`, so an undeclared field would be silently stripped) — the inbound
721
+ * seam is closed to match this outbound emit.
722
+ */
723
+ bentoViewBlocks?: BentoViewBlockWire[];
724
+ bentoViewName?: string;
725
+ profileEntityBentoTemplates?: WorkspaceYaml['profileEntityBentoTemplates'];
726
+ layoutConfig?: WorkspaceYaml['layout'];
727
+ capabilities?: WorkspaceYaml['integrations'];
728
+ playbooks?: WorkspaceYaml['playbooks'];
729
+ onboarding?: WorkspaceYaml['onboarding'];
730
+ /** Template-composition dependencies — resolved by the apply endpoint. */
731
+ dependencies?: WorkspaceYaml['dependencies'];
732
+ }
733
+ /**
734
+ * Resolve a template (by slug or YAML object) into the full `PackageDefinition`
735
+ * accepted by `POST /api/hub/packages/apply` and the CP registry seeder. This is
736
+ * the single seam the CLI and control-plane use so they read from the canonical
737
+ * package instead of disk-stored JSON.
18
738
  */
19
- export type { WorkspaceYaml, TemplateMeta, TemplateAppRef, TemplateAppKind, TemplateProfile, TemplateProperty, TemplateView, TemplateSidebarItem, TemplateSidebarSurface, TemplateLayoutConfig, TemplateBentoBlock, TemplateEntityLink, TemplateSeedEntity, TemplateSuggestedRelation, TemplateDisplayTemplate, TemplateIntegration, TemplateAutomation, TemplateExtendsRef, TemplateProfileEntityBentoTemplates, TemplateDefaultSource, TemplateSourceRole, TemplateOnboarding, TemplateOnboardingCollectTarget, TemplatePlaybook, TemplatePlaybookParam, } from './types.js';
20
- export { WORKSPACE_TEMPLATES, getWorkspaceTemplate, listWorkspaceTemplates, listPublicTemplates, } from './templates.js';
21
- export type { WorkspaceTemplateSlug } from './templates.js';
22
- export { toWorkspaceDefinition, toPackageDefinition } from './define.js';
23
- export type { WorkspaceDefinitionInput, ToDefinitionResult, PackageDefinitionOutput, } from './define.js';
24
- //# sourceMappingURL=index.d.ts.map
739
+ declare function toPackageDefinition(slugOrYaml: string | WorkspaceYaml): PackageDefinitionOutput;
740
+
741
+ export { type BentoViewBlockWire, type BentoWidgetBlockWire, type BundledCatalogEntry, type BundledEntry, type CatalogEntry, type MergeCatalogInput, type MergeCatalogResult, PACKAGE_DEPENDENCY_KINDS, type PackageDefinitionOutput, type PackageDependencyKind, type RemoteCatalogEntry, type RemoteEntry, type RemoteSourceStatus, type SplitBentoBlocks, type TemplateAppKind, type TemplateAppRef, type TemplateAutomation, type TemplateBentoBlock, type TemplateDefaultSource, type TemplateDependency, type TemplateDisplayTemplate, type TemplateEntityLink, type TemplateExtendsRef, type TemplateIntegration, type TemplateLayoutConfig, type TemplateMeta, type TemplateOnboarding, type TemplateOnboardingCollectTarget, type TemplatePlaybook, type TemplatePlaybookParam, type TemplateProfile, type TemplateProfileEntityBentoTemplates, type TemplateProperty, type TemplateSeedEntity, type TemplateSidebarItem, type TemplateSidebarSurface, type TemplateSourceRole, type TemplateSuggestedRelation, type TemplateView, type ToDefinitionResult, WORKSPACE_TEMPLATES, type WorkspaceDefinitionInput, type WorkspaceTemplateSlug, type WorkspaceYaml, getWorkspaceTemplate, listPublicTemplates, listWorkspaceTemplates, mergeCatalog, splitBentoBlocks, toPackageDefinition, toWorkspaceDefinition };