@ekanos/sdk 0.18.0 → 0.19.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/api-report.md +92 -1
- package/dist/components/base-activation-dialog.js +1 -1
- package/dist/components/base-activation-dialog.js.map +1 -1
- package/dist/components/widgets/widget-ask-bar.js +1 -1
- package/dist/components/widgets/widget-ask-bar.js.map +1 -1
- package/dist/components/widgets/widget.js +17 -2
- package/dist/components/widgets/widget.js.map +1 -1
- package/dist/contract/derive-contract.d.ts +14 -0
- package/dist/contract/derive-contract.js +237 -0
- package/dist/contract/derive-contract.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.js +9 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/synthesize-example.d.ts +6 -0
- package/dist/contract/synthesize-example.js +61 -0
- package/dist/contract/synthesize-example.js.map +1 -0
- package/dist/contract/to-json-schema.d.ts +19 -0
- package/dist/contract/to-json-schema.js +300 -0
- package/dist/contract/to-json-schema.js.map +1 -0
- package/dist/contract/types.d.ts +39 -0
- package/dist/contract/types.js +12 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/experience/client.d.ts +55 -0
- package/dist/experience/client.js +125 -0
- package/dist/experience/client.js.map +1 -0
- package/dist/experience/define-experience.d.ts +107 -0
- package/dist/experience/define-experience.js +107 -0
- package/dist/experience/define-experience.js.map +1 -0
- package/dist/experience/index.d.ts +12 -0
- package/dist/experience/index.js +12 -0
- package/dist/experience/index.js.map +1 -0
- package/dist/experience/runtime.d.ts +54 -0
- package/dist/experience/runtime.js +2 -0
- package/dist/experience/runtime.js.map +1 -0
- package/dist/experience/server.d.ts +11 -0
- package/dist/experience/server.js +47 -0
- package/dist/experience/server.js.map +1 -0
- package/dist/experience/types.d.ts +76 -0
- package/dist/experience/types.js +2 -0
- package/dist/experience/types.js.map +1 -0
- package/dist/experience/workflow-template.d.ts +103 -0
- package/dist/experience/workflow-template.js +132 -0
- package/dist/experience/workflow-template.js.map +1 -0
- package/eslint.design-preset.mjs +3 -2
- package/eslint.design-rules.mjs +267 -3
- package/eslint.experience-preset.mjs +85 -0
- package/package.json +44 -6
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { ReadOperationKey, IntegrationName } from './types.js';
|
|
3
|
+
import type { WorkflowTemplate } from './workflow-template.js';
|
|
4
|
+
/**
|
|
5
|
+
* Keys that belong to an INTEGRATION and have no meaning on an experience.
|
|
6
|
+
* Typed `never` so passing one is a compile error that names the key; the
|
|
7
|
+
* runtime check in {@link defineExperience} catches the same keys from
|
|
8
|
+
* untyped code.
|
|
9
|
+
*/
|
|
10
|
+
export interface IntegrationOnlyKeys {
|
|
11
|
+
oauth?: never;
|
|
12
|
+
egress?: never;
|
|
13
|
+
storage?: never;
|
|
14
|
+
webhooks?: never;
|
|
15
|
+
tools?: never;
|
|
16
|
+
actions?: never;
|
|
17
|
+
connection?: never;
|
|
18
|
+
activation?: never;
|
|
19
|
+
events?: never;
|
|
20
|
+
agentEvents?: never;
|
|
21
|
+
schedules?: never;
|
|
22
|
+
secrets?: never;
|
|
23
|
+
}
|
|
24
|
+
export type ExperienceWidgetWidth = 'compact' | 'half' | 'full';
|
|
25
|
+
export interface ExperienceWidget {
|
|
26
|
+
/** kebab-case, unique within the experience. */
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
/** Integrations this widget calls. Checked against `ekanos.json` `integrations` by `ekanos check`. */
|
|
30
|
+
integrations: readonly IntegrationName[];
|
|
31
|
+
width?: ExperienceWidgetWidth;
|
|
32
|
+
/**
|
|
33
|
+
* A plain React component. It receives no integration props: it calls
|
|
34
|
+
* `useOperation` / `useOperationMutation` and renders with `@ekanos/ui`,
|
|
35
|
+
* exactly as an integration widget does today.
|
|
36
|
+
*/
|
|
37
|
+
component: ComponentType;
|
|
38
|
+
isCollapsible?: boolean;
|
|
39
|
+
isPinnable?: boolean;
|
|
40
|
+
aiFooterEnabled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ExperiencePage {
|
|
43
|
+
id: string;
|
|
44
|
+
/** Route segment under the experience, e.g. `review`. */
|
|
45
|
+
path: string;
|
|
46
|
+
title: string;
|
|
47
|
+
integrations: readonly IntegrationName[];
|
|
48
|
+
component: ComponentType;
|
|
49
|
+
}
|
|
50
|
+
/** One reads-only section of the review queue; `read` must be a READ op of the integration. */
|
|
51
|
+
export type ReviewQueueSection = {
|
|
52
|
+
[S in IntegrationName]: {
|
|
53
|
+
id: string;
|
|
54
|
+
integration: S;
|
|
55
|
+
read: ReadOperationKey<S>;
|
|
56
|
+
};
|
|
57
|
+
}[IntegrationName];
|
|
58
|
+
export interface ExperienceReviewQueue {
|
|
59
|
+
readsOnly: true;
|
|
60
|
+
sections: readonly ReviewQueueSection[];
|
|
61
|
+
}
|
|
62
|
+
/** A declaration only: the host decides how the sidebar draws it. */
|
|
63
|
+
export interface ExperienceSidebar {
|
|
64
|
+
section: string;
|
|
65
|
+
icon: string;
|
|
66
|
+
label: string;
|
|
67
|
+
}
|
|
68
|
+
export interface ExperienceInput extends IntegrationOnlyKeys {
|
|
69
|
+
/** kebab-case; must equal `slug` in `ekanos.json`. */
|
|
70
|
+
slug: string;
|
|
71
|
+
name: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
sidebar?: ExperienceSidebar;
|
|
74
|
+
widgets?: readonly ExperienceWidget[];
|
|
75
|
+
pages?: readonly ExperiencePage[];
|
|
76
|
+
workflows?: readonly WorkflowTemplate[];
|
|
77
|
+
reviewQueue?: ExperienceReviewQueue;
|
|
78
|
+
}
|
|
79
|
+
export interface ExperienceDefinition {
|
|
80
|
+
readonly kind: 'experience';
|
|
81
|
+
readonly slug: string;
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly description?: string;
|
|
84
|
+
readonly sidebar?: ExperienceSidebar;
|
|
85
|
+
readonly widgets: readonly ExperienceWidget[];
|
|
86
|
+
readonly pages: readonly ExperiencePage[];
|
|
87
|
+
readonly workflows: readonly WorkflowTemplate[];
|
|
88
|
+
readonly reviewQueue?: ExperienceReviewQueue;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Declare an experience: widgets, pages, workflow templates and a reads-only
|
|
92
|
+
* review queue that reach integrations only through their pinned contracts.
|
|
93
|
+
*
|
|
94
|
+
* Integrations are NOT declared here. They live in `ekanos.json` `integrations` (readable
|
|
95
|
+
* without running code) and `ekanos codegen` types them; naming an integration that is
|
|
96
|
+
* not there is a compile error, and `ekanos check` re-verifies it.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* export default defineExperience({
|
|
100
|
+
* slug: 'content-engine',
|
|
101
|
+
* name: 'Content engine',
|
|
102
|
+
* widgets: [{ id: 'queue', title: 'Queue', integrations: ['cms'], component: Queue }],
|
|
103
|
+
* });
|
|
104
|
+
*/
|
|
105
|
+
export declare function defineExperience(input: ExperienceInput): ExperienceDefinition;
|
|
106
|
+
/** Integrations an experience definition touches, deduplicated (for `check`/manifest). */
|
|
107
|
+
export declare function slotsUsedBy(definition: ExperienceDefinition): string[];
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const INTEGRATION_ONLY_KEYS = [
|
|
2
|
+
'oauth',
|
|
3
|
+
'egress',
|
|
4
|
+
'storage',
|
|
5
|
+
'webhooks',
|
|
6
|
+
'tools',
|
|
7
|
+
'actions',
|
|
8
|
+
'connection',
|
|
9
|
+
'activation',
|
|
10
|
+
'events',
|
|
11
|
+
'agentEvents',
|
|
12
|
+
'schedules',
|
|
13
|
+
'secrets',
|
|
14
|
+
];
|
|
15
|
+
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
16
|
+
function assertUnique(kind, ids) {
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
for (const id of ids) {
|
|
19
|
+
if (seen.has(id)) {
|
|
20
|
+
throw new Error(`Invalid experience definition: ${kind} id "${id}" is declared twice.`);
|
|
21
|
+
}
|
|
22
|
+
seen.add(id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Declare an experience: widgets, pages, workflow templates and a reads-only
|
|
27
|
+
* review queue that reach integrations only through their pinned contracts.
|
|
28
|
+
*
|
|
29
|
+
* Integrations are NOT declared here. They live in `ekanos.json` `integrations` (readable
|
|
30
|
+
* without running code) and `ekanos codegen` types them; naming an integration that is
|
|
31
|
+
* not there is a compile error, and `ekanos check` re-verifies it.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* export default defineExperience({
|
|
35
|
+
* slug: 'content-engine',
|
|
36
|
+
* name: 'Content engine',
|
|
37
|
+
* widgets: [{ id: 'queue', title: 'Queue', integrations: ['cms'], component: Queue }],
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
export function defineExperience(input) {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
const raw = input;
|
|
43
|
+
for (const key of INTEGRATION_ONLY_KEYS) {
|
|
44
|
+
if (raw[key] !== undefined) {
|
|
45
|
+
throw new Error(`Invalid experience definition: "${key}" belongs to an integration. An experience reaches integrations only through the integrations it declares (ekanos.json "integrations").`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!KEBAB.test(input.slug)) {
|
|
49
|
+
throw new Error(`Invalid experience definition: slug "${input.slug}" must be kebab-case.`);
|
|
50
|
+
}
|
|
51
|
+
if (input.name.trim() === '') {
|
|
52
|
+
throw new Error('Invalid experience definition: name is required.');
|
|
53
|
+
}
|
|
54
|
+
const widgets = (_a = input.widgets) !== null && _a !== void 0 ? _a : [];
|
|
55
|
+
const pages = (_b = input.pages) !== null && _b !== void 0 ? _b : [];
|
|
56
|
+
const workflows = (_c = input.workflows) !== null && _c !== void 0 ? _c : [];
|
|
57
|
+
for (const widget of widgets) {
|
|
58
|
+
if (!KEBAB.test(widget.id)) {
|
|
59
|
+
throw new Error(`Invalid experience definition: widget id "${widget.id}" must be kebab-case.`);
|
|
60
|
+
}
|
|
61
|
+
if (typeof widget.component !== 'function' &&
|
|
62
|
+
typeof widget.component !== 'object') {
|
|
63
|
+
throw new Error(`Invalid experience definition: widget "${widget.id}" needs a component.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const page of pages) {
|
|
67
|
+
if (!KEBAB.test(page.id) || !KEBAB.test(page.path)) {
|
|
68
|
+
throw new Error(`Invalid experience definition: page "${page.id}" id and path must be kebab-case.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
assertUnique('widget', widgets.map((w) => w.id));
|
|
72
|
+
assertUnique('page', pages.map((p) => p.id));
|
|
73
|
+
assertUnique('page path', pages.map((p) => p.path));
|
|
74
|
+
assertUnique('workflow template', workflows.map((w) => w.id));
|
|
75
|
+
if (input.reviewQueue) {
|
|
76
|
+
if (input.reviewQueue.readsOnly !== true) {
|
|
77
|
+
throw new Error('Invalid experience definition: reviewQueue.readsOnly must be true.');
|
|
78
|
+
}
|
|
79
|
+
assertUnique('review queue section', input.reviewQueue.sections.map((s) => s.id));
|
|
80
|
+
}
|
|
81
|
+
return Object.freeze(Object.assign(Object.assign(Object.assign(Object.assign({ kind: 'experience', slug: input.slug, name: input.name }, (input.description === undefined
|
|
82
|
+
? {}
|
|
83
|
+
: { description: input.description })), (input.sidebar === undefined ? {} : { sidebar: input.sidebar })), { widgets: Object.freeze([...widgets]), pages: Object.freeze([...pages]), workflows: Object.freeze([...workflows]) }), (input.reviewQueue === undefined
|
|
84
|
+
? {}
|
|
85
|
+
: { reviewQueue: input.reviewQueue })));
|
|
86
|
+
}
|
|
87
|
+
/** Integrations an experience definition touches, deduplicated (for `check`/manifest). */
|
|
88
|
+
export function slotsUsedBy(definition) {
|
|
89
|
+
var _a;
|
|
90
|
+
var _b;
|
|
91
|
+
const used = new Set();
|
|
92
|
+
for (const widget of definition.widgets)
|
|
93
|
+
for (const s of widget.integrations)
|
|
94
|
+
used.add(s);
|
|
95
|
+
for (const page of definition.pages)
|
|
96
|
+
for (const s of page.integrations)
|
|
97
|
+
used.add(s);
|
|
98
|
+
for (const section of (_b = (_a = definition.reviewQueue) === null || _a === void 0 ? void 0 : _a.sections) !== null && _b !== void 0 ? _b : [])
|
|
99
|
+
used.add(section.integration);
|
|
100
|
+
for (const template of definition.workflows) {
|
|
101
|
+
for (const s of template.build())
|
|
102
|
+
if (s.type === 'tool')
|
|
103
|
+
used.add(s.integration);
|
|
104
|
+
}
|
|
105
|
+
return [...used].sort();
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=define-experience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-experience.js","sourceRoot":"","sources":["../../src/experience/define-experience.ts"],"names":[],"mappings":"AA0BA,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;AA4EF,MAAM,KAAK,GAAG,iCAAiC,CAAC;AAEhD,SAAS,YAAY,CAAC,IAAY,EAAE,GAAsB;IACxD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,kCAAkC,IAAI,QAAQ,EAAE,sBAAsB,CACvE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAsB;;IACrD,MAAM,GAAG,GAAG,KAA2C,CAAC;IACxD,KAAK,MAAM,GAAG,IAAI,qBAAqB,EAAE,CAAC;QACxC,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,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":["import type { ComponentType } from 'react';\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\nexport interface ExperiencePage {\n id: string;\n /** Route segment under the experience, e.g. `review`. */\n path: string;\n title: string;\n integrations: readonly IntegrationName[];\n component: ComponentType;\n}\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 ExperiencePage[];\n workflows?: readonly WorkflowTemplate[];\n reviewQueue?: ExperienceReviewQueue;\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}\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 for (const page of pages) {\n if (!KEBAB.test(page.id) || !KEBAB.test(page.path)) {\n throw new Error(\n `Invalid experience definition: page \"${page.id}\" id and path must be kebab-case.`,\n );\n }\n }\n assertUnique(\n 'widget',\n widgets.map((w) => w.id),\n );\n assertUnique(\n 'page',\n pages.map((p) => p.id),\n );\n assertUnique(\n 'page path',\n pages.map((p) => p.path),\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([...pages]),\n workflows: Object.freeze([...workflows]),\n ...(input.reviewQueue === undefined\n ? {}\n : { reviewQueue: input.reviewQueue }),\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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ekanos/sdk/experience — author an experience: widgets, pages and workflow
|
|
3
|
+
* templates that reach integrations only through contract-typed operations.
|
|
4
|
+
*
|
|
5
|
+
* Isomorphic and free of React hooks (those are `/experience/client`) and of
|
|
6
|
+
* Node APIs (`/experience/server`). No import of integration code, ever: the
|
|
7
|
+
* `experience-boundary` check fails the build if one appears.
|
|
8
|
+
*/
|
|
9
|
+
export { defineExperience, slotsUsedBy, type ExperienceDefinition, type ExperienceInput, type ExperiencePage, type ExperienceReviewQueue, type ExperienceSidebar, type ExperienceWidget, type ExperienceWidgetWidth, type IntegrationOnlyKeys, type ReviewQueueSection, } from './define-experience.js';
|
|
10
|
+
export { TEMPLATE_INSTALLATION_ID, defineWorkflowTemplate, ref, serializeWorkflowTemplate, step, type AiStep, type ApprovalStep, type SerializeWorkflowOptions, type StepOptions, type ToolStep, type WithRefs, type WorkflowDsl, type WorkflowRef, type WorkflowStep, type WorkflowTemplate, type WorkflowTemplateInput, } from './workflow-template.js';
|
|
11
|
+
export { OPERATION_REFUSAL_REASONS, type InputArgs, type OperationEffect, type OperationError, type OperationInput, type OperationKey, type OperationOutput, type OperationRefusalReason, type OperationResult, type OperationShape, type ReadOperationKey, type IntegrationName, type IntegrationRegistry, type IntegrationShape, type WriteOperationKey, } from './types.js';
|
|
12
|
+
export type { ApprovalToken, ExperienceRuntime, OperationCallRequest, OperationChannel, IntegrationInfo, IntegrationProvenance, } from './runtime.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ekanos/sdk/experience — author an experience: widgets, pages and workflow
|
|
3
|
+
* templates that reach integrations only through contract-typed operations.
|
|
4
|
+
*
|
|
5
|
+
* Isomorphic and free of React hooks (those are `/experience/client`) and of
|
|
6
|
+
* Node APIs (`/experience/server`). No import of integration code, ever: the
|
|
7
|
+
* `experience-boundary` check fails the build if one appears.
|
|
8
|
+
*/
|
|
9
|
+
export { defineExperience, slotsUsedBy, } from './define-experience.js';
|
|
10
|
+
export { TEMPLATE_INSTALLATION_ID, defineWorkflowTemplate, ref, serializeWorkflowTemplate, step, } from './workflow-template.js';
|
|
11
|
+
export { OPERATION_REFUSAL_REASONS, } from './types.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/experience/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,gBAAgB,EAChB,WAAW,GAUZ,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,GAAG,EACH,yBAAyB,EACzB,IAAI,GAYL,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,yBAAyB,GAe1B,MAAM,SAAS,CAAC","sourcesContent":["/**\n * @ekanos/sdk/experience — author an experience: widgets, pages and workflow\n * templates that reach integrations only through contract-typed operations.\n *\n * Isomorphic and free of React hooks (those are `/experience/client`) and of\n * Node APIs (`/experience/server`). No import of integration code, ever: the\n * `experience-boundary` check fails the build if one appears.\n */\nexport {\n defineExperience,\n slotsUsedBy,\n type ExperienceDefinition,\n type ExperienceInput,\n type ExperiencePage,\n type ExperienceReviewQueue,\n type ExperienceSidebar,\n type ExperienceWidget,\n type ExperienceWidgetWidth,\n type IntegrationOnlyKeys,\n type ReviewQueueSection,\n} from './define-experience';\n\nexport {\n TEMPLATE_INSTALLATION_ID,\n defineWorkflowTemplate,\n ref,\n serializeWorkflowTemplate,\n step,\n type AiStep,\n type ApprovalStep,\n type SerializeWorkflowOptions,\n type StepOptions,\n type ToolStep,\n type WithRefs,\n type WorkflowDsl,\n type WorkflowRef,\n type WorkflowStep,\n type WorkflowTemplate,\n type WorkflowTemplateInput,\n} from './workflow-template';\n\nexport {\n OPERATION_REFUSAL_REASONS,\n type InputArgs,\n type OperationEffect,\n type OperationError,\n type OperationInput,\n type OperationKey,\n type OperationOutput,\n type OperationRefusalReason,\n type OperationResult,\n type OperationShape,\n type ReadOperationKey,\n type IntegrationName,\n type IntegrationRegistry,\n type IntegrationShape,\n type WriteOperationKey,\n} from './types';\n\nexport type {\n ApprovalToken,\n ExperienceRuntime,\n OperationCallRequest,\n OperationChannel,\n IntegrationInfo,\n IntegrationProvenance,\n} from './runtime';\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ekanos/sdk/experience/runtime` — the ONE seam between an experience and
|
|
3
|
+
* an integration.
|
|
4
|
+
*
|
|
5
|
+
* An experience calls operations through an {@link ExperienceRuntime} and
|
|
6
|
+
* through nothing else: no import of integration code, no `fetch` to an
|
|
7
|
+
* integration route. The local harness implements it over its own
|
|
8
|
+
* `/__ekanos/api/ops/run`; the host implements it over the installation's integration
|
|
9
|
+
* route. Both answer with the same {@link OperationResult} and the same
|
|
10
|
+
* refusal reasons, so an experience behaves identically in either.
|
|
11
|
+
*
|
|
12
|
+
* Isomorphic and dependency-free: types only (plus the re-exports below).
|
|
13
|
+
*/
|
|
14
|
+
import type { OperationResult } from '@ekanos/integration-schema';
|
|
15
|
+
export { OPERATION_REFUSAL_REASONS, type OperationError, type OperationRefusalReason, type OperationResult, } from './types.js';
|
|
16
|
+
/** The channel a call arrives on; writes are judged by it (see `write_refused_on_channel`). */
|
|
17
|
+
export type OperationChannel = 'http' | 'rsc' | 'workflow';
|
|
18
|
+
/**
|
|
19
|
+
* Proof that a person approved one write. Opaque to the experience: the
|
|
20
|
+
* runtime mints it (the harness approvals tray; the host approval gate) and
|
|
21
|
+
* checks it. An experience may carry one back into `mutate(input, { approval })`.
|
|
22
|
+
*/
|
|
23
|
+
export interface ApprovalToken {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
}
|
|
26
|
+
export interface OperationCallRequest {
|
|
27
|
+
/** The integration name from `ekanos.json` `integrations` (its slug). */
|
|
28
|
+
integration: string;
|
|
29
|
+
/** `tool/<name>` or `action/<name>`. The version is the one `ekanos.json` pins. */
|
|
30
|
+
op: string;
|
|
31
|
+
input: unknown;
|
|
32
|
+
channel: OperationChannel;
|
|
33
|
+
approval?: ApprovalToken;
|
|
34
|
+
}
|
|
35
|
+
export type IntegrationProvenance = 'registry' | 'local';
|
|
36
|
+
/** What a runtime can say about an integration (for UI badges, never for widgets' logic). */
|
|
37
|
+
export interface IntegrationInfo {
|
|
38
|
+
name: string;
|
|
39
|
+
version: string;
|
|
40
|
+
provenance: IntegrationProvenance;
|
|
41
|
+
bindingMode?: string;
|
|
42
|
+
runMode?: 'fixtures' | 'live';
|
|
43
|
+
}
|
|
44
|
+
export interface ExperienceRuntime {
|
|
45
|
+
/**
|
|
46
|
+
* Run one operation. May take as long as a person takes to decide: a write
|
|
47
|
+
* on an approval-gated channel resolves only once the approval tray has
|
|
48
|
+
* answered (`write_not_approved` when it was rejected). Never throws for a
|
|
49
|
+
* refusal: those are `{ ok: false, reason }`. A rejected promise means the
|
|
50
|
+
* runtime itself is broken.
|
|
51
|
+
*/
|
|
52
|
+
call(request: OperationCallRequest): Promise<OperationResult<unknown>>;
|
|
53
|
+
integrations(): IntegrationInfo[];
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/experience/runtime.ts"],"names":[],"mappings":"AAeA,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 the installation's integration\n * route. 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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExperienceRuntime } from './runtime.js';
|
|
2
|
+
import type { InputArgs, OperationInput, OperationKey, OperationOutput, OperationResult, IntegrationName } from './types.js';
|
|
3
|
+
/** Run `fn` with `runtime` as the one `operation()` calls inside it. */
|
|
4
|
+
export declare function runWithExperienceRuntime<T>(runtime: ExperienceRuntime, fn: () => T): T;
|
|
5
|
+
/** Register a process-wide runtime (the harness, which has no per-request wrapper). */
|
|
6
|
+
export declare function configureExperienceRuntime(runtime: ExperienceRuntime): void;
|
|
7
|
+
/**
|
|
8
|
+
* Call one operation on the server. Writes are judged by the `rsc` channel:
|
|
9
|
+
* the runtime refuses them unless it holds an approval (`write_refused_on_channel`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function operation<S extends IntegrationName, K extends OperationKey<S>>(integration: S, op: K, ...args: InputArgs<OperationInput<S, K>>): Promise<OperationResult<OperationOutput<S, K>>>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ekanos/sdk/experience/server` — call an integration operation from a server
|
|
3
|
+
* component, server action or route.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const res = await operation('cms', 'tool/list_posts', { limit: 20 });
|
|
7
|
+
* if (res.ok) res.data; // typed from the pinned contract
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* The runtime comes from `AsyncLocalStorage` (set by the host or the harness
|
|
11
|
+
* around the request with {@link runWithExperienceRuntime}), falling back to
|
|
12
|
+
* one registered with {@link configureExperienceRuntime}.
|
|
13
|
+
*/
|
|
14
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
15
|
+
const storage = new AsyncLocalStorage();
|
|
16
|
+
const GLOBAL_KEY = Symbol.for('@ekanos/sdk/experience/runtime');
|
|
17
|
+
/** Run `fn` with `runtime` as the one `operation()` calls inside it. */
|
|
18
|
+
export function runWithExperienceRuntime(runtime, fn) {
|
|
19
|
+
return storage.run(runtime, fn);
|
|
20
|
+
}
|
|
21
|
+
/** Register a process-wide runtime (the harness, which has no per-request wrapper). */
|
|
22
|
+
export function configureExperienceRuntime(runtime) {
|
|
23
|
+
globalThis[GLOBAL_KEY] = runtime;
|
|
24
|
+
}
|
|
25
|
+
function currentRuntime() {
|
|
26
|
+
var _a;
|
|
27
|
+
const runtime = (_a = storage.getStore()) !== null && _a !== void 0 ? _a : globalThis[GLOBAL_KEY];
|
|
28
|
+
if (!runtime) {
|
|
29
|
+
throw new Error('operation() has no ExperienceRuntime. The host and `ekanos dev` set one per request; in a test call runWithExperienceRuntime(runtime, ...).');
|
|
30
|
+
}
|
|
31
|
+
return runtime;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Call one operation on the server. Writes are judged by the `rsc` channel:
|
|
35
|
+
* the runtime refuses them unless it holds an approval (`write_refused_on_channel`).
|
|
36
|
+
*/
|
|
37
|
+
export async function operation(integration, op, ...args) {
|
|
38
|
+
var _a;
|
|
39
|
+
const result = await currentRuntime().call({
|
|
40
|
+
integration,
|
|
41
|
+
op,
|
|
42
|
+
input: (_a = args[0]) !== null && _a !== void 0 ? _a : {},
|
|
43
|
+
channel: 'rsc',
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/experience/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAqB,CAAC;AAE3D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAMhE,wEAAwE;AACxE,MAAM,UAAU,wBAAwB,CACtC,OAA0B,EAC1B,EAAW;IAEX,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,0BAA0B,CAAC,OAA0B;IAClE,UAAgC,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;AAC1D,CAAC;AAED,SAAS,cAAc;;IACrB,MAAM,OAAO,SACX,OAAO,CAAC,QAAQ,EAAE,mCAAK,UAAgC,CAAC,UAAU,CAAC,CAAC;IACtE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,6IAA6I,CAC9I,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAI7B,WAAc,EACd,EAAK,EACL,GAAG,IAAqC;;IAExC,MAAM,MAAM,GAAG,MAAM,cAAc,EAAE,CAAC,IAAI,CAAC;QACzC,WAAW;QACX,EAAE;QACF,KAAK,QAAE,IAAI,CAAC,CAAC,CAAC,mCAAI,EAAE;QACpB,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,OAAO,MAAgD,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * `@ekanos/sdk/experience/server` — call an integration operation from a server\n * component, server action or route.\n *\n * ```ts\n * const res = await operation('cms', 'tool/list_posts', { limit: 20 });\n * if (res.ok) res.data; // typed from the pinned contract\n * ```\n *\n * The runtime comes from `AsyncLocalStorage` (set by the host or the harness\n * around the request with {@link runWithExperienceRuntime}), falling back to\n * one registered with {@link configureExperienceRuntime}.\n */\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { ExperienceRuntime } from './runtime';\nimport type {\n InputArgs,\n OperationInput,\n OperationKey,\n OperationOutput,\n OperationResult,\n IntegrationName,\n} from './types';\n\nconst storage = new AsyncLocalStorage<ExperienceRuntime>();\n\nconst GLOBAL_KEY = Symbol.for('@ekanos/sdk/experience/runtime');\n\ntype GlobalWithRuntime = typeof globalThis & {\n [GLOBAL_KEY]?: ExperienceRuntime;\n};\n\n/** Run `fn` with `runtime` as the one `operation()` calls inside it. */\nexport function runWithExperienceRuntime<T>(\n runtime: ExperienceRuntime,\n fn: () => T,\n): T {\n return storage.run(runtime, fn);\n}\n\n/** Register a process-wide runtime (the harness, which has no per-request wrapper). */\nexport function configureExperienceRuntime(runtime: ExperienceRuntime): void {\n (globalThis as GlobalWithRuntime)[GLOBAL_KEY] = runtime;\n}\n\nfunction currentRuntime(): ExperienceRuntime {\n const runtime =\n storage.getStore() ?? (globalThis as GlobalWithRuntime)[GLOBAL_KEY];\n if (!runtime) {\n throw new Error(\n 'operation() has no ExperienceRuntime. The host and `ekanos dev` set one per request; in a test call runWithExperienceRuntime(runtime, ...).',\n );\n }\n\n return runtime;\n}\n\n/**\n * Call one operation on the server. Writes are judged by the `rsc` channel:\n * the runtime refuses them unless it holds an approval (`write_refused_on_channel`).\n */\nexport async function operation<\n S extends IntegrationName,\n K extends OperationKey<S>,\n>(\n integration: S,\n op: K,\n ...args: InputArgs<OperationInput<S, K>>\n): Promise<OperationResult<OperationOutput<S, K>>> {\n const result = await currentRuntime().call({\n integration,\n op,\n input: args[0] ?? {},\n channel: 'rsc',\n });\n\n return result as OperationResult<OperationOutput<S, K>>;\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { OperationRefusalReason } from '@ekanos/integration-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Types shared by every `@ekanos/sdk/experience*` entrypoint.
|
|
4
|
+
*
|
|
5
|
+
* An experience never imports integration code. Everything it may call is a
|
|
6
|
+
* *operation of an integration the experience depends on*, and the types of those operations come from the PINNED
|
|
7
|
+
* CONTRACTS (`contracts/*.contract.json`), turned into a `.d.ts` by
|
|
8
|
+
* `ekanos codegen` (`src/.ekanos/integrations.d.ts`). That file augments
|
|
9
|
+
* {@link IntegrationRegistry} below; until it exists the registry is empty and every
|
|
10
|
+
* integration/operation name degrades to a plain `string` (loose, never wrong).
|
|
11
|
+
*/
|
|
12
|
+
/** Whether an operation changes anything. Comes from the contract, never authored. */
|
|
13
|
+
export type OperationEffect = 'read' | 'write';
|
|
14
|
+
/** What one operation looks like in {@link IntegrationRegistry} (generated). */
|
|
15
|
+
export interface OperationShape {
|
|
16
|
+
effect: OperationEffect;
|
|
17
|
+
input: unknown;
|
|
18
|
+
output: unknown;
|
|
19
|
+
}
|
|
20
|
+
/** What one integration looks like in {@link IntegrationRegistry} (generated). */
|
|
21
|
+
export interface IntegrationShape {
|
|
22
|
+
version: string;
|
|
23
|
+
ops: Record<string, OperationShape>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The generated registry of integrations and their operations. Empty here on
|
|
27
|
+
* purpose: `src/.ekanos/integrations.d.ts` fills it by module augmentation.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* declare module '@ekanos/sdk/experience' {
|
|
31
|
+
* interface IntegrationRegistry {
|
|
32
|
+
* sanity: { version: '0.2'; ops: { 'tool/list_posts': {...} } };
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export interface IntegrationRegistry {
|
|
38
|
+
}
|
|
39
|
+
type RegistryEmpty = [keyof IntegrationRegistry] extends [never] ? true : false;
|
|
40
|
+
/** An integration name from the generated registry (any string before codegen has run). */
|
|
41
|
+
export type IntegrationName = RegistryEmpty extends true ? string : Extract<keyof IntegrationRegistry, string>;
|
|
42
|
+
type OpsOf<S extends string> = S extends keyof IntegrationRegistry ? IntegrationRegistry[S] extends {
|
|
43
|
+
ops: infer O;
|
|
44
|
+
} ? O : never : Record<string, OperationShape>;
|
|
45
|
+
type OpKeysWithEffect<S extends string, E extends OperationEffect> = {
|
|
46
|
+
[K in keyof OpsOf<S>]: OpsOf<S>[K] extends {
|
|
47
|
+
effect: E;
|
|
48
|
+
} ? K : never;
|
|
49
|
+
}[keyof OpsOf<S>];
|
|
50
|
+
/** Every `kind/name` operation key of an integration. */
|
|
51
|
+
export type OperationKey<S extends IntegrationName> = Extract<keyof OpsOf<S>, string>;
|
|
52
|
+
/** The read operations of an integration: the only ones `useOperation` accepts. */
|
|
53
|
+
export type ReadOperationKey<S extends IntegrationName> = Extract<RegistryEmpty extends true ? string : OpKeysWithEffect<S, 'read'>, string>;
|
|
54
|
+
/** The write operations of an integration: `useOperationMutation` and `step.tool` only. */
|
|
55
|
+
export type WriteOperationKey<S extends IntegrationName> = Extract<RegistryEmpty extends true ? string : OpKeysWithEffect<S, 'write'>, string>;
|
|
56
|
+
type OpAt<S extends IntegrationName, K extends string> = K extends keyof OpsOf<S> ? OpsOf<S>[K] : never;
|
|
57
|
+
/** The input type of `integration` + `op`, inferred from the pinned contract. */
|
|
58
|
+
export type OperationInput<S extends IntegrationName, K extends string> = OpAt<S, K> extends {
|
|
59
|
+
input: infer I;
|
|
60
|
+
} ? I : unknown;
|
|
61
|
+
/** The (fail-closed validated) output type of `integration` + `op`. */
|
|
62
|
+
export type OperationOutput<S extends IntegrationName, K extends string> = OpAt<S, K> extends {
|
|
63
|
+
output: infer O;
|
|
64
|
+
} ? O : unknown;
|
|
65
|
+
export { OPERATION_REFUSAL_REASONS } from '@ekanos/integration-schema';
|
|
66
|
+
export type { OperationRefusalReason, OperationResult, } from '@ekanos/integration-schema';
|
|
67
|
+
/** A refused or failed call, as data. */
|
|
68
|
+
export interface OperationError {
|
|
69
|
+
reason: OperationRefusalReason;
|
|
70
|
+
message: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Rest-parameter helper: the `input` argument is optional exactly when every
|
|
74
|
+
* field of the operation's input is optional (`{}` input included).
|
|
75
|
+
*/
|
|
76
|
+
export type InputArgs<I> = Record<never, never> extends I ? [input?: I] : [input: I];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/experience/types.ts"],"names":[],"mappings":"AA4FA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["import type { OperationRefusalReason } from '@ekanos/integration-schema';\n\n/**\n * Types shared by every `@ekanos/sdk/experience*` entrypoint.\n *\n * An experience never imports integration code. Everything it may call is a\n * *operation of an integration the experience depends on*, and the types of those operations come from the PINNED\n * CONTRACTS (`contracts/*.contract.json`), turned into a `.d.ts` by\n * `ekanos codegen` (`src/.ekanos/integrations.d.ts`). That file augments\n * {@link IntegrationRegistry} below; until it exists the registry is empty and every\n * integration/operation name degrades to a plain `string` (loose, never wrong).\n */\n\n/** Whether an operation changes anything. Comes from the contract, never authored. */\nexport type OperationEffect = 'read' | 'write';\n\n/** What one operation looks like in {@link IntegrationRegistry} (generated). */\nexport interface OperationShape {\n effect: OperationEffect;\n input: unknown;\n output: unknown;\n}\n\n/** What one integration looks like in {@link IntegrationRegistry} (generated). */\nexport interface IntegrationShape {\n version: string;\n ops: Record<string, OperationShape>;\n}\n\n/**\n * The generated registry of integrations and their operations. Empty here on\n * purpose: `src/.ekanos/integrations.d.ts` fills it by module augmentation.\n *\n * ```ts\n * declare module '@ekanos/sdk/experience' {\n * interface IntegrationRegistry {\n * sanity: { version: '0.2'; ops: { 'tool/list_posts': {...} } };\n * }\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface IntegrationRegistry {}\n\ntype RegistryEmpty = [keyof IntegrationRegistry] extends [never] ? true : false;\n\n/** An integration name from the generated registry (any string before codegen has run). */\nexport type IntegrationName = RegistryEmpty extends true\n ? string\n : Extract<keyof IntegrationRegistry, string>;\n\ntype OpsOf<S extends string> = S extends keyof IntegrationRegistry\n ? IntegrationRegistry[S] extends { ops: infer O }\n ? O\n : never\n : Record<string, OperationShape>;\n\ntype OpKeysWithEffect<S extends string, E extends OperationEffect> = {\n [K in keyof OpsOf<S>]: OpsOf<S>[K] extends { effect: E } ? K : never;\n}[keyof OpsOf<S>];\n\n/** Every `kind/name` operation key of an integration. */\nexport type OperationKey<S extends IntegrationName> = Extract<\n keyof OpsOf<S>,\n string\n>;\n\n/** The read operations of an integration: the only ones `useOperation` accepts. */\nexport type ReadOperationKey<S extends IntegrationName> = Extract<\n RegistryEmpty extends true ? string : OpKeysWithEffect<S, 'read'>,\n string\n>;\n\n/** The write operations of an integration: `useOperationMutation` and `step.tool` only. */\nexport type WriteOperationKey<S extends IntegrationName> = Extract<\n RegistryEmpty extends true ? string : OpKeysWithEffect<S, 'write'>,\n string\n>;\n\ntype OpAt<\n S extends IntegrationName,\n K extends string,\n> = K extends keyof OpsOf<S> ? OpsOf<S>[K] : never;\n\n/** The input type of `integration` + `op`, inferred from the pinned contract. */\nexport type OperationInput<S extends IntegrationName, K extends string> =\n OpAt<S, K> extends { input: infer I } ? I : unknown;\n\n/** The (fail-closed validated) output type of `integration` + `op`. */\nexport type OperationOutput<S extends IntegrationName, K extends string> =\n OpAt<S, K> extends { output: infer O } ? O : unknown;\n\nexport { OPERATION_REFUSAL_REASONS } from '@ekanos/integration-schema';\nexport type {\n OperationRefusalReason,\n OperationResult,\n} from '@ekanos/integration-schema';\n\n/** A refused or failed call, as data. */\nexport interface OperationError {\n reason: OperationRefusalReason;\n message: string;\n}\n\n/**\n * Rest-parameter helper: the `input` argument is optional exactly when every\n * field of the operation's input is optional (`{}` input included).\n */\nexport type InputArgs<I> =\n Record<never, never> extends I ? [input?: I] : [input: I];\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { TEMPLATE_INSTALLATION_ID, type WorkflowTemplate as EngineWorkflowTemplate } from '@ekanos/integration-schema';
|
|
2
|
+
import type { OperationInput, OperationKey, IntegrationName } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A reference to an earlier step's output (`{ ref: 'draft.title' }`), the
|
|
5
|
+
* workflow engine's operand shape. Build one with {@link ref}.
|
|
6
|
+
*/
|
|
7
|
+
export interface WorkflowRef {
|
|
8
|
+
readonly ref: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ref(path: string): WorkflowRef;
|
|
11
|
+
/** Each input field may be literal or a reference to an earlier step's output. */
|
|
12
|
+
export type WithRefs<T> = T extends readonly unknown[] ? T | WorkflowRef : T extends object ? {
|
|
13
|
+
[P in keyof T]: WithRefs<T[P]> | WorkflowRef;
|
|
14
|
+
} : T | WorkflowRef;
|
|
15
|
+
export interface StepOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Step id(s) this step follows. Default: the previous step in `build()`
|
|
18
|
+
* order (the first step follows nothing).
|
|
19
|
+
*/
|
|
20
|
+
after?: string | readonly string[];
|
|
21
|
+
}
|
|
22
|
+
export interface ToolStep {
|
|
23
|
+
readonly type: 'tool';
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly integration: string;
|
|
26
|
+
/** `tool/<name>` or `action/<name>`; effect comes from the pinned contract. */
|
|
27
|
+
readonly op: string;
|
|
28
|
+
readonly args: Record<string, unknown>;
|
|
29
|
+
readonly after?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface AiStep {
|
|
32
|
+
readonly type: 'ai';
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly kind: string;
|
|
35
|
+
readonly instructions: string;
|
|
36
|
+
readonly outputSchemaRef: string;
|
|
37
|
+
readonly after?: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
export interface ApprovalStep {
|
|
40
|
+
readonly type: 'approval';
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly summary: string;
|
|
43
|
+
readonly approverScope: 'account' | 'user';
|
|
44
|
+
readonly after?: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
export type WorkflowStep = ToolStep | AiStep | ApprovalStep;
|
|
47
|
+
/**
|
|
48
|
+
* Step constructors for {@link defineWorkflowTemplate}.
|
|
49
|
+
*
|
|
50
|
+
* `step.tool` is typed from the generated registry: the integration, the operation
|
|
51
|
+
* and its `args` are checked against the pinned contract. Whether a tool step
|
|
52
|
+
* reads or writes is NOT authored; it is read from the contract at build, so a
|
|
53
|
+
* template cannot call a write as if it were a read.
|
|
54
|
+
*/
|
|
55
|
+
export declare const step: {
|
|
56
|
+
tool<S extends IntegrationName, K extends OperationKey<S>>(id: string, integration: S, op: K, args: WithRefs<OperationInput<S, K>>, options?: StepOptions): ToolStep;
|
|
57
|
+
ai(id: string, config: {
|
|
58
|
+
instructions: string;
|
|
59
|
+
outputSchemaRef: string;
|
|
60
|
+
kind?: string;
|
|
61
|
+
}, options?: StepOptions): AiStep;
|
|
62
|
+
approval(id: string, config: {
|
|
63
|
+
summary: string;
|
|
64
|
+
approverScope?: 'account' | 'user';
|
|
65
|
+
}, options?: StepOptions): ApprovalStep;
|
|
66
|
+
};
|
|
67
|
+
export interface WorkflowTemplateInput {
|
|
68
|
+
/** kebab-case, unique within the experience. */
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
/** A 5-field cron expression. Omit for a template that is started by hand. */
|
|
72
|
+
schedule?: string;
|
|
73
|
+
scope?: 'account' | 'user';
|
|
74
|
+
/** Evaluated at `ekanos build`, never at runtime. */
|
|
75
|
+
build: () => readonly WorkflowStep[];
|
|
76
|
+
}
|
|
77
|
+
export interface WorkflowTemplate {
|
|
78
|
+
readonly kind: 'workflow-template';
|
|
79
|
+
readonly id: string;
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly schedule?: string;
|
|
82
|
+
readonly scope: 'account' | 'user';
|
|
83
|
+
readonly build: () => readonly WorkflowStep[];
|
|
84
|
+
}
|
|
85
|
+
export declare function defineWorkflowTemplate(input: WorkflowTemplateInput): WorkflowTemplate;
|
|
86
|
+
/** The serialized workflow the host's engine runs (validated by `WorkflowTemplateSchema`). */
|
|
87
|
+
export type WorkflowDsl = EngineWorkflowTemplate;
|
|
88
|
+
export { TEMPLATE_INSTALLATION_ID };
|
|
89
|
+
export interface SerializeWorkflowOptions {
|
|
90
|
+
/**
|
|
91
|
+
* Reads `read`/`write` for an integration operation from the pinned contract. Return
|
|
92
|
+
* `undefined` when the operation is unknown: serialization then throws, so
|
|
93
|
+
* a template can never name an operation the contract lacks.
|
|
94
|
+
*/
|
|
95
|
+
effectOf: (integration: string, op: string) => 'read' | 'write' | undefined;
|
|
96
|
+
installationId?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Turn a template into the engine's DSL. Pure and deterministic: the same
|
|
100
|
+
* template and contracts always give the same JSON (it is hashed into the
|
|
101
|
+
* manifest digest).
|
|
102
|
+
*/
|
|
103
|
+
export declare function serializeWorkflowTemplate(template: WorkflowTemplate, options: SerializeWorkflowOptions): WorkflowDsl;
|