@lunnoa/client 2.2.0 → 2.4.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/README.md +2 -2
- package/dist/cli.js +139 -1
- package/dist/index.cjs +144 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +128 -4
- package/dist/index.d.ts +128 -4
- package/dist/index.js +141 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +49 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +111 -2
- package/dist/react.d.ts +111 -2
- package/dist/react.js +49 -0
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/skills/lunnoa-client/SKILL.md +80 -4
- package/skills/lunnoa-solution-design/SKILL.md +15 -4
package/dist/index.js
CHANGED
|
@@ -535,6 +535,7 @@ var DEFINE_KINDS = {
|
|
|
535
535
|
connection: "connection",
|
|
536
536
|
aiConnection: "aiConnection",
|
|
537
537
|
action: "action",
|
|
538
|
+
trigger: "trigger",
|
|
538
539
|
workflow: "workflow",
|
|
539
540
|
agent: "agent",
|
|
540
541
|
entityType: "entityType"
|
|
@@ -551,6 +552,92 @@ function defineAction(config) {
|
|
|
551
552
|
}
|
|
552
553
|
return { kind: DEFINE_KINDS.action, ...config };
|
|
553
554
|
}
|
|
555
|
+
function assertTriggerConfig(config) {
|
|
556
|
+
if (!config.id?.trim()) {
|
|
557
|
+
throw new Error("defineTrigger requires id (catalogue trigger id)");
|
|
558
|
+
}
|
|
559
|
+
for (const field of config.inputs ?? []) {
|
|
560
|
+
if (!field?.id?.trim()) {
|
|
561
|
+
throw new Error("defineTrigger inputs require id");
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (config.inputs?.length && config.id.trim() !== MANUAL_TRIGGER_ID) {
|
|
565
|
+
throw new Error(
|
|
566
|
+
"defineTrigger inputs are only valid on flow-control_trigger_manual"
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function defineTrigger(config) {
|
|
571
|
+
assertTriggerConfig(config);
|
|
572
|
+
return { kind: DEFINE_KINDS.trigger, ...config };
|
|
573
|
+
}
|
|
574
|
+
var MANUAL_TRIGGER_ID = "flow-control_trigger_manual";
|
|
575
|
+
var TRIGGER_KEY = "trigger";
|
|
576
|
+
var STEP_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
577
|
+
var STEP_REF_PATTERN = /={{step:([^}]*)}}/g;
|
|
578
|
+
function refString(key, path) {
|
|
579
|
+
const parts = [key, ...path.map(String)];
|
|
580
|
+
for (const part of parts) {
|
|
581
|
+
if (!part || /[,{}]/.test(part)) {
|
|
582
|
+
throw new Error(`ref path parts must be non-empty and contain no , { or }: "${part}"`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return `={{step:${parts.join(",")}}}`;
|
|
586
|
+
}
|
|
587
|
+
var ref = {
|
|
588
|
+
/** A trigger output field, e.g. a Manually Run input id. */
|
|
589
|
+
trigger: (field, ...path) => refString(TRIGGER_KEY, [field, ...path]),
|
|
590
|
+
/** An earlier step's output, by its `key`. Array indexes are numbers. */
|
|
591
|
+
step: (key, ...path) => refString(key, path)
|
|
592
|
+
};
|
|
593
|
+
function collectRefs(value, out) {
|
|
594
|
+
if (typeof value === "string") {
|
|
595
|
+
for (const match of value.matchAll(STEP_REF_PATTERN)) {
|
|
596
|
+
out.push(match[1].split(",").map((part) => part.trim()));
|
|
597
|
+
}
|
|
598
|
+
} else if (Array.isArray(value)) {
|
|
599
|
+
value.forEach((item) => collectRefs(item, out));
|
|
600
|
+
} else if (value && typeof value === "object") {
|
|
601
|
+
Object.values(value).forEach((item) => collectRefs(item, out));
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function assertStepRefs(config) {
|
|
605
|
+
const triggerId = config.trigger?.id.trim() ?? MANUAL_TRIGGER_ID;
|
|
606
|
+
const triggerFields = triggerId === MANUAL_TRIGGER_ID ? new Set((config.trigger?.inputs ?? []).map((f) => f.id.trim())) : void 0;
|
|
607
|
+
const allKeys = /* @__PURE__ */ new Set();
|
|
608
|
+
for (const step of config.steps) {
|
|
609
|
+
if (step.key === void 0) continue;
|
|
610
|
+
if (!STEP_KEY_PATTERN.test(step.key) || step.key === TRIGGER_KEY) {
|
|
611
|
+
throw new Error(
|
|
612
|
+
`Step key "${step.key}" must start with a letter, use letters, digits, - or _, and not be "${TRIGGER_KEY}".`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
if (allKeys.has(step.key)) {
|
|
616
|
+
throw new Error(`Step key "${step.key}" is used twice.`);
|
|
617
|
+
}
|
|
618
|
+
allKeys.add(step.key);
|
|
619
|
+
}
|
|
620
|
+
const earlier = /* @__PURE__ */ new Set([TRIGGER_KEY]);
|
|
621
|
+
config.steps.forEach((step, index) => {
|
|
622
|
+
const refs = [];
|
|
623
|
+
collectRefs([step.use?.input, step.input], refs);
|
|
624
|
+
const where = `Step "${step.key ?? step.name ?? index + 1}"`;
|
|
625
|
+
for (const [key = "", ...path] of refs) {
|
|
626
|
+
const shown = `={{step:${[key, ...path].join(",")}}}`;
|
|
627
|
+
if (!earlier.has(key)) {
|
|
628
|
+
throw new Error(
|
|
629
|
+
allKeys.has(key) ? `${where}: ${shown} refers to itself or a later step. Use the trigger or an earlier step.` : `${where}: ${shown} names unknown key "${key}". Use "trigger" or an earlier step's key.`
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
if (key === TRIGGER_KEY && triggerFields && !triggerFields.has(path[0] ?? "")) {
|
|
633
|
+
throw new Error(
|
|
634
|
+
`${where}: ${shown} uses trigger field "${path[0] ?? ""}", which is not declared in trigger inputs.`
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (step.key) earlier.add(step.key);
|
|
639
|
+
});
|
|
640
|
+
}
|
|
554
641
|
function defineWorkflow(config) {
|
|
555
642
|
if (!config.slug?.trim()) {
|
|
556
643
|
throw new Error("defineWorkflow requires slug");
|
|
@@ -558,6 +645,10 @@ function defineWorkflow(config) {
|
|
|
558
645
|
if (!config.steps?.length) {
|
|
559
646
|
throw new Error("defineWorkflow requires at least one step");
|
|
560
647
|
}
|
|
648
|
+
if (config.trigger) {
|
|
649
|
+
assertTriggerConfig(config.trigger);
|
|
650
|
+
}
|
|
651
|
+
assertStepRefs(config);
|
|
561
652
|
return { kind: DEFINE_KINDS.workflow, ...config };
|
|
562
653
|
}
|
|
563
654
|
function defineAgent(config) {
|
|
@@ -603,6 +694,40 @@ function resolveActionAppId(action) {
|
|
|
603
694
|
`Cannot infer appId for action "${id}". Pass appId explicitly.`
|
|
604
695
|
);
|
|
605
696
|
}
|
|
697
|
+
function resolveTriggerAppId(trigger) {
|
|
698
|
+
if (trigger.appId?.trim()) {
|
|
699
|
+
return trigger.appId.trim();
|
|
700
|
+
}
|
|
701
|
+
const id = trigger.id.trim();
|
|
702
|
+
const marker = "_trigger_";
|
|
703
|
+
const markerIndex = id.indexOf(marker);
|
|
704
|
+
if (markerIndex > 0) {
|
|
705
|
+
return id.slice(0, markerIndex);
|
|
706
|
+
}
|
|
707
|
+
const dot = id.indexOf(".");
|
|
708
|
+
if (dot > 0) {
|
|
709
|
+
return id.slice(0, dot);
|
|
710
|
+
}
|
|
711
|
+
throw new Error(
|
|
712
|
+
`Cannot infer appId for trigger "${id}". Pass appId explicitly.`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
function resolveTriggerId(trigger) {
|
|
716
|
+
const id = trigger.id.trim();
|
|
717
|
+
const appId = trigger.appId?.trim();
|
|
718
|
+
if (appId && id.startsWith(`${appId}.`)) {
|
|
719
|
+
return id.slice(appId.length + 1);
|
|
720
|
+
}
|
|
721
|
+
const marker = "_trigger_";
|
|
722
|
+
if (id.includes(marker)) {
|
|
723
|
+
return id;
|
|
724
|
+
}
|
|
725
|
+
const dot = id.indexOf(".");
|
|
726
|
+
if (dot > 0) {
|
|
727
|
+
return id.slice(dot + 1);
|
|
728
|
+
}
|
|
729
|
+
return id;
|
|
730
|
+
}
|
|
606
731
|
function resolveActionId(action) {
|
|
607
732
|
const id = action.id.trim();
|
|
608
733
|
const appId = action.appId?.trim();
|
|
@@ -1815,7 +1940,9 @@ function stepFromDefinition(step) {
|
|
|
1815
1940
|
...use.input ?? {},
|
|
1816
1941
|
...step.input ?? {}
|
|
1817
1942
|
};
|
|
1943
|
+
const key = step.key;
|
|
1818
1944
|
return {
|
|
1945
|
+
...key ? { key } : {},
|
|
1819
1946
|
appId: resolveActionAppId(use),
|
|
1820
1947
|
actionId: resolveActionId(use),
|
|
1821
1948
|
...use.connection?.id ? { connectionId: use.connection.id } : {},
|
|
@@ -2017,9 +2144,21 @@ var WorkflowAppsResource = class {
|
|
|
2017
2144
|
};
|
|
2018
2145
|
|
|
2019
2146
|
// src/resources/workflows.ts
|
|
2147
|
+
function triggerToUpsertInput(trigger) {
|
|
2148
|
+
return {
|
|
2149
|
+
triggerId: resolveTriggerId(trigger),
|
|
2150
|
+
appId: resolveTriggerAppId(trigger),
|
|
2151
|
+
...trigger.connection?.id ? { connectionId: trigger.connection.id } : {},
|
|
2152
|
+
...trigger.input ? { input: trigger.input } : {},
|
|
2153
|
+
...trigger.inputs?.length ? { inputs: trigger.inputs } : {},
|
|
2154
|
+
...trigger.name ? { name: trigger.name } : {},
|
|
2155
|
+
...trigger.description ? { description: trigger.description } : {}
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2020
2158
|
function stepToUpsertInput(step) {
|
|
2021
2159
|
const use = step.use;
|
|
2022
2160
|
return {
|
|
2161
|
+
...step.key ? { key: step.key } : {},
|
|
2023
2162
|
appId: resolveActionAppId(use),
|
|
2024
2163
|
actionId: resolveActionId(use),
|
|
2025
2164
|
connectionId: use.connection?.id,
|
|
@@ -2037,6 +2176,7 @@ function workflowDefinitionToUpsert(def) {
|
|
|
2037
2176
|
name: def.name,
|
|
2038
2177
|
description: def.description,
|
|
2039
2178
|
isActive: def.isActive,
|
|
2179
|
+
...def.trigger ? { trigger: triggerToUpsertInput(def.trigger) } : {},
|
|
2040
2180
|
managedByCode: true,
|
|
2041
2181
|
steps: def.steps.map(stepToUpsertInput)
|
|
2042
2182
|
};
|
|
@@ -2235,6 +2375,6 @@ function createServerClient(options) {
|
|
|
2235
2375
|
});
|
|
2236
2376
|
}
|
|
2237
2377
|
|
|
2238
|
-
export { API_KEY_PREFIX, ActionsResource, AgentChatClient, AgentChatStream, AgentsResource, AiConnectionsResource, ApprovalsResource, AuthResource, ConnectionsResource, DEFINE_KINDS, DiscoveryResource, EntitiesResource, EntityTypesResource, ExecutionProgressStream, ExecutionTimeoutError, ExecutionsResource, HttpClient, KnowledgeResource, LunnoaApiError, LunnoaClient, QueueItemsResource, QueuesResource, RunsResource, ScorecardsResource, SsoAuthResource, TablesResource, TasksResource, VariablesResource, WorkflowAppsResource, WorkflowsResource, assertApiKeyAllowedInEnvironment, createBrowserClient, createLocalStorageTokenStore, createMemoryTokenStore, createServerClient, defineAction, defineAgent, defineAiConnection, defineConnection, defineEntityType, defineWorkflow, entityTypeDefinitionToUpsert, isBrowserEnvironment, isLoginRequires2FA, iterateOffset, iteratePages, parseSseEvents, parseSseStream, resolveActionAppId, resolveActionId };
|
|
2378
|
+
export { API_KEY_PREFIX, ActionsResource, AgentChatClient, AgentChatStream, AgentsResource, AiConnectionsResource, ApprovalsResource, AuthResource, ConnectionsResource, DEFINE_KINDS, DiscoveryResource, EntitiesResource, EntityTypesResource, ExecutionProgressStream, ExecutionTimeoutError, ExecutionsResource, HttpClient, KnowledgeResource, LunnoaApiError, LunnoaClient, QueueItemsResource, QueuesResource, RunsResource, ScorecardsResource, SsoAuthResource, TablesResource, TasksResource, VariablesResource, WorkflowAppsResource, WorkflowsResource, assertApiKeyAllowedInEnvironment, createBrowserClient, createLocalStorageTokenStore, createMemoryTokenStore, createServerClient, defineAction, defineAgent, defineAiConnection, defineConnection, defineEntityType, defineTrigger, defineWorkflow, entityTypeDefinitionToUpsert, isBrowserEnvironment, isLoginRequires2FA, iterateOffset, iteratePages, parseSseEvents, parseSseStream, ref, resolveActionAppId, resolveActionId, resolveTriggerAppId, resolveTriggerId };
|
|
2239
2379
|
//# sourceMappingURL=index.js.map
|
|
2240
2380
|
//# sourceMappingURL=index.js.map
|