@elevasis/sdk 1.51.0 → 1.52.0

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.
@@ -51,23 +51,30 @@ A pipeline's step catalog is named `content:catalog/{pipelineId}-steps` and refe
51
51
  | Add content nav or a content route | `CONTENT_ITEMS`, `ContentSidebar`, `ContentSidebarMiddle` | Same manifest/sidebar composition pattern as CRM and lead-gen. |
52
52
  | Give producers a style guide or voice constraints | The generating workflow's own prompt | Content has no rules-document tier. Put the instructions where the model reads them. |
53
53
  | Track where a piece was published | `createDistribution` / `updateDistribution` | One distribution row per platform per item. |
54
+ | Actually post an item to a platform | Section 6 — a publish panel of yours, over a prepared distribution row | Publishing is operating, so it is your screen. Instagram has a published workflow; do not copy it. |
54
55
  | Pick source material for a new item | `createSourceAsset` / `getSourceAsset` / `listSourceAssets` / `updateSourceAsset` | Raw material a producer works from -- an uploaded episode, a transcript, a reference file. |
55
56
  | Operate the pipeline from outside a browser | `elevasis-sdk content:*` | Read-only plus one write (`content:review`). Not how a workflow produces content -- see the boundary below. |
56
57
  | Add a new persisted content column or table | Platform/API migration work, not just scaffold work | DB, core schemas/types, API service/handlers, hooks, docs, and scaffold contracts move together. |
57
58
 
58
59
  ## Published Content Surfaces
59
60
 
60
- | Surface | Import from | Use for |
61
- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------------------------------------ |
62
- | `contentManifest`, `CONTENT_ITEMS`, `ContentSidebar`, `ContentSidebarMiddle`, `MyReviewQueuePanel` | `@elevasis/ui/features/content` | Feature registration and sidebar composition |
63
- | `ContentOverviewPage`, `ContentItemsPage`, `ContentItemReviewPage`, `ContentPipelinesPage`, `ContentPipelineBoardPage` | `@elevasis/ui/features/content` | Shared pages you can route to or wrap |
64
- | `ContentDistributionsPage`, `ContentDistributionDetailPage` | `@elevasis/ui/features/content` | Distribution surfaces |
65
- | `ContentReviewCard`, `ReviewActionBar`, `PayloadBody`, `AlternatesPanel`, `ProcessingStateStrip` | `@elevasis/ui/features/content` | Review UI primitives for a custom review screen |
66
- | `useContentConfig`, `resolveContentStepResource` | `@elevasis/ui/features/content` | Read the resolved pipeline/step catalogs from OM |
67
- | `useContentItems`, `useContentItem`, `useContentItemAttempts`, `useUpdateContentItem`, `useReviewContentItem` | `@elevasis/ui/hooks` | Item data access and review mutations |
68
- | `useContentDistributions`, `useContentDistribution`, `useUpdateContentDistribution` | `@elevasis/ui/hooks` | Distribution data access |
69
- | `useContentPipelineSummary` | `@elevasis/ui/hooks` | Pipeline roll-ups |
70
- | `content` | `@elevasis/sdk/worker` | Workflow-side content adapter |
61
+ | Surface | Import from | Use for |
62
+ | ---------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | ------------------------------------------------ |
63
+ | `contentManifest`, `CONTENT_ITEMS`, `ContentSidebar`, `ContentSidebarMiddle`, `MyReviewQueuePanel` | `@elevasis/ui/features/content` | Feature registration and sidebar composition |
64
+ | `ContentOverviewPage`, `ContentItemsPage`, `ContentItemReviewPage`, `ContentPipelinesPage`, `ContentPipelineBoardPage` | `@elevasis/ui/features/content` | Shared pages you can route to or wrap |
65
+ | `ContentDistributionsPage`, `ContentDistributionDetailPage` | `@elevasis/ui/features/content` | Distribution surfaces |
66
+ | `ContentReviewCard`, `ReviewActionBar`, `PayloadBody`, `AlternatesPanel`, `ProcessingStateStrip` | `@elevasis/ui/features/content` | Review UI primitives for a custom review screen |
67
+ | `useContentConfig`, `resolveContentStepResource` | `@elevasis/ui/features/content` | Read the resolved pipeline/step catalogs from OM |
68
+ | `useContentItems`, `useContentItem`, `useContentItemAttempts`, `useUpdateContentItem`, `useReviewContentItem` | `@elevasis/ui/hooks` | Item data access and review mutations |
69
+ | `useContentDistributions`, `useContentDistribution`, `useUpdateContentDistribution` | `@elevasis/ui/hooks` | Distribution data access |
70
+ | `useContentPipelineSummary` | `@elevasis/ui/hooks` | Pipeline roll-ups |
71
+ | `ContentWorkspaceShell`, `ContentAnalysisStepPanel`, `ContentStepPanelMap`, `ContentWorkspaceState` | `@elevasis/ui/features/content` | The workspace frame and its panel contract |
72
+ | `useExecuteAsync`, `useExecution`, `isExecutionInFlight`, `TERMINAL_EXECUTION_STATUSES` | `@elevasis/ui/hooks` | Start a publishing workflow and watch it finish |
73
+ | `useCreateContentDistribution`, `useUpdateContentDistribution` | `@elevasis/ui/hooks` | Prepare and record a post |
74
+ | `content` | `@elevasis/sdk/worker` | Workflow-side content adapter |
75
+ | `createPublishInstagramWorkflow`, `createInstagramAdapter` | `@elevasis/sdk/worker` | Post to Instagram from a workflow |
76
+ | `createMockInstagram` | `@elevasis/sdk/test-utils` | Test a publish pipeline without a real account |
77
+ | `defineContentPipeline`, `defineContentSystem` | `@elevasis/core/organization-model` | Declare a pipeline and derive the System block |
71
78
 
72
79
  Read the generated contracts before changing typed boundaries:
73
80
 
@@ -418,13 +425,254 @@ rendering "Pipelines" here, and nothing fails to tell you.
418
425
  Replace `contentManifest` with `customContentManifest` in the local `SYSTEM_MANIFESTS` array and add
419
426
  the matching route under `ui/src/routes/content/`.
420
427
 
421
- ## 6. Mark the System API-Ready
428
+ ## 6. Send It Out
429
+
430
+ Sections 1 through 5 get an item made and reviewed. This one covers the last step of a pipeline
431
+ that publishes: turning a finished item into a post on a platform.
432
+
433
+ Publishing is **operating**, so by the section 5 contract it is yours: a panel on your workspace,
434
+ not a shared page. The shared distribution pages display what went out and never write. What the
435
+ platform gives you is the distribution row, a way to start a workflow and watch it, and — for
436
+ Instagram — the publishing workflow itself.
437
+
438
+ ### A panel is registered against a step key
439
+
440
+ `ContentWorkspaceShell` walks the pipeline from the deployed model and renders whichever panel
441
+ your map names for the active step. The map is keyed by **step key**, not by any convention on the
442
+ component:
443
+
444
+ ```tsx
445
+ import { ContentAnalysisStepPanel, ContentWorkspaceShell } from '@elevasis/ui/features/content'
446
+ import type { ContentStepPanelMap } from '@elevasis/ui/features/content'
447
+
448
+ interface PostDraft {
449
+ platform: string | null
450
+ publishExecutionId: string | null
451
+ }
452
+
453
+ const panels: ContentStepPanelMap<PostDraft> = {
454
+ analysis: ContentAnalysisStepPanel,
455
+ caption: CaptionStepPanel,
456
+ publish: PublishStepPanel
457
+ }
458
+
459
+ export function WritePostPage() {
460
+ return (
461
+ <ContentWorkspaceShell
462
+ panels={panels}
463
+ initialDraft={{ platform: null, publishExecutionId: null }}
464
+ title="Write a Post"
465
+ />
466
+ )
467
+ }
468
+ ```
469
+
470
+ Every panel is called with the same `ContentWorkspaceState<TDraft>` — the item, its body, the
471
+ distribution row, `refetchDistributions`, step navigation, and your own `draft`. Anything matching
472
+ that signature is a panel. A step key with no entry in the map is reported rather than rendering
473
+ nothing, which is the reason the map is explicit instead of derived from the key.
474
+
475
+ `ContentAnalysisStepPanel` is the one step panel published today, because it needs an item id and
476
+ nothing else. A publish panel is not shippable the same way: it reaches a credential, a status
477
+ vocabulary, and a workflow id, all of which are yours to choose.
478
+
479
+ ### Prepare the distribution row before posting
480
+
481
+ A distribution is one row per platform per item, and it is what the publishing workflow reads. It
482
+ must exist, and carry its media, **before** anything goes out:
483
+
484
+ ```tsx
485
+ const createDistribution = useCreateContentDistribution()
486
+
487
+ await createDistribution.mutateAsync({
488
+ contentItemId: item.id,
489
+ platform,
490
+ format: 'carousel',
491
+ status: 'pending',
492
+ // The caption as it will go out. The row is the record of the post, not a pointer at an
493
+ // item whose body may be edited afterwards.
494
+ adaptedBody: body.trim().length > 0 ? body : null,
495
+ mediaUrls: renderedEntries
496
+ })
497
+ refetchDistributions()
498
+ ```
499
+
500
+ The row freezing what goes out is the point: re-cropping an image after the fact must not quietly
501
+ change what the record says was posted. The corollary is that a row prepared before the caption was
502
+ written holds a stale caption — write the current body onto it at post time, while `publishedAt` is
503
+ still null and nothing has gone out yet.
504
+
505
+ ### Reaching a publishing workflow
506
+
507
+ Start it async and watch it. Staging a carousel is one upload per image plus polling until the
508
+ platform reports each container finished, which is far longer than a request a page can hold open:
509
+
510
+ ```tsx
511
+ const startPublish = useExecuteAsync()
512
+ const publishExecution = useExecution(publishWorkflowId, draft.publishExecutionId ?? '')
513
+
514
+ const started = await startPublish.mutateAsync({
515
+ resourceId: publishWorkflowId,
516
+ resourceType: 'workflow',
517
+ input: { distributionId: distribution.id }
518
+ })
519
+ setDraft({ publishExecutionId: started.executionId })
520
+ ```
521
+
522
+ **Name the workflow; do not ask the model which one it is.** `resolveContentStepResource` returns
523
+ the first resource whose ontology claims the step's action, which is a coin flip once more than one
524
+ does. A workflow id is a decision your app makes — pass it as a prop or read it from your own
525
+ config.
526
+
527
+ **Use `isExecutionInFlight` for "is it still going", not `status === 'running'`.** `warning` is a
528
+ terminal status the platform picks for a run that succeeded while emitting warn-level logs, so a
529
+ `running` test treats a finished run as still in flight and a `completed`-only test never notices
530
+ it finished. Both are exported from `@elevasis/ui/hooks`:
531
+
532
+ ```tsx
533
+ import { isExecutionInFlight, TERMINAL_EXECUTION_STATUSES } from '@elevasis/ui/hooks'
534
+ ```
535
+
536
+ `useExecution` already polls on that predicate, so a panel needs no poll of its own. One browser
537
+ caveat when you go to verify it: React Query pauses `refetchInterval` while `document.hidden`, so a
538
+ backgrounded tab measures zero requests against correct code.
539
+
540
+ ### Instagram: use the published workflow, do not copy it
541
+
542
+ `createPublishInstagramWorkflow` takes a credential name and returns a registered workflow. That is
543
+ the whole of what is project-specific about posting to Instagram:
544
+
545
+ <!-- doc-snippet:skip: illustrative excerpt -- a project-local registration module -->
546
+
547
+ ```ts
548
+ import { createPublishInstagramWorkflow } from '@elevasis/sdk/worker'
549
+
550
+ export const publishInstagramWorkflow = createPublishInstagramWorkflow({
551
+ credentialName: 'acme-instagram',
552
+ resourceId: 'cnt-publish-instagram-workflow'
553
+ })
554
+ ```
555
+
556
+ The credential holds `{ accessToken, igUserId }` — the account id rides along with the token, so no
557
+ caller carries it. Given a `distributionId` the workflow signs each image, builds the containers,
558
+ publishes, and writes the returned post id and permalink back onto the same row. It does not move
559
+ the item's status: which status means "finished" is resolved against your own model by the surface
560
+ that owns the item, and deciding it twice is two answers that can disagree.
561
+
562
+ **It refuses rather than repairs, and that is why it is not yours to copy.** Three checks run before
563
+ anything reaches Instagram, each guarding an action that cannot be taken back:
564
+
565
+ | Refusal | Why it is a refusal |
566
+ | ---------------------------------------- | --------------------------------------------------------------------------- |
567
+ | the row's `platform` is not `instagram` | posting a row prepared for somewhere else posts the wrong thing |
568
+ | the row already carries `platformPostId` | only a real publish writes that field, so posting again duplicates the post |
569
+ | the row already carries `publishedAt` | someone recorded this as posted; posting now would post it twice |
570
+ | the row has no `mediaUrls` | there is nothing to post — render first |
571
+
572
+ To post again, create a new distribution. Nothing clears these.
573
+
574
+ A failed execution therefore generally means **nothing was posted**, and its own error message is
575
+ more specific than anything a panel could write — show `execution.error` rather than a generic line.
576
+
577
+ ### Posting by hand
578
+
579
+ Not every platform has a workflow behind it, and the manual path needs no credential at all.
580
+ Record it on the same row:
581
+
582
+ ```tsx
583
+ await updateDistribution.mutateAsync({
584
+ distributionId: distribution.id,
585
+ updates: {
586
+ status: 'published',
587
+ publishMethod: 'manual',
588
+ publishedAt: new Date().toISOString(),
589
+ ...(isUsableUrl ? { platformUrl: typedUrl } : {})
590
+ }
591
+ })
592
+ ```
593
+
594
+ `publishedAt` set with no `platformPostId` is the manual shape — do not invent an id no platform
595
+ returned. When you later ask how a post went out, test against `'manual'` rather than against an
596
+ API value: a publishing workflow writes the platform it posted through (`'instagram-api'`), so
597
+ "was this done by hand" is the question with one stable answer.
598
+
599
+ ### Testing a publish pipeline
600
+
601
+ Mock the integration; do not point a test at a real account. `createMockInstagram` covers all eight
602
+ adapter methods:
603
+
604
+ <!-- doc-snippet:skip: illustrative excerpt -- vitest usage inside a project's own suite -->
605
+
606
+ ```ts
607
+ import { createMockInstagram } from '@elevasis/sdk/test-utils'
608
+
609
+ const instagram = createMockInstagram('acme-instagram', {
610
+ // A publish sequence polls until the container reports FINISHED. Un-overridden, it never does.
611
+ getContainerStatus: ({ containerId }) => ({ containerId, statusCode: 'FINISHED', status: 'Finished' }),
612
+ publishContainer: { mediaId: 'media-1' }
613
+ })
614
+ ```
615
+
616
+ ## 7. Mark the System API-Ready
422
617
 
423
618
  `content.apiInterface.lifecycle` goes `active` only when the System's scoped resources, `content:object/item`, and the pipeline/step/status catalogs are all in place. Two failure modes are worth knowing before you flip it:
424
619
 
425
620
  - An **empty** `apiInterface.resourceIds` array throws rather than opting out. Omitting the whole `apiInterface` block is the opt-out; a `resourceIds: []` stub is the anomaly.
426
621
  - Readiness is derived from a **deployed** snapshot. A model edit that has not been redeployed produces a stale-snapshot 503 that looks like a code bug. Redeploy before debugging.
427
622
 
623
+ ### Or derive the whole block with `defineContentSystem`
624
+
625
+ `defineContentPipeline` (section 1) removes the per-pipeline duplication. What is left is the
626
+ surrounding boilerplate every content adopter writes identically: the `apiInterface` block, its
627
+ `readinessContract`, the `content:object/item` object type, and the status catalog. `defineContentSystem`
628
+ takes the pipelines and derives all four.
629
+
630
+ <!-- doc-snippet:skip: illustrative excerpt -- references project-local pipeline declarations -->
631
+
632
+ ```ts
633
+ import { defineContentPipeline, defineContentSystem } from '@elevasis/core/organization-model'
634
+
635
+ const linkedInPost = defineContentPipeline({
636
+ systemPath: 'content',
637
+ id: 'linkedin-post',
638
+ label: 'LinkedIn Post',
639
+ workspaceRoute: '/content/write',
640
+ steps: [{ key: 'draft', actor: 'agent', review: 'required', resource: saveContentBatch }]
641
+ })
642
+
643
+ export const contentSystem = defineContentSystem({
644
+ systemPath: 'content',
645
+ resourceIds: ['save-content-batch', 'publish-linkedin'],
646
+ pipelines: [linkedInPost],
647
+ item: { label: 'Post', description: 'One LinkedIn post, from idea to distribution.' },
648
+ statuses: [
649
+ { key: 'draft', label: 'Written', order: 10, semanticClass: 'active' },
650
+ { key: 'posted', label: 'Posted', order: 20, semanticClass: 'completed' }
651
+ ]
652
+ })
653
+
654
+ // Inside the content System:
655
+ // apiInterface: contentSystem.apiInterface
656
+ // ontology: { ...contentSystem.objectTypes, ...contentSystem.catalogTypes, ...yourOwn }
657
+ ```
658
+
659
+ It emits `apiInterface` (with `readinessProfile: 'content.api'` and a `readinessContract` listing
660
+ the pipeline, every step catalog, and the status catalog), `objectTypes` carrying
661
+ `content:object/item`, and `catalogTypes` carrying the pipeline, step, and status catalogs. Your own
662
+ object types, action types, and per-adopter catalogs — pillar, platform, source-asset kind — stay
663
+ hand-authored alongside them.
664
+
665
+ **The contract is unchanged; only the boilerplate is gone.** Content is validated against a
666
+ declared `readinessContract` rather than a platform validator, and that is deliberate: a CRM
667
+ pipeline is a CRM pipeline, so platform code can hardcode what to check, while a content pipeline is
668
+ whatever its adopter declares. Making it built-in would hardcode one step catalog for every project.
669
+ `defineContentSystem` writes the contract for you; it does not remove it.
670
+
671
+ **`lifecycle` defaults to `'active'`, so calling this helper is itself the decision to serve the
672
+ API.** Pass `lifecycle: 'draft'` while the pipelines are declared but not yet served. The opt-out
673
+ above — omitting `apiInterface` entirely — means not calling `defineContentSystem` for that block at
674
+ all; there is no way to call it and get no marker.
675
+
428
676
  ## Verify
429
677
 
430
678
  Run the checks for the surfaces you touched:
@@ -56,7 +56,6 @@ description: "Auto-generated catalog of all published @elevasis/ui subpath expor
56
56
  | `@elevasis/ui/provider/ElevasisServiceContext` | Elevasis Service Context | Provider | Standalone service context and provider that supplies apiRequest, organizationId, and isReady to child components. |
57
57
  | `@elevasis/ui/hooks/delivery` | Hooks Delivery | Hooks | Published delivery hooks for projects, milestones, tasks, and notes. |
58
58
  | `@elevasis/ui/hooks/user-notes` | Hooks User Notes | Hooks | Published user-notes query and mutation hooks used by shared Notes surfaces. |
59
- | `@elevasis/ui/hooks/operations/command-view/utils/transformCommandViewData` | Transform Command View Data | Hooks | Utility that transforms backend CommandViewData arrays into a unified frontend CommandViewGraph with nodes and edges. |
60
59
  | `@elevasis/ui/test-utils` | Test Utils | Testing | Published rendering helpers, auth mocks, MSW handlers, and test provider utilities. |
61
60
  | `@elevasis/ui/test-utils/setup` | Test Utils Setup | Testing | Vitest setup file for UI consumers using browser mocks and MSW. |
62
61
  | `@elevasis/ui/test-utils/setup-integration` | Test Utils Integration Setup | Testing | Vitest setup file for integration tests that avoid MSW and use real network boundaries. |