@ekanos/sdk 0.21.0 → 0.22.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.
- package/dist/experience/define-experience.d.ts +2 -2
- package/dist/experience/define-experience.js.map +1 -1
- package/dist/experience/runtime.d.ts +3 -2
- package/dist/experience/runtime.js.map +1 -1
- package/dist/experience/workflow-template.d.ts +11 -0
- package/dist/experience/workflow-template.js +4 -10
- package/dist/experience/workflow-template.js.map +1 -1
- package/dist/types/workspace-target.d.ts +2 -3
- package/dist/types/workspace-target.js.map +1 -1
- package/package.json +3 -3
|
@@ -105,8 +105,8 @@ export type ExperiencePage = (Omit<ExperienceOverviewPageInput, 'integrations'>
|
|
|
105
105
|
* A layout the experience suggests: workspaces (named groups of widgets and
|
|
106
106
|
* pages) a Source admin can apply. Audiences are free-form NAMES, not roles or
|
|
107
107
|
* permissions: a package cannot know a Source's audiences, so the host maps a
|
|
108
|
-
* name to the Source audience of the same name and
|
|
109
|
-
* match for everyone.
|
|
108
|
+
* name to the Source's business type (level-1 audience) of the same name and
|
|
109
|
+
* leaves an item with no match for everyone.
|
|
110
110
|
*/
|
|
111
111
|
export type ExperienceSuggestedLayout = SuggestedLayout;
|
|
112
112
|
/** One reads-only section of the review queue; `read` must be a READ op of the integration. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-experience.js","sourceRoot":"","sources":["../../src/experience/define-experience.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EAGrB,eAAe,GAChB,MAAM,4BAA4B,CAAC;AA0BpC,MAAM,qBAAqB,GAAsB;IAC/C,OAAO;IACP,QAAQ;IACR,SAAS;IACT,UAAU;IACV,OAAO;IACP,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,aAAa;IACb,WAAW;IACX,SAAS;CACV,CAAC;AAuJF,SAAS,aAAa,CAAC,IAAyB;;IAC9C,MAAM,IAAI,SAAuB,IA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K;QACjC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,YAAY;YAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,MAAM,OAAO,UAAI,MAAA,UAAU,CAAC,WAAW,0CAAE,QAAQ,mCAAI,EAAE;QAC1D,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAChC,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QAC5C,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,EAAE;YAC9B,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import type { ComponentType } from 'react';\n\nimport {\n EXPERIENCE_PAGE_KINDS,\n SuggestedLayoutSchema,\n type ExperiencePageKind,\n type SuggestedLayout,\n surfaceProblems,\n} from '@ekanos/integration-schema';\n\nimport type { ReadOperationKey, IntegrationName } from './types';\nimport type { WorkflowTemplate } from './workflow-template';\n\n/**\n * Keys that belong to an INTEGRATION and have no meaning on an experience.\n * Typed `never` so passing one is a compile error that names the key; the\n * runtime check in {@link defineExperience} catches the same keys from\n * untyped code.\n */\nexport interface IntegrationOnlyKeys {\n oauth?: never;\n egress?: never;\n storage?: never;\n webhooks?: never;\n tools?: never;\n actions?: never;\n connection?: never;\n activation?: never;\n events?: never;\n agentEvents?: never;\n schedules?: never;\n secrets?: never;\n}\n\nconst INTEGRATION_ONLY_KEYS: readonly string[] = [\n 'oauth',\n 'egress',\n 'storage',\n 'webhooks',\n 'tools',\n 'actions',\n 'connection',\n 'activation',\n 'events',\n 'agentEvents',\n 'schedules',\n 'secrets',\n];\n\nexport type ExperienceWidgetWidth = 'compact' | 'half' | 'full';\n\nexport interface ExperienceWidget {\n /** kebab-case, unique within the experience. */\n id: string;\n title: string;\n /** Integrations this widget calls. Checked against `ekanos.json` `integrations` by `ekanos check`. */\n integrations: readonly IntegrationName[];\n width?: ExperienceWidgetWidth;\n /**\n * A plain React component. It receives no integration props: it calls\n * `useOperation` / `useOperationMutation` and renders with `@ekanos/ui`,\n * exactly as an integration widget does today.\n */\n component: ComponentType;\n isCollapsible?: boolean;\n isPinnable?: boolean;\n aiFooterEnabled?: boolean;\n}\n\n/** What a custom page's component receives. */\nexport interface ExperiencePageProps {\n /**\n * The route below the page's own path, as segments: `[]` at the page itself,\n * `['archive']` at `<page path>/archive`. Only the sub-routes a page declares\n * in `routes` are served.\n */\n path: string[];\n}\n\nexport interface ExperiencePageRoute {\n /** kebab-case segments joined by `/`, relative to the page: `archive`, `drafts/new`. */\n path: string;\n title: string;\n}\n\ninterface ExperiencePageBase {\n /** kebab-case, unique within the experience. */\n id: string;\n title: string;\n}\n\n/**\n * The experience's root, shown when someone opens it. Give it a `component`\n * for a hand-built landing page, or none for the host's default overview.\n * An experience has at most one.\n */\nexport interface ExperienceOverviewPageInput extends ExperiencePageBase {\n kind: 'overview';\n path?: never;\n integrations?: readonly IntegrationName[];\n component?: ComponentType<ExperiencePageProps>;\n}\n\n/**\n * A widget dashboard of the experience's own widgets, laid out by the host.\n * No component: `widgets` lists widget ids declared in this experience.\n */\nexport interface ExperienceCanvasPageInput extends ExperiencePageBase {\n kind: 'canvas';\n /** Route segment under the experience, e.g. `review`. */\n path: string;\n widgets: readonly string[];\n integrations?: readonly IntegrationName[];\n component?: never;\n}\n\n/** A page you build yourself. `kind` may be left out: this is the default. */\nexport interface ExperienceCustomPageInput extends ExperiencePageBase {\n kind?: 'custom';\n /** Route segment under the experience, e.g. `review`. */\n path: string;\n /** Sub-routes the component handles; it reads the remainder from its `path` prop. */\n routes?: readonly ExperiencePageRoute[];\n integrations: readonly IntegrationName[];\n component: ComponentType<ExperiencePageProps>;\n}\n\nexport type ExperiencePageInput =\n | ExperienceOverviewPageInput\n | ExperienceCanvasPageInput\n | ExperienceCustomPageInput;\n\n/** A page as `defineExperience` returns it: `kind` and `integrations` always set. */\nexport type ExperiencePage =\n | (Omit<ExperienceOverviewPageInput, 'integrations'> & {\n integrations: readonly IntegrationName[];\n })\n | (Omit<ExperienceCanvasPageInput, 'integrations'> & {\n integrations: readonly IntegrationName[];\n })\n | (Omit<ExperienceCustomPageInput, 'kind'> & { kind: 'custom' });\n\n/**\n * A layout the experience suggests: workspaces (named groups of widgets and\n * pages) a Source admin can apply. Audiences are free-form NAMES, not roles or\n * permissions: a package cannot know a Source's audiences, so the host maps a\n * name to the Source audience of the same name and leaves an item with no\n * match for everyone.\n */\nexport type ExperienceSuggestedLayout = SuggestedLayout;\n\n/** One reads-only section of the review queue; `read` must be a READ op of the integration. */\nexport type ReviewQueueSection = {\n [S in IntegrationName]: {\n id: string;\n integration: S;\n read: ReadOperationKey<S>;\n };\n}[IntegrationName];\n\nexport interface ExperienceReviewQueue {\n readsOnly: true;\n sections: readonly ReviewQueueSection[];\n}\n\n/** A declaration only: the host decides how the sidebar draws it. */\nexport interface ExperienceSidebar {\n section: string;\n icon: string;\n label: string;\n}\n\nexport interface ExperienceInput extends IntegrationOnlyKeys {\n /** kebab-case; must equal `slug` in `ekanos.json`. */\n slug: string;\n name: string;\n description?: string;\n sidebar?: ExperienceSidebar;\n widgets?: readonly ExperienceWidget[];\n pages?: readonly ExperiencePageInput[];\n workflows?: readonly WorkflowTemplate[];\n reviewQueue?: ExperienceReviewQueue;\n suggestedLayout?: ExperienceSuggestedLayout;\n}\n\nexport interface ExperienceDefinition {\n readonly kind: 'experience';\n readonly slug: string;\n readonly name: string;\n readonly description?: string;\n readonly sidebar?: ExperienceSidebar;\n readonly widgets: readonly ExperienceWidget[];\n readonly pages: readonly ExperiencePage[];\n readonly workflows: readonly WorkflowTemplate[];\n readonly reviewQueue?: ExperienceReviewQueue;\n readonly suggestedLayout?: ExperienceSuggestedLayout;\n}\n\nfunction normalizePage(page: ExperiencePageInput): ExperiencePage {\n const kind: ExperiencePageKind = page.kind ?? 'custom';\n const rawPath = (page as { path?: unknown }).path;\n if (kind === 'overview') {\n if (rawPath !== undefined) {\n throw new Error(\n `Invalid experience definition: overview page \"${page.id}\" is the experience's root and takes no path.`,\n );\n }\n } else if (typeof rawPath !== 'string' || rawPath === '') {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" needs a path (a kebab-case string).`,\n );\n }\n\n return {\n ...page,\n kind,\n integrations: page.integrations ?? [],\n } as ExperiencePage;\n}\n\nconst KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\nfunction assertUnique(kind: string, ids: readonly string[]): void {\n const seen = new Set<string>();\n for (const id of ids) {\n if (seen.has(id)) {\n throw new Error(\n `Invalid experience definition: ${kind} id \"${id}\" is declared twice.`,\n );\n }\n seen.add(id);\n }\n}\n\n/**\n * Declare an experience: widgets, pages, workflow templates and a reads-only\n * review queue that reach integrations only through their pinned contracts.\n *\n * Integrations are NOT declared here. They live in `ekanos.json` `integrations` (readable\n * without running code) and `ekanos codegen` types them; naming an integration that is\n * not there is a compile error, and `ekanos check` re-verifies it.\n *\n * @example\n * export default defineExperience({\n * slug: 'content-engine',\n * name: 'Content engine',\n * widgets: [{ id: 'queue', title: 'Queue', integrations: ['cms'], component: Queue }],\n * });\n */\nexport function defineExperience(input: ExperienceInput): ExperienceDefinition {\n const raw = input as unknown as Record<string, unknown>;\n for (const key of INTEGRATION_ONLY_KEYS) {\n if (raw[key] !== undefined) {\n throw new Error(\n `Invalid experience definition: \"${key}\" belongs to an integration. An experience reaches integrations only through the integrations it declares (ekanos.json \"integrations\").`,\n );\n }\n }\n if (!KEBAB.test(input.slug)) {\n throw new Error(\n `Invalid experience definition: slug \"${input.slug}\" must be kebab-case.`,\n );\n }\n if (input.name.trim() === '') {\n throw new Error('Invalid experience definition: name is required.');\n }\n\n const widgets = input.widgets ?? [];\n const pages = input.pages ?? [];\n const workflows = input.workflows ?? [];\n\n for (const widget of widgets) {\n if (!KEBAB.test(widget.id)) {\n throw new Error(\n `Invalid experience definition: widget id \"${widget.id}\" must be kebab-case.`,\n );\n }\n if (\n typeof widget.component !== 'function' &&\n typeof widget.component !== 'object'\n ) {\n throw new Error(\n `Invalid experience definition: widget \"${widget.id}\" needs a component.`,\n );\n }\n }\n const normalizedPages = pages.map(normalizePage);\n for (const page of normalizedPages) {\n if (!(EXPERIENCE_PAGE_KINDS as readonly string[]).includes(page.kind)) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" has kind \"${String(page.kind)}\"; use overview, canvas or custom.`,\n );\n }\n if (\n !KEBAB.test(page.id) ||\n (page.kind !== 'overview' && !KEBAB.test(page.path))\n ) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" id and path must be kebab-case.`,\n );\n }\n const component = (page as { component?: unknown }).component;\n if (page.kind === 'canvas' && component !== undefined) {\n throw new Error(\n `Invalid experience definition: canvas page \"${page.id}\" takes \"widgets\", not a component.`,\n );\n }\n if (\n page.kind === 'custom' &&\n typeof component !== 'function' &&\n typeof component !== 'object'\n ) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" needs a component.`,\n );\n }\n }\n if (input.suggestedLayout !== undefined) {\n const parsed = SuggestedLayoutSchema.safeParse(input.suggestedLayout);\n if (!parsed.success) {\n throw new Error(\n `Invalid experience definition: suggestedLayout is malformed: ${parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ')}.`,\n );\n }\n }\n const problems = surfaceProblems({\n widgets,\n pages: normalizedPages.map((page) => ({\n id: page.id,\n kind: page.kind,\n ...(page.kind === 'overview' ? {} : { path: page.path }),\n ...(page.kind === 'canvas' ? { widgets: page.widgets } : {}),\n ...(page.kind === 'custom' && page.routes ? { routes: page.routes } : {}),\n })),\n ...(input.suggestedLayout\n ? { suggestedLayout: input.suggestedLayout }\n : {}),\n });\n if (problems[0] !== undefined) {\n throw new Error(`Invalid experience definition: ${problems[0]}.`);\n }\n assertUnique(\n 'workflow template',\n workflows.map((w) => w.id),\n );\n\n if (input.reviewQueue) {\n if (input.reviewQueue.readsOnly !== true) {\n throw new Error(\n 'Invalid experience definition: reviewQueue.readsOnly must be true.',\n );\n }\n assertUnique(\n 'review queue section',\n input.reviewQueue.sections.map((s) => s.id),\n );\n }\n\n return Object.freeze({\n kind: 'experience' as const,\n slug: input.slug,\n name: input.name,\n ...(input.description === undefined\n ? {}\n : { description: input.description }),\n ...(input.sidebar === undefined ? {} : { sidebar: input.sidebar }),\n widgets: Object.freeze([...widgets]),\n pages: Object.freeze(normalizedPages),\n workflows: Object.freeze([...workflows]),\n ...(input.reviewQueue === undefined\n ? {}\n : { reviewQueue: input.reviewQueue }),\n ...(input.suggestedLayout === undefined\n ? {}\n : { suggestedLayout: input.suggestedLayout }),\n });\n}\n\n/** Integrations an experience definition touches, deduplicated (for `check`/manifest). */\nexport function slotsUsedBy(definition: ExperienceDefinition): string[] {\n const used = new Set<string>();\n for (const widget of definition.widgets)\n for (const s of widget.integrations) used.add(s);\n for (const page of definition.pages)\n for (const s of page.integrations) used.add(s);\n for (const section of definition.reviewQueue?.sections ?? [])\n used.add(section.integration);\n for (const template of definition.workflows) {\n for (const s of template.build())\n if (s.type === 'tool') used.add(s.integration);\n }\n\n return [...used].sort();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"define-experience.js","sourceRoot":"","sources":["../../src/experience/define-experience.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EAGrB,eAAe,GAChB,MAAM,4BAA4B,CAAC;AA0BpC,MAAM,qBAAqB,GAAsB;IAC/C,OAAO;IACP,QAAQ;IACR,SAAS;IACT,UAAU;IACV,OAAO;IACP,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,aAAa;IACb,WAAW;IACX,SAAS;CACV,CAAC;AAuJF,SAAS,aAAa,CAAC,IAAyB;;IAC9C,MAAM,IAAI,SAAuB,IAAI,CAAC,IAAI,mCAAI,QAAQ,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I,IAAI,CAAC,YAAY;YAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjD,KAAK,MAAM,OAAO,UAAI,MAAA,UAAU,CAAC,WAAW,0CAAE,QAAQ,mCAAI,EAAE;QAC1D,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAChC,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QAC5C,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,EAAE;YAC9B,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import type { ComponentType } from 'react';\n\nimport {\n EXPERIENCE_PAGE_KINDS,\n SuggestedLayoutSchema,\n type ExperiencePageKind,\n type SuggestedLayout,\n surfaceProblems,\n} from '@ekanos/integration-schema';\n\nimport type { ReadOperationKey, IntegrationName } from './types';\nimport type { WorkflowTemplate } from './workflow-template';\n\n/**\n * Keys that belong to an INTEGRATION and have no meaning on an experience.\n * Typed `never` so passing one is a compile error that names the key; the\n * runtime check in {@link defineExperience} catches the same keys from\n * untyped code.\n */\nexport interface IntegrationOnlyKeys {\n oauth?: never;\n egress?: never;\n storage?: never;\n webhooks?: never;\n tools?: never;\n actions?: never;\n connection?: never;\n activation?: never;\n events?: never;\n agentEvents?: never;\n schedules?: never;\n secrets?: never;\n}\n\nconst INTEGRATION_ONLY_KEYS: readonly string[] = [\n 'oauth',\n 'egress',\n 'storage',\n 'webhooks',\n 'tools',\n 'actions',\n 'connection',\n 'activation',\n 'events',\n 'agentEvents',\n 'schedules',\n 'secrets',\n];\n\nexport type ExperienceWidgetWidth = 'compact' | 'half' | 'full';\n\nexport interface ExperienceWidget {\n /** kebab-case, unique within the experience. */\n id: string;\n title: string;\n /** Integrations this widget calls. Checked against `ekanos.json` `integrations` by `ekanos check`. */\n integrations: readonly IntegrationName[];\n width?: ExperienceWidgetWidth;\n /**\n * A plain React component. It receives no integration props: it calls\n * `useOperation` / `useOperationMutation` and renders with `@ekanos/ui`,\n * exactly as an integration widget does today.\n */\n component: ComponentType;\n isCollapsible?: boolean;\n isPinnable?: boolean;\n aiFooterEnabled?: boolean;\n}\n\n/** What a custom page's component receives. */\nexport interface ExperiencePageProps {\n /**\n * The route below the page's own path, as segments: `[]` at the page itself,\n * `['archive']` at `<page path>/archive`. Only the sub-routes a page declares\n * in `routes` are served.\n */\n path: string[];\n}\n\nexport interface ExperiencePageRoute {\n /** kebab-case segments joined by `/`, relative to the page: `archive`, `drafts/new`. */\n path: string;\n title: string;\n}\n\ninterface ExperiencePageBase {\n /** kebab-case, unique within the experience. */\n id: string;\n title: string;\n}\n\n/**\n * The experience's root, shown when someone opens it. Give it a `component`\n * for a hand-built landing page, or none for the host's default overview.\n * An experience has at most one.\n */\nexport interface ExperienceOverviewPageInput extends ExperiencePageBase {\n kind: 'overview';\n path?: never;\n integrations?: readonly IntegrationName[];\n component?: ComponentType<ExperiencePageProps>;\n}\n\n/**\n * A widget dashboard of the experience's own widgets, laid out by the host.\n * No component: `widgets` lists widget ids declared in this experience.\n */\nexport interface ExperienceCanvasPageInput extends ExperiencePageBase {\n kind: 'canvas';\n /** Route segment under the experience, e.g. `review`. */\n path: string;\n widgets: readonly string[];\n integrations?: readonly IntegrationName[];\n component?: never;\n}\n\n/** A page you build yourself. `kind` may be left out: this is the default. */\nexport interface ExperienceCustomPageInput extends ExperiencePageBase {\n kind?: 'custom';\n /** Route segment under the experience, e.g. `review`. */\n path: string;\n /** Sub-routes the component handles; it reads the remainder from its `path` prop. */\n routes?: readonly ExperiencePageRoute[];\n integrations: readonly IntegrationName[];\n component: ComponentType<ExperiencePageProps>;\n}\n\nexport type ExperiencePageInput =\n | ExperienceOverviewPageInput\n | ExperienceCanvasPageInput\n | ExperienceCustomPageInput;\n\n/** A page as `defineExperience` returns it: `kind` and `integrations` always set. */\nexport type ExperiencePage =\n | (Omit<ExperienceOverviewPageInput, 'integrations'> & {\n integrations: readonly IntegrationName[];\n })\n | (Omit<ExperienceCanvasPageInput, 'integrations'> & {\n integrations: readonly IntegrationName[];\n })\n | (Omit<ExperienceCustomPageInput, 'kind'> & { kind: 'custom' });\n\n/**\n * A layout the experience suggests: workspaces (named groups of widgets and\n * pages) a Source admin can apply. Audiences are free-form NAMES, not roles or\n * permissions: a package cannot know a Source's audiences, so the host maps a\n * name to the Source's business type (level-1 audience) of the same name and\n * leaves an item with no match for everyone.\n */\nexport type ExperienceSuggestedLayout = SuggestedLayout;\n\n/** One reads-only section of the review queue; `read` must be a READ op of the integration. */\nexport type ReviewQueueSection = {\n [S in IntegrationName]: {\n id: string;\n integration: S;\n read: ReadOperationKey<S>;\n };\n}[IntegrationName];\n\nexport interface ExperienceReviewQueue {\n readsOnly: true;\n sections: readonly ReviewQueueSection[];\n}\n\n/** A declaration only: the host decides how the sidebar draws it. */\nexport interface ExperienceSidebar {\n section: string;\n icon: string;\n label: string;\n}\n\nexport interface ExperienceInput extends IntegrationOnlyKeys {\n /** kebab-case; must equal `slug` in `ekanos.json`. */\n slug: string;\n name: string;\n description?: string;\n sidebar?: ExperienceSidebar;\n widgets?: readonly ExperienceWidget[];\n pages?: readonly ExperiencePageInput[];\n workflows?: readonly WorkflowTemplate[];\n reviewQueue?: ExperienceReviewQueue;\n suggestedLayout?: ExperienceSuggestedLayout;\n}\n\nexport interface ExperienceDefinition {\n readonly kind: 'experience';\n readonly slug: string;\n readonly name: string;\n readonly description?: string;\n readonly sidebar?: ExperienceSidebar;\n readonly widgets: readonly ExperienceWidget[];\n readonly pages: readonly ExperiencePage[];\n readonly workflows: readonly WorkflowTemplate[];\n readonly reviewQueue?: ExperienceReviewQueue;\n readonly suggestedLayout?: ExperienceSuggestedLayout;\n}\n\nfunction normalizePage(page: ExperiencePageInput): ExperiencePage {\n const kind: ExperiencePageKind = page.kind ?? 'custom';\n const rawPath = (page as { path?: unknown }).path;\n if (kind === 'overview') {\n if (rawPath !== undefined) {\n throw new Error(\n `Invalid experience definition: overview page \"${page.id}\" is the experience's root and takes no path.`,\n );\n }\n } else if (typeof rawPath !== 'string' || rawPath === '') {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" needs a path (a kebab-case string).`,\n );\n }\n\n return {\n ...page,\n kind,\n integrations: page.integrations ?? [],\n } as ExperiencePage;\n}\n\nconst KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\nfunction assertUnique(kind: string, ids: readonly string[]): void {\n const seen = new Set<string>();\n for (const id of ids) {\n if (seen.has(id)) {\n throw new Error(\n `Invalid experience definition: ${kind} id \"${id}\" is declared twice.`,\n );\n }\n seen.add(id);\n }\n}\n\n/**\n * Declare an experience: widgets, pages, workflow templates and a reads-only\n * review queue that reach integrations only through their pinned contracts.\n *\n * Integrations are NOT declared here. They live in `ekanos.json` `integrations` (readable\n * without running code) and `ekanos codegen` types them; naming an integration that is\n * not there is a compile error, and `ekanos check` re-verifies it.\n *\n * @example\n * export default defineExperience({\n * slug: 'content-engine',\n * name: 'Content engine',\n * widgets: [{ id: 'queue', title: 'Queue', integrations: ['cms'], component: Queue }],\n * });\n */\nexport function defineExperience(input: ExperienceInput): ExperienceDefinition {\n const raw = input as unknown as Record<string, unknown>;\n for (const key of INTEGRATION_ONLY_KEYS) {\n if (raw[key] !== undefined) {\n throw new Error(\n `Invalid experience definition: \"${key}\" belongs to an integration. An experience reaches integrations only through the integrations it declares (ekanos.json \"integrations\").`,\n );\n }\n }\n if (!KEBAB.test(input.slug)) {\n throw new Error(\n `Invalid experience definition: slug \"${input.slug}\" must be kebab-case.`,\n );\n }\n if (input.name.trim() === '') {\n throw new Error('Invalid experience definition: name is required.');\n }\n\n const widgets = input.widgets ?? [];\n const pages = input.pages ?? [];\n const workflows = input.workflows ?? [];\n\n for (const widget of widgets) {\n if (!KEBAB.test(widget.id)) {\n throw new Error(\n `Invalid experience definition: widget id \"${widget.id}\" must be kebab-case.`,\n );\n }\n if (\n typeof widget.component !== 'function' &&\n typeof widget.component !== 'object'\n ) {\n throw new Error(\n `Invalid experience definition: widget \"${widget.id}\" needs a component.`,\n );\n }\n }\n const normalizedPages = pages.map(normalizePage);\n for (const page of normalizedPages) {\n if (!(EXPERIENCE_PAGE_KINDS as readonly string[]).includes(page.kind)) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" has kind \"${String(page.kind)}\"; use overview, canvas or custom.`,\n );\n }\n if (\n !KEBAB.test(page.id) ||\n (page.kind !== 'overview' && !KEBAB.test(page.path))\n ) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" id and path must be kebab-case.`,\n );\n }\n const component = (page as { component?: unknown }).component;\n if (page.kind === 'canvas' && component !== undefined) {\n throw new Error(\n `Invalid experience definition: canvas page \"${page.id}\" takes \"widgets\", not a component.`,\n );\n }\n if (\n page.kind === 'custom' &&\n typeof component !== 'function' &&\n typeof component !== 'object'\n ) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" needs a component.`,\n );\n }\n }\n if (input.suggestedLayout !== undefined) {\n const parsed = SuggestedLayoutSchema.safeParse(input.suggestedLayout);\n if (!parsed.success) {\n throw new Error(\n `Invalid experience definition: suggestedLayout is malformed: ${parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ')}.`,\n );\n }\n }\n const problems = surfaceProblems({\n widgets,\n pages: normalizedPages.map((page) => ({\n id: page.id,\n kind: page.kind,\n ...(page.kind === 'overview' ? {} : { path: page.path }),\n ...(page.kind === 'canvas' ? { widgets: page.widgets } : {}),\n ...(page.kind === 'custom' && page.routes ? { routes: page.routes } : {}),\n })),\n ...(input.suggestedLayout\n ? { suggestedLayout: input.suggestedLayout }\n : {}),\n });\n if (problems[0] !== undefined) {\n throw new Error(`Invalid experience definition: ${problems[0]}.`);\n }\n assertUnique(\n 'workflow template',\n workflows.map((w) => w.id),\n );\n\n if (input.reviewQueue) {\n if (input.reviewQueue.readsOnly !== true) {\n throw new Error(\n 'Invalid experience definition: reviewQueue.readsOnly must be true.',\n );\n }\n assertUnique(\n 'review queue section',\n input.reviewQueue.sections.map((s) => s.id),\n );\n }\n\n return Object.freeze({\n kind: 'experience' as const,\n slug: input.slug,\n name: input.name,\n ...(input.description === undefined\n ? {}\n : { description: input.description }),\n ...(input.sidebar === undefined ? {} : { sidebar: input.sidebar }),\n widgets: Object.freeze([...widgets]),\n pages: Object.freeze(normalizedPages),\n workflows: Object.freeze([...workflows]),\n ...(input.reviewQueue === undefined\n ? {}\n : { reviewQueue: input.reviewQueue }),\n ...(input.suggestedLayout === undefined\n ? {}\n : { suggestedLayout: input.suggestedLayout }),\n });\n}\n\n/** Integrations an experience definition touches, deduplicated (for `check`/manifest). */\nexport function slotsUsedBy(definition: ExperienceDefinition): string[] {\n const used = new Set<string>();\n for (const widget of definition.widgets)\n for (const s of widget.integrations) used.add(s);\n for (const page of definition.pages)\n for (const s of page.integrations) used.add(s);\n for (const section of definition.reviewQueue?.sections ?? [])\n used.add(section.integration);\n for (const template of definition.workflows) {\n for (const s of template.build())\n if (s.type === 'tool') used.add(s.integration);\n }\n\n return [...used].sort();\n}\n"]}
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* An experience calls operations through an {@link ExperienceRuntime} and
|
|
6
6
|
* through nothing else: no import of integration code, no `fetch` to an
|
|
7
7
|
* integration route. The local harness implements it over its own
|
|
8
|
-
* `/__ekanos/api/ops/run`; the host implements it over
|
|
9
|
-
*
|
|
8
|
+
* `/__ekanos/api/ops/run`; the host implements it over its experience route,
|
|
9
|
+
* `/api/experiences/<experience>/slots/…?account=<team>`, with the team's own
|
|
10
|
+
* connection to each integration (no install). Both answer with the same {@link OperationResult} and the same
|
|
10
11
|
* refusal reasons, so an experience behaves identically in either.
|
|
11
12
|
*
|
|
12
13
|
* Isomorphic and dependency-free: types only (plus the re-exports below).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/experience/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/experience/runtime.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,yBAAyB,GAI1B,MAAM,SAAS,CAAC","sourcesContent":["/**\n * `@ekanos/sdk/experience/runtime` — the ONE seam between an experience and\n * an integration.\n *\n * An experience calls operations through an {@link ExperienceRuntime} and\n * through nothing else: no import of integration code, no `fetch` to an\n * integration route. The local harness implements it over its own\n * `/__ekanos/api/ops/run`; the host implements it over its experience route,\n * `/api/experiences/<experience>/slots/…?account=<team>`, with the team's own\n * connection to each integration (no install). Both answer with the same {@link OperationResult} and the same\n * refusal reasons, so an experience behaves identically in either.\n *\n * Isomorphic and dependency-free: types only (plus the re-exports below).\n */\nimport type { OperationResult } from '@ekanos/integration-schema';\n\nexport {\n OPERATION_REFUSAL_REASONS,\n type OperationError,\n type OperationRefusalReason,\n type OperationResult,\n} from './types';\n\n/** The channel a call arrives on; writes are judged by it (see `write_refused_on_channel`). */\nexport type OperationChannel = 'http' | 'rsc' | 'workflow';\n\n/**\n * Proof that a person approved one write. Opaque to the experience: the\n * runtime mints it (the harness approvals tray; the host approval gate) and\n * checks it. An experience may carry one back into `mutate(input, { approval })`.\n */\nexport interface ApprovalToken {\n readonly id: string;\n}\n\nexport interface OperationCallRequest {\n /** The integration name from `ekanos.json` `integrations` (its slug). */\n integration: string;\n /** `tool/<name>` or `action/<name>`. The version is the one `ekanos.json` pins. */\n op: string;\n input: unknown;\n channel: OperationChannel;\n approval?: ApprovalToken;\n}\n\nexport type IntegrationProvenance = 'registry' | 'local';\n\n/** What a runtime can say about an integration (for UI badges, never for widgets' logic). */\nexport interface IntegrationInfo {\n name: string;\n version: string;\n provenance: IntegrationProvenance;\n bindingMode?: string;\n runMode?: 'fixtures' | 'live';\n}\n\nexport interface ExperienceRuntime {\n /**\n * Run one operation. May take as long as a person takes to decide: a write\n * on an approval-gated channel resolves only once the approval tray has\n * answered (`write_not_approved` when it was rejected). Never throws for a\n * refusal: those are `{ ok: false, reason }`. A rejected promise means the\n * runtime itself is broken.\n */\n call(request: OperationCallRequest): Promise<OperationResult<unknown>>;\n integrations(): IntegrationInfo[];\n}\n"]}
|
|
@@ -93,6 +93,17 @@ export interface SerializeWorkflowOptions {
|
|
|
93
93
|
* a template can never name an operation the contract lacks.
|
|
94
94
|
*/
|
|
95
95
|
effectOf: (integration: string, op: string) => 'read' | 'write' | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The experience's slug, written on every tool step as `experience`. The
|
|
98
|
+
* host resolves the running team's connection from it at run time.
|
|
99
|
+
*/
|
|
100
|
+
experience?: string;
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated Pass `experience`. Written on every tool step as
|
|
103
|
+
* `installationId` when `experience` is absent; with neither, steps carry
|
|
104
|
+
* the deprecated `TEMPLATE_INSTALLATION_ID` placeholder so a caller built
|
|
105
|
+
* against 0.21 keeps producing a valid template.
|
|
106
|
+
*/
|
|
96
107
|
installationId?: string;
|
|
97
108
|
}
|
|
98
109
|
/**
|
|
@@ -60,7 +60,9 @@ export { TEMPLATE_INSTALLATION_ID };
|
|
|
60
60
|
export function serializeWorkflowTemplate(template, options) {
|
|
61
61
|
var _a;
|
|
62
62
|
const steps = template.build();
|
|
63
|
-
const
|
|
63
|
+
const target = options.experience !== undefined
|
|
64
|
+
? { experience: options.experience }
|
|
65
|
+
: { installationId: (_a = options.installationId) !== null && _a !== void 0 ? _a : TEMPLATE_INSTALLATION_ID };
|
|
64
66
|
const where = `workflow template "${template.id}"`;
|
|
65
67
|
if (steps.length === 0)
|
|
66
68
|
throw new Error(`${where}: build() returned no steps.`);
|
|
@@ -91,15 +93,7 @@ export function serializeWorkflowTemplate(template, options) {
|
|
|
91
93
|
if (effect === undefined) {
|
|
92
94
|
throw new Error(`${where}: step "${s.id}" calls ${s.integration} ${s.op}, which the pinned contract does not declare.`);
|
|
93
95
|
}
|
|
94
|
-
return {
|
|
95
|
-
id: s.id,
|
|
96
|
-
type: 'fusion_tool',
|
|
97
|
-
tool: s.op,
|
|
98
|
-
installationId,
|
|
99
|
-
slot: s.integration,
|
|
100
|
-
args: s.args,
|
|
101
|
-
effect,
|
|
102
|
-
};
|
|
96
|
+
return Object.assign(Object.assign({ id: s.id, type: 'fusion_tool', tool: s.op }, target), { slot: s.integration, args: s.args, effect });
|
|
103
97
|
}
|
|
104
98
|
case 'ai':
|
|
105
99
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-template.js","sourceRoot":"","sources":["../../src/experience/workflow-template.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AAYpC,MAAM,UAAU,GAAG,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAE1E,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC;AA8CD,MAAM,OAAO,GAAG,CAAC,OAAgC,EAAE,EAAE,CACnD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,MAAK,SAAS;IAC1B,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC;QACE,KAAK,EACH,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC/B,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;YACjB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;KACzB,CAAC;AAER;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,CACF,EAAU,EACV,WAAc,EACd,EAAK,EACL,IAAoC,EACpC,OAAqB;QAErB,uBACE,IAAI,EAAE,MAAM,EACZ,EAAE;YACF,WAAW;YACX,EAAE,EACF,IAAI,EAAE,IA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C,CAAC,EAAE,WAAW,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,EAAE,+CAA+C,CACvG,CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,CAAC,CAAC,EAAE;oBACV,cAAc;oBACd,IAAI,EAAE,CAAC,CAAC,WAAW;oBACnB,IAAI,EAAE,CAAC,CAAC,IAGC;oBACT,MAAM;iBACP,CAAC;YACJ,CAAC;YACD,KAAK,IAAI;gBACP,OAAO;oBACL,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,YAAY,EAAE,CAAC,CAAC,YAAY;oBAC5B,eAAe,EAAE,CAAC,CAAC,eAAe;iBACnC,CAAC;YACJ,KAAK,UAAU;gBACb,OAAO;oBACL,EAAE,EAAE,CAAC,CAAC,EAAE;oBACR,IAAI,EAAE,eAAe;oBACrB,eAAe,EAAE,CAAC,CAAC,OAAO;oBAC1B,aAAa,EAAE,CAAC,CAAC,aAAa;iBAC/B,CAAC;QACN,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,GAAG;QACZ,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,OAAO,EACL,QAAQ,CAAC,QAAQ,KAAK,SAAS;YAC7B,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE;YACpB,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE;QACnD,KAAK,EAAE,QAAQ;QACf,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import {\n TEMPLATE_INSTALLATION_ID,\n type WorkflowTemplate as EngineWorkflowTemplate,\n} from '@ekanos/integration-schema';\n\nimport type { OperationInput, OperationKey, IntegrationName } from './types';\n\n/**\n * A reference to an earlier step's output (`{ ref: 'draft.title' }`), the\n * workflow engine's operand shape. Build one with {@link ref}.\n */\nexport interface WorkflowRef {\n readonly ref: string;\n}\n\nexport function ref(path: string): WorkflowRef {\n if (path.trim() === '') throw new Error('ref(): path must not be empty.');\n\n return { ref: path };\n}\n\n/** Each input field may be literal or a reference to an earlier step's output. */\nexport type WithRefs<T> = T extends readonly unknown[]\n ? T | WorkflowRef\n : T extends object\n ? { [P in keyof T]: WithRefs<T[P]> | WorkflowRef }\n : T | WorkflowRef;\n\nexport interface StepOptions {\n /**\n * Step id(s) this step follows. Default: the previous step in `build()`\n * order (the first step follows nothing).\n */\n after?: string | readonly string[];\n}\n\nexport interface ToolStep {\n readonly type: 'tool';\n readonly id: string;\n readonly integration: string;\n /** `tool/<name>` or `action/<name>`; effect comes from the pinned contract. */\n readonly op: string;\n readonly args: Record<string, unknown>;\n readonly after?: readonly string[];\n}\n\nexport interface AiStep {\n readonly type: 'ai';\n readonly id: string;\n readonly kind: string;\n readonly instructions: string;\n readonly outputSchemaRef: string;\n readonly after?: readonly string[];\n}\n\nexport interface ApprovalStep {\n readonly type: 'approval';\n readonly id: string;\n readonly summary: string;\n readonly approverScope: 'account' | 'user';\n readonly after?: readonly string[];\n}\n\nexport type WorkflowStep = ToolStep | AiStep | ApprovalStep;\n\nconst afterOf = (options: StepOptions | undefined) =>\n options?.after === undefined\n ? {}\n : {\n after:\n typeof options.after === 'string'\n ? [options.after]\n : [...options.after],\n };\n\n/**\n * Step constructors for {@link defineWorkflowTemplate}.\n *\n * `step.tool` is typed from the generated registry: the integration, the operation\n * and its `args` are checked against the pinned contract. Whether a tool step\n * reads or writes is NOT authored; it is read from the contract at build, so a\n * template cannot call a write as if it were a read.\n */\nexport const step = {\n tool<S extends IntegrationName, K extends OperationKey<S>>(\n id: string,\n integration: S,\n op: K,\n args: WithRefs<OperationInput<S, K>>,\n options?: StepOptions,\n ): ToolStep {\n return {\n type: 'tool',\n id,\n integration,\n op,\n args: args as Record<string, unknown>,\n ...afterOf(options),\n };\n },\n ai(\n id: string,\n config: { instructions: string; outputSchemaRef: string; kind?: string },\n options?: StepOptions,\n ): AiStep {\n return {\n type: 'ai',\n id,\n kind: config.kind ?? 'draft',\n instructions: config.instructions,\n outputSchemaRef: config.outputSchemaRef,\n ...afterOf(options),\n };\n },\n approval(\n id: string,\n config: { summary: string; approverScope?: 'account' | 'user' },\n options?: StepOptions,\n ): ApprovalStep {\n return {\n type: 'approval',\n id,\n summary: config.summary,\n approverScope: config.approverScope ?? 'account',\n ...afterOf(options),\n };\n },\n};\n\nconst TEMPLATE_ID = /^[a-z][a-z0-9-]*$/;\nconst STEP_ID = /^[a-z][a-z0-9_]*$/;\nconst RESERVED_STEP_IDS = new Set(['trigger', 'item', 'loop', 'run']);\n\nexport interface WorkflowTemplateInput {\n /** kebab-case, unique within the experience. */\n id: string;\n name: string;\n /** A 5-field cron expression. Omit for a template that is started by hand. */\n schedule?: string;\n scope?: 'account' | 'user';\n /** Evaluated at `ekanos build`, never at runtime. */\n build: () => readonly WorkflowStep[];\n}\n\nexport interface WorkflowTemplate {\n readonly kind: 'workflow-template';\n readonly id: string;\n readonly name: string;\n readonly schedule?: string;\n readonly scope: 'account' | 'user';\n readonly build: () => readonly WorkflowStep[];\n}\n\nexport function defineWorkflowTemplate(\n input: WorkflowTemplateInput,\n): WorkflowTemplate {\n if (!TEMPLATE_ID.test(input.id)) {\n throw new Error(\n `defineWorkflowTemplate: id \"${input.id}\" must be kebab-case (e.g. \"morning-digest\").`,\n );\n }\n if (input.name.trim() === '') {\n throw new Error(`defineWorkflowTemplate(\"${input.id}\"): name is required.`);\n }\n if (\n input.schedule !== undefined &&\n input.schedule.trim().split(/\\s+/).length !== 5\n ) {\n throw new Error(\n `defineWorkflowTemplate(\"${input.id}\"): schedule must be a 5-field cron expression, got \"${input.schedule}\".`,\n );\n }\n\n return Object.freeze({\n kind: 'workflow-template' as const,\n id: input.id,\n name: input.name,\n ...(input.schedule === undefined ? {} : { schedule: input.schedule }),\n scope: input.scope ?? 'account',\n build: input.build,\n });\n}\n\n/** The serialized workflow the host's engine runs (validated by `WorkflowTemplateSchema`). */\nexport type WorkflowDsl = EngineWorkflowTemplate;\n\nexport { TEMPLATE_INSTALLATION_ID };\n\nexport interface SerializeWorkflowOptions {\n /**\n * Reads `read`/`write` for an integration operation from the pinned contract. Return\n * `undefined` when the operation is unknown: serialization then throws, so\n * a template can never name an operation the contract lacks.\n */\n effectOf: (integration: string, op: string) => 'read' | 'write' | undefined;\n installationId?: string;\n}\n\n/**\n * Turn a template into the engine's DSL. Pure and deterministic: the same\n * template and contracts always give the same JSON (it is hashed into the\n * manifest digest).\n */\nexport function serializeWorkflowTemplate(\n template: WorkflowTemplate,\n options: SerializeWorkflowOptions,\n): WorkflowDsl {\n const steps = template.build();\n const installationId = options.installationId ?? TEMPLATE_INSTALLATION_ID;\n const where = `workflow template \"${template.id}\"`;\n\n if (steps.length === 0)\n throw new Error(`${where}: build() returned no steps.`);\n\n const seen = new Set<string>();\n for (const s of steps) {\n if (!STEP_ID.test(s.id) || RESERVED_STEP_IDS.has(s.id)) {\n throw new Error(`${where}: step id \"${s.id}\" is invalid or reserved.`);\n }\n if (seen.has(s.id))\n throw new Error(`${where}: step id \"${s.id}\" is used twice.`);\n seen.add(s.id);\n }\n\n const edges: WorkflowDsl['edges'] = [];\n steps.forEach((s, index) => {\n const predecessors = s.after ?? (index === 0 ? [] : [steps[index - 1]!.id]);\n for (const from of predecessors) {\n if (!seen.has(from)) {\n throw new Error(\n `${where}: step \"${s.id}\" follows unknown step \"${from}\".`,\n );\n }\n edges.push({ from, to: s.id });\n }\n });\n\n const dslSteps = steps.map((s): WorkflowDsl['steps'][number] => {\n switch (s.type) {\n case 'tool': {\n const effect = options.effectOf(s.integration, s.op);\n if (effect === undefined) {\n throw new Error(\n `${where}: step \"${s.id}\" calls ${s.integration} ${s.op}, which the pinned contract does not declare.`,\n );\n }\n\n return {\n id: s.id,\n type: 'fusion_tool',\n tool: s.op,\n installationId,\n slot: s.integration,\n args: s.args as Extract<\n WorkflowDsl['steps'][number],\n { type: 'fusion_tool' }\n >['args'],\n effect,\n };\n }\n case 'ai':\n return {\n id: s.id,\n type: 'ai_step',\n kind: s.kind,\n instructions: s.instructions,\n outputSchemaRef: s.outputSchemaRef,\n };\n case 'approval':\n return {\n id: s.id,\n type: 'approval_gate',\n summaryTemplate: s.summary,\n approverScope: s.approverScope,\n };\n }\n });\n\n return {\n version: '1',\n name: template.name,\n scope: template.scope,\n trigger:\n template.schedule === undefined\n ? { type: 'manual' }\n : { type: 'schedule', cron: template.schedule },\n steps: dslSteps,\n edges,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow-template.js","sourceRoot":"","sources":["../../src/experience/workflow-template.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,4BAA4B,CAAC;AAYpC,MAAM,UAAU,GAAG,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAE1E,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC;AA8CD,MAAM,OAAO,GAAG,CAAC,OAAgC,EAAE,EAAE,CACnD,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,MAAK,SAAS;IAC1B,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC;QACE,KAAK,EACH,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC/B,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;YACjB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;KACzB,CAAC;AAER;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,IAAI,CACF,EAAU,EACV,WAAc,EACd,EAAK,EACL,IAAoC,EACpC,OAAqB;QAErB,uBACE,IAAI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ACnD,KAAK,EAAE,QAAQ;QACf,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import {\n TEMPLATE_INSTALLATION_ID,\n type WorkflowTemplate as EngineWorkflowTemplate,\n} from '@ekanos/integration-schema';\n\nimport type { OperationInput, OperationKey, IntegrationName } from './types';\n\n/**\n * A reference to an earlier step's output (`{ ref: 'draft.title' }`), the\n * workflow engine's operand shape. Build one with {@link ref}.\n */\nexport interface WorkflowRef {\n readonly ref: string;\n}\n\nexport function ref(path: string): WorkflowRef {\n if (path.trim() === '') throw new Error('ref(): path must not be empty.');\n\n return { ref: path };\n}\n\n/** Each input field may be literal or a reference to an earlier step's output. */\nexport type WithRefs<T> = T extends readonly unknown[]\n ? T | WorkflowRef\n : T extends object\n ? { [P in keyof T]: WithRefs<T[P]> | WorkflowRef }\n : T | WorkflowRef;\n\nexport interface StepOptions {\n /**\n * Step id(s) this step follows. Default: the previous step in `build()`\n * order (the first step follows nothing).\n */\n after?: string | readonly string[];\n}\n\nexport interface ToolStep {\n readonly type: 'tool';\n readonly id: string;\n readonly integration: string;\n /** `tool/<name>` or `action/<name>`; effect comes from the pinned contract. */\n readonly op: string;\n readonly args: Record<string, unknown>;\n readonly after?: readonly string[];\n}\n\nexport interface AiStep {\n readonly type: 'ai';\n readonly id: string;\n readonly kind: string;\n readonly instructions: string;\n readonly outputSchemaRef: string;\n readonly after?: readonly string[];\n}\n\nexport interface ApprovalStep {\n readonly type: 'approval';\n readonly id: string;\n readonly summary: string;\n readonly approverScope: 'account' | 'user';\n readonly after?: readonly string[];\n}\n\nexport type WorkflowStep = ToolStep | AiStep | ApprovalStep;\n\nconst afterOf = (options: StepOptions | undefined) =>\n options?.after === undefined\n ? {}\n : {\n after:\n typeof options.after === 'string'\n ? [options.after]\n : [...options.after],\n };\n\n/**\n * Step constructors for {@link defineWorkflowTemplate}.\n *\n * `step.tool` is typed from the generated registry: the integration, the operation\n * and its `args` are checked against the pinned contract. Whether a tool step\n * reads or writes is NOT authored; it is read from the contract at build, so a\n * template cannot call a write as if it were a read.\n */\nexport const step = {\n tool<S extends IntegrationName, K extends OperationKey<S>>(\n id: string,\n integration: S,\n op: K,\n args: WithRefs<OperationInput<S, K>>,\n options?: StepOptions,\n ): ToolStep {\n return {\n type: 'tool',\n id,\n integration,\n op,\n args: args as Record<string, unknown>,\n ...afterOf(options),\n };\n },\n ai(\n id: string,\n config: { instructions: string; outputSchemaRef: string; kind?: string },\n options?: StepOptions,\n ): AiStep {\n return {\n type: 'ai',\n id,\n kind: config.kind ?? 'draft',\n instructions: config.instructions,\n outputSchemaRef: config.outputSchemaRef,\n ...afterOf(options),\n };\n },\n approval(\n id: string,\n config: { summary: string; approverScope?: 'account' | 'user' },\n options?: StepOptions,\n ): ApprovalStep {\n return {\n type: 'approval',\n id,\n summary: config.summary,\n approverScope: config.approverScope ?? 'account',\n ...afterOf(options),\n };\n },\n};\n\nconst TEMPLATE_ID = /^[a-z][a-z0-9-]*$/;\nconst STEP_ID = /^[a-z][a-z0-9_]*$/;\nconst RESERVED_STEP_IDS = new Set(['trigger', 'item', 'loop', 'run']);\n\nexport interface WorkflowTemplateInput {\n /** kebab-case, unique within the experience. */\n id: string;\n name: string;\n /** A 5-field cron expression. Omit for a template that is started by hand. */\n schedule?: string;\n scope?: 'account' | 'user';\n /** Evaluated at `ekanos build`, never at runtime. */\n build: () => readonly WorkflowStep[];\n}\n\nexport interface WorkflowTemplate {\n readonly kind: 'workflow-template';\n readonly id: string;\n readonly name: string;\n readonly schedule?: string;\n readonly scope: 'account' | 'user';\n readonly build: () => readonly WorkflowStep[];\n}\n\nexport function defineWorkflowTemplate(\n input: WorkflowTemplateInput,\n): WorkflowTemplate {\n if (!TEMPLATE_ID.test(input.id)) {\n throw new Error(\n `defineWorkflowTemplate: id \"${input.id}\" must be kebab-case (e.g. \"morning-digest\").`,\n );\n }\n if (input.name.trim() === '') {\n throw new Error(`defineWorkflowTemplate(\"${input.id}\"): name is required.`);\n }\n if (\n input.schedule !== undefined &&\n input.schedule.trim().split(/\\s+/).length !== 5\n ) {\n throw new Error(\n `defineWorkflowTemplate(\"${input.id}\"): schedule must be a 5-field cron expression, got \"${input.schedule}\".`,\n );\n }\n\n return Object.freeze({\n kind: 'workflow-template' as const,\n id: input.id,\n name: input.name,\n ...(input.schedule === undefined ? {} : { schedule: input.schedule }),\n scope: input.scope ?? 'account',\n build: input.build,\n });\n}\n\n/** The serialized workflow the host's engine runs (validated by `WorkflowTemplateSchema`). */\nexport type WorkflowDsl = EngineWorkflowTemplate;\n\nexport { TEMPLATE_INSTALLATION_ID };\n\nexport interface SerializeWorkflowOptions {\n /**\n * Reads `read`/`write` for an integration operation from the pinned contract. Return\n * `undefined` when the operation is unknown: serialization then throws, so\n * a template can never name an operation the contract lacks.\n */\n effectOf: (integration: string, op: string) => 'read' | 'write' | undefined;\n /**\n * The experience's slug, written on every tool step as `experience`. The\n * host resolves the running team's connection from it at run time.\n */\n experience?: string;\n /**\n * @deprecated Pass `experience`. Written on every tool step as\n * `installationId` when `experience` is absent; with neither, steps carry\n * the deprecated `TEMPLATE_INSTALLATION_ID` placeholder so a caller built\n * against 0.21 keeps producing a valid template.\n */\n installationId?: string;\n}\n\n/**\n * Turn a template into the engine's DSL. Pure and deterministic: the same\n * template and contracts always give the same JSON (it is hashed into the\n * manifest digest).\n */\nexport function serializeWorkflowTemplate(\n template: WorkflowTemplate,\n options: SerializeWorkflowOptions,\n): WorkflowDsl {\n const steps = template.build();\n const target =\n options.experience !== undefined\n ? { experience: options.experience }\n : { installationId: options.installationId ?? TEMPLATE_INSTALLATION_ID };\n const where = `workflow template \"${template.id}\"`;\n\n if (steps.length === 0)\n throw new Error(`${where}: build() returned no steps.`);\n\n const seen = new Set<string>();\n for (const s of steps) {\n if (!STEP_ID.test(s.id) || RESERVED_STEP_IDS.has(s.id)) {\n throw new Error(`${where}: step id \"${s.id}\" is invalid or reserved.`);\n }\n if (seen.has(s.id))\n throw new Error(`${where}: step id \"${s.id}\" is used twice.`);\n seen.add(s.id);\n }\n\n const edges: WorkflowDsl['edges'] = [];\n steps.forEach((s, index) => {\n const predecessors = s.after ?? (index === 0 ? [] : [steps[index - 1]!.id]);\n for (const from of predecessors) {\n if (!seen.has(from)) {\n throw new Error(\n `${where}: step \"${s.id}\" follows unknown step \"${from}\".`,\n );\n }\n edges.push({ from, to: s.id });\n }\n });\n\n const dslSteps = steps.map((s): WorkflowDsl['steps'][number] => {\n switch (s.type) {\n case 'tool': {\n const effect = options.effectOf(s.integration, s.op);\n if (effect === undefined) {\n throw new Error(\n `${where}: step \"${s.id}\" calls ${s.integration} ${s.op}, which the pinned contract does not declare.`,\n );\n }\n\n return {\n id: s.id,\n type: 'fusion_tool',\n tool: s.op,\n ...target,\n slot: s.integration,\n args: s.args as Extract<\n WorkflowDsl['steps'][number],\n { type: 'fusion_tool' }\n >['args'],\n effect,\n };\n }\n case 'ai':\n return {\n id: s.id,\n type: 'ai_step',\n kind: s.kind,\n instructions: s.instructions,\n outputSchemaRef: s.outputSchemaRef,\n };\n case 'approval':\n return {\n id: s.id,\n type: 'approval_gate',\n summaryTemplate: s.summary,\n approverScope: s.approverScope,\n };\n }\n });\n\n return {\n version: '1',\n name: template.name,\n scope: template.scope,\n trigger:\n template.schedule === undefined\n ? { type: 'manual' }\n : { type: 'schedule', cron: template.schedule },\n steps: dslSteps,\n edges,\n };\n}\n"]}
|
|
@@ -16,9 +16,8 @@ export interface WorkspaceTargetDefinition {
|
|
|
16
16
|
* alphanumeric with single hyphens between segments. */
|
|
17
17
|
slug: string;
|
|
18
18
|
name: string;
|
|
19
|
-
/** A Font Awesome class string, e.g. `fa-inbox`.
|
|
20
|
-
*
|
|
21
|
-
* not be written. Validated by the host at gate time. */
|
|
19
|
+
/** A Font Awesome class string, e.g. `fa-inbox`. Validated by the host at
|
|
20
|
+
* gate time. */
|
|
22
21
|
icon?: string;
|
|
23
22
|
description?: string;
|
|
24
23
|
/** Defaults to `'masonry'` when omitted. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-target.js","sourceRoot":"","sources":["../../src/types/workspace-target.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The contract an integration uses to declare the workspaces it ships with\n * (`BaseIntegration.getWorkspaceTargets()`).\n *\n * The host's canonical definition is `z.input<typeof WorkspaceTargetSchema>`\n * (`@kit/integrations-core`, `schemas/workspace-target.schema.ts`) — the\n * schema validates declarations in CI and at materialization time, including\n * cross-field rules a type cannot carry (icon-name validity, slug format,\n * `inheritsWidgets`/`includedWidgetIds` exclusivity, one inheriting target\n * per set). This structural twin exists so the SDK's root entrypoint owns its\n * types without importing the host schema; the parity test beside these types\n * keeps the two shapes mutually assignable.\n */\nexport interface WorkspaceTargetDefinition {\n /** Stable URL segment — `/workspace/<slug>` routes reference it. Lowercase\n * alphanumeric with single hyphens between segments. */\n slug: string;\n name: string;\n /** A Font Awesome class string, e.g. `fa-inbox`.
|
|
1
|
+
{"version":3,"file":"workspace-target.js","sourceRoot":"","sources":["../../src/types/workspace-target.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The contract an integration uses to declare the workspaces it ships with\n * (`BaseIntegration.getWorkspaceTargets()`).\n *\n * The host's canonical definition is `z.input<typeof WorkspaceTargetSchema>`\n * (`@kit/integrations-core`, `schemas/workspace-target.schema.ts`) — the\n * schema validates declarations in CI and at materialization time, including\n * cross-field rules a type cannot carry (icon-name validity, slug format,\n * `inheritsWidgets`/`includedWidgetIds` exclusivity, one inheriting target\n * per set). This structural twin exists so the SDK's root entrypoint owns its\n * types without importing the host schema; the parity test beside these types\n * keeps the two shapes mutually assignable.\n */\nexport interface WorkspaceTargetDefinition {\n /** Stable URL segment — `/workspace/<slug>` routes reference it. Lowercase\n * alphanumeric with single hyphens between segments. */\n slug: string;\n name: string;\n /** A Font Awesome class string, e.g. `fa-inbox`. Validated by the host at\n * gate time. */\n icon?: string;\n description?: string;\n /** Defaults to `'masonry'` when omitted. */\n layout?: 'masonry' | 'two-column';\n /**\n * Whether this workspace receives the product's otherwise-unplaced\n * widgets. Exactly one target per product must set it; mutually exclusive\n * with `includedWidgetIds`.\n */\n inheritsWidgets?: boolean;\n /** Limit this workspace to specific widget ids. */\n includedWidgetIds?: string[];\n /**\n * Create this workspace on a Source as soon as the product is made\n * available there, instead of waiting for an admin to add it. Only for a\n * product that works as shipped (`activation: { required: false }`).\n */\n materializeOnEntitlement?: boolean;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekanos/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The official SDK for building Ekanos integrations.",
|
|
6
6
|
"homepage": "https://sdk.ekanos.dev/sdk/overview",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"access": "public"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@ekanos/integration-schema": "0.
|
|
118
|
-
"@ekanos/ui": "0.
|
|
117
|
+
"@ekanos/integration-schema": "0.22.0",
|
|
118
|
+
"@ekanos/ui": "0.22.0",
|
|
119
119
|
"@supabase/supabase-js": "2.118.0",
|
|
120
120
|
"server-only": "^0.0.1",
|
|
121
121
|
"zod-to-json-schema": "3.25.2"
|