@norskvideo/ctl-sdk 0.1.1 → 0.1.2

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.
@@ -31,16 +31,22 @@ export function ProductTemplateBuildForm({ productName, configScreenUrl, onClose
31
31
  // caller can hand it off to its launch flow without waiting for a refetch),
32
32
  // null on failure.
33
33
  const saveProductTemplate = async () => {
34
- if (!iframeRef.current) {
35
- toast.error("Configuration not ready");
36
- return null;
37
- }
38
- const result = await iframeRef.current.submit();
39
- if (!result.ok) {
40
- toast.error(result.error ?? "Configuration submission failed");
41
- return null;
34
+ // No config screen declared: there is nothing to collect, so the build
35
+ // request carries empty form values rather than requiring an iframe.
36
+ let formValues = {};
37
+ if (configScreenUrl) {
38
+ if (!iframeRef.current) {
39
+ toast.error("Configuration not ready");
40
+ return null;
41
+ }
42
+ const result = await iframeRef.current.submit();
43
+ if (!result.ok) {
44
+ toast.error(result.error ?? "Configuration submission failed");
45
+ return null;
46
+ }
47
+ formValues = result.formValues;
42
48
  }
43
- const outcome = await onSubmit({ productName, productTemplateName, formValues: result.formValues });
49
+ const outcome = await onSubmit({ productName, productTemplateName, formValues });
44
50
  if (!outcome.ok) {
45
51
  toast.error(`Save product template failed: ${outcome.error}`);
46
52
  return null;
@@ -22,8 +22,8 @@ export declare const ManifestSchema: z.ZodObject<{
22
22
  healthCheckPath: z.ZodDefault<z.ZodString>;
23
23
  productMcpPath: z.ZodOptional<z.ZodString>;
24
24
  }, z.core.$strip>;
25
- ui: z.ZodObject<{
26
- configScreenUrl: z.ZodString;
25
+ ui: z.ZodDefault<z.ZodObject<{
26
+ configScreenUrl: z.ZodOptional<z.ZodString>;
27
27
  instanceConfigScreenUrl: z.ZodOptional<z.ZodString>;
28
28
  sidebarEntries: z.ZodDefault<z.ZodArray<z.ZodObject<{
29
29
  label: z.ZodString;
@@ -39,8 +39,8 @@ export declare const ManifestSchema: z.ZodObject<{
39
39
  label: z.ZodString;
40
40
  configScreenUrl: z.ZodString;
41
41
  }, z.core.$strip>>>;
42
- }, z.core.$strip>;
43
- cli: z.ZodObject<{
42
+ }, z.core.$strip>>;
43
+ cli: z.ZodDefault<z.ZodObject<{
44
44
  subcommandTree: z.ZodDefault<z.ZodArray<z.ZodObject<{
45
45
  name: z.ZodString;
46
46
  description: z.ZodString;
@@ -53,6 +53,7 @@ export declare const ManifestSchema: z.ZodObject<{
53
53
  number: "number";
54
54
  boolean: "boolean";
55
55
  }>>;
56
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
57
  }, z.core.$strip>>>;
57
58
  subcommands: z.ZodDefault<z.ZodArray<z.ZodObject<{
58
59
  name: z.ZodString;
@@ -66,6 +67,7 @@ export declare const ManifestSchema: z.ZodObject<{
66
67
  number: "number";
67
68
  boolean: "boolean";
68
69
  }>>;
70
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
71
  }, z.core.$strip>>>;
70
72
  request: z.ZodOptional<z.ZodObject<{
71
73
  method: z.ZodEnum<{
@@ -87,7 +89,7 @@ export declare const ManifestSchema: z.ZodObject<{
87
89
  path: z.ZodString;
88
90
  }, z.core.$strip>>;
89
91
  }, z.core.$strip>>>;
90
- }, z.core.$strip>;
92
+ }, z.core.$strip>>;
91
93
  targets: z.ZodArray<z.ZodEnum<{
92
94
  "norsk-ctl": "norsk-ctl";
93
95
  "docker-compose": "docker-compose";
@@ -110,4 +112,9 @@ export declare const ManifestSchema: z.ZodObject<{
110
112
  }, z.core.$strip>>;
111
113
  }, z.core.$strip>;
112
114
  export type Manifest = z.infer<typeof ManifestSchema>;
115
+ /** Producer-facing shape: everything the reader defaults is optional, so a
116
+ * product's buildManifest() sends only what it actually declares instead of
117
+ * `sidebarEntries: []`-style boilerplate. The parsed {@link Manifest} keeps
118
+ * those fields present, so runner code needs no null-guards. */
119
+ export type ManifestInput = z.input<typeof ManifestSchema>;
113
120
  export {};
@@ -31,6 +31,9 @@ const CliFlagSchema = z.object({
31
31
  description: z.string(),
32
32
  required: z.boolean().optional(),
33
33
  type: z.enum(["string", "number", "boolean"]).optional(),
34
+ choices: z.array(z.string()).optional().meta({
35
+ description: "Allowed values for the flag. The runner's CLI rejects anything else and lists them in help output. Omit for free-form flags.",
36
+ }),
34
37
  });
35
38
  /** How a CLI leaf forwards to the product's HTTP surface. The runner registers
36
39
  * a yargs command that issues `method` against `/products/<name><path>` (the
@@ -106,8 +109,11 @@ export const ManifestSchema = z.object({
106
109
  description: "Path on the product control-plane's HTTP surface where it serves an always-on, instance-independent MCP endpoint (e.g. plugin scaffolding). Proxied as `<product>_<tool>`. Distinct from the per-instance `mcpPath`. Omit for products without one.",
107
110
  }),
108
111
  }),
109
- ui: z.object({
110
- configScreenUrl: z.string(),
112
+ ui: z
113
+ .object({
114
+ configScreenUrl: z.string().optional().meta({
115
+ description: "URL (on the product's HTTP surface) of the configure screen the runner iframes to build product templates. Omit for backend-only products with no configure UI — the runner skips its registration probe and the UI offers a config-free build path instead of an iframe.",
116
+ }),
111
117
  // Optional rich instance-launch config screen. When present, the runner's
112
118
  // launch flow probes it (a GET carrying product-template context); the
113
119
  // product returns 200 to have the runner iframe it in place of the
@@ -121,10 +127,13 @@ export const ManifestSchema = z.object({
121
127
  sidebarEntries: z.array(SidebarEntrySchema).default([]),
122
128
  dashboardWidgets: z.array(DashboardWidgetSchema).default([]),
123
129
  productTemplateActions: z.array(ProductTemplateActionSchema).default([]),
124
- }),
125
- cli: z.object({
130
+ })
131
+ .default({ sidebarEntries: [], dashboardWidgets: [], productTemplateActions: [] }),
132
+ cli: z
133
+ .object({
126
134
  subcommandTree: z.array(CliCommandSchema).default([]),
127
- }),
135
+ })
136
+ .default({ subcommandTree: [] }),
128
137
  targets: z.array(TargetSchema),
129
138
  components: z.array(ComponentDescSchema).default([]),
130
139
  runtime: RuntimeHintsSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -5,6 +5,6 @@
5
5
  * path (used by mgr — name validation + bytes persistence).
6
6
  */
7
7
  export declare class ProductTemplateError extends Error {
8
- code: "INVALID_NAME" | "NAME_CONFLICT" | "FILE_NOT_FOUND" | "EXTRACTION_FAILED" | "MANIFEST_MISSING" | "MANIFEST_INVALID" | "COMPOSE_MISSING" | "PARAMETERS_INVALID" | "NOT_FOUND" | "IN_USE";
9
- constructor(code: "INVALID_NAME" | "NAME_CONFLICT" | "FILE_NOT_FOUND" | "EXTRACTION_FAILED" | "MANIFEST_MISSING" | "MANIFEST_INVALID" | "COMPOSE_MISSING" | "PARAMETERS_INVALID" | "NOT_FOUND" | "IN_USE", message: string);
8
+ code: "INVALID_NAME" | "NAME_CONFLICT" | "FILE_NOT_FOUND" | "EXTRACTION_FAILED" | "MANIFEST_MISSING" | "MANIFEST_INVALID" | "COMPOSE_MISSING" | "PARAMETERS_INVALID" | "NOT_FOUND" | "IN_USE" | "PRODUCT_MISMATCH";
9
+ constructor(code: "INVALID_NAME" | "NAME_CONFLICT" | "FILE_NOT_FOUND" | "EXTRACTION_FAILED" | "MANIFEST_MISSING" | "MANIFEST_INVALID" | "COMPOSE_MISSING" | "PARAMETERS_INVALID" | "NOT_FOUND" | "IN_USE" | "PRODUCT_MISMATCH", message: string);
10
10
  }
package/workflow.d.ts CHANGED
@@ -39,6 +39,14 @@ export declare const VIDEO_ONLY: SubscriptionStreams;
39
39
  export declare const AUDIO_ONLY: SubscriptionStreams;
40
40
  export declare const FIRST_VIDEO: SubscriptionStreams;
41
41
  export declare const FIRST_AUDIO: SubscriptionStreams;
42
+ export type ComponentAdder<Handle> = {
43
+ addNode(identifier: string, config: never): Handle;
44
+ };
45
+ export declare function addComponent<Handle, C extends object>(builder: ComponentAdder<Handle>, component: WorkflowComponent<C>): Handle;
46
+ export type DocumentSource = {
47
+ toDocument(): unknown;
48
+ };
49
+ export declare function toWorkflowDoc<D extends WorkflowDoc = WorkflowDoc>(builder: DocumentSource): D;
42
50
  export type SyntheticNodeInfo = {
43
51
  identifier: string;
44
52
  subscription: {
@@ -57,4 +65,36 @@ export type SyntheticNodeInfo = {
57
65
  };
58
66
  };
59
67
  };
68
+ export type ComponentStubMedia = "video" | "audio" | "subtitle" | "ancillary" | "playlist";
69
+ export type ComponentStubSpec = {
70
+ identifier: string;
71
+ accepts?: ComponentStubMedia[];
72
+ produces?: ComponentStubMedia[] | "passthrough";
73
+ acceptsTransient?: boolean;
74
+ validateConfig?: (config: Record<string, unknown>) => string[] | undefined;
75
+ };
76
+ type StubMediaFlags = {
77
+ [M in ComponentStubMedia]?: true;
78
+ };
79
+ export type StubNodeInfo = {
80
+ identifier: string;
81
+ subscription: {
82
+ accepts?: {
83
+ type: "simple-stream";
84
+ acceptsTransient: boolean;
85
+ } & StubMediaFlags;
86
+ produces?: ({
87
+ type: "simple-stream";
88
+ } & StubMediaFlags) | {
89
+ type: "dynamic-streams";
90
+ streams: <S>(cfg: unknown, inputStreams: S) => S;
91
+ };
92
+ };
93
+ validateConfig?: (config: Record<string, unknown>) => string[] | undefined;
94
+ };
95
+ export declare function stubNodeInfo<T = StubNodeInfo>(spec: ComponentStubSpec): T;
96
+ export declare function stubbedLibrary<Info = StubNodeInfo>(find: (identifier: string) => Info | undefined, stubs: ComponentStubSpec[]): {
97
+ find(identifier: string): Info | undefined;
98
+ };
60
99
  export declare function syntheticInfo<T = SyntheticNodeInfo>(identifier: string): T;
100
+ export {};
package/workflow.js CHANGED
@@ -26,6 +26,76 @@ export const FIRST_AUDIO = {
26
26
  type: "take-first-stream",
27
27
  filter: [{ media: "audio" }],
28
28
  };
29
+ // Typed `addNode` boundary: adds a factory-built component to a WorkflowBuilder
30
+ // with the factory's config typing intact, so composers need no `config as
31
+ // never` at the add boundary. Subscriptions are NOT applied — wiring goes
32
+ // through the builder's connect()/pick* helpers, exactly as every product's
33
+ // local add() helper behaved. The single cast below is the one audited erasure:
34
+ // the builder's `BaseConfig` constraint wants an index signature that interface-
35
+ // declared product configs may lack, while the real gates stay intact — the
36
+ // factory return type checks the config shape at construction, and
37
+ // builder.validate() runs each node's real validateConfig at compose time.
38
+ export function addComponent(builder, component) {
39
+ return builder.addNode(component.type, component.config);
40
+ }
41
+ // Typed `toDocument` boundary: the builder returns its all-optional YamlDocument
42
+ // shape, which products immediately re-assert as their WorkflowDoc (previously
43
+ // via `as unknown as WorkflowDoc` at every call site). Sound by construction:
44
+ // the builder always emits a components array, and each entry carries the
45
+ // type/config/subscriptions the composer added. Pass a product-extended doc
46
+ // type (e.g. probe's signed document) as `D` when the product adds fields.
47
+ export function toWorkflowDoc(builder) {
48
+ return builder.toDocument();
49
+ }
50
+ function mediaFlags(media) {
51
+ return Object.fromEntries(media.map((m) => [m, true]));
52
+ }
53
+ // A builder NodeInfo from a metadata-only stub declaration. Unlike
54
+ // syntheticInfo's accept-anything fallback, the resulting info carries the
55
+ // component's REAL media contract, so edges into and out of the stub
56
+ // stream-validate like any built-in (only its config stays unvalidated unless
57
+ // the spec supplies validateConfig).
58
+ export function stubNodeInfo(spec) {
59
+ const accepts = spec.accepts
60
+ ? {
61
+ accepts: {
62
+ type: "simple-stream",
63
+ ...mediaFlags(spec.accepts),
64
+ acceptsTransient: spec.acceptsTransient ?? true,
65
+ },
66
+ }
67
+ : {};
68
+ const produces = spec.produces === "passthrough"
69
+ ? {
70
+ produces: {
71
+ type: "dynamic-streams",
72
+ streams: (_cfg, inputStreams) => inputStreams,
73
+ },
74
+ }
75
+ : spec.produces && spec.produces.length > 0
76
+ ? { produces: { type: "simple-stream", ...mediaFlags(spec.produces) } }
77
+ : {};
78
+ return {
79
+ identifier: spec.identifier,
80
+ subscription: { ...accepts, ...produces },
81
+ ...(spec.validateConfig ? { validateConfig: spec.validateConfig } : {}),
82
+ };
83
+ }
84
+ // A ComponentLibrary that resolves the real library first and declared stubs
85
+ // second — and, crucially, NOTHING else: an identifier that is neither real nor
86
+ // declared stays unresolved, so the builder's addNode throws on it instead of
87
+ // silently composing against a permissive synthetic. This is what lets
88
+ // builder.validate() be a throwing gate fleet-wide — every node is either a
89
+ // real NodeInfo or an explicitly declared stub, and a typo fails the compose.
90
+ export function stubbedLibrary(find, stubs) {
91
+ const stubInfos = new Map();
92
+ for (const spec of stubs) {
93
+ if (stubInfos.has(spec.identifier))
94
+ throw new Error(`duplicate component stub: ${spec.identifier}`);
95
+ stubInfos.set(spec.identifier, stubNodeInfo(spec));
96
+ }
97
+ return { find: (identifier) => find(identifier) ?? stubInfos.get(identifier) };
98
+ }
29
99
  // A permissive builder NodeInfo for an identifier the real component library
30
100
  // does not know (a product's own component, or an alpha/custom node that lives
31
101
  // only in the running studio image). It accepts any media and PASSES INPUT