@lunnoa/client 0.0.0-development
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/LICENSE +202 -0
- package/README.md +338 -0
- package/dist/cli.js +2635 -0
- package/dist/index.cjs +2141 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7211 -0
- package/dist/index.d.ts +7211 -0
- package/dist/index.js +2094 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +2640 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +3533 -0
- package/dist/react.d.ts +3533 -0
- package/dist/react.js +2630 -0
- package/dist/react.js.map +1 -0
- package/package.json +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"Commons Clause" License Condition v1.0
|
|
2
|
+
|
|
3
|
+
The Software is provided to you by the Licensor under the License, as defined
|
|
4
|
+
below, subject to the following condition.
|
|
5
|
+
|
|
6
|
+
Without limiting other conditions in the License, the grant of rights under
|
|
7
|
+
the License will not include, and the License does not grant to you, the
|
|
8
|
+
right to Sell the Software.
|
|
9
|
+
|
|
10
|
+
For purposes of the foregoing, "Sell" means practicing any or all of the
|
|
11
|
+
rights granted to you under the License to provide to third parties, for a
|
|
12
|
+
fee or other consideration (including without limitation fees for hosting or
|
|
13
|
+
consulting/ support services related to the Software), a product or service
|
|
14
|
+
whose value derives, entirely or substantially, from the functionality of the
|
|
15
|
+
Software. Any license notice or attribution required by the License must also
|
|
16
|
+
include this Commons Clause License Condition notice.
|
|
17
|
+
|
|
18
|
+
Software: @lunnoa/client
|
|
19
|
+
|
|
20
|
+
License: Apache License, Version 2.0
|
|
21
|
+
(http://www.apache.org/licenses/LICENSE-2.0)
|
|
22
|
+
|
|
23
|
+
Licensor: Lunnoa Labs
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
Apache License
|
|
28
|
+
Version 2.0, January 2004
|
|
29
|
+
http://www.apache.org/licenses/
|
|
30
|
+
|
|
31
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
32
|
+
|
|
33
|
+
1. Definitions.
|
|
34
|
+
|
|
35
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
36
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
37
|
+
|
|
38
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
39
|
+
the copyright owner that is granting the License.
|
|
40
|
+
|
|
41
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
42
|
+
other entities that control, are controlled by, or are under common
|
|
43
|
+
control with that entity. For the purposes of this definition,
|
|
44
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
45
|
+
direction or management of such entity, whether by contract or
|
|
46
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
47
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
48
|
+
|
|
49
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
50
|
+
exercising permissions granted by this License.
|
|
51
|
+
|
|
52
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
53
|
+
including but not limited to software source code, documentation
|
|
54
|
+
source, and configuration files.
|
|
55
|
+
|
|
56
|
+
"Object" form shall mean any form resulting from mechanical
|
|
57
|
+
transformation or translation of a Source form, including but
|
|
58
|
+
not limited to compiled object code, generated documentation,
|
|
59
|
+
and conversions to other media types.
|
|
60
|
+
|
|
61
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
62
|
+
Object form, made available under the License, as indicated by a
|
|
63
|
+
copyright notice that is included in or attached to the work
|
|
64
|
+
(an example is provided in the Appendix below).
|
|
65
|
+
|
|
66
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
67
|
+
form, that is based on (or derived from) the Work and for which the
|
|
68
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
69
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
70
|
+
of this License, Derivative Works shall not include works that remain
|
|
71
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
72
|
+
the Work and Derivative Works thereof.
|
|
73
|
+
|
|
74
|
+
"Contribution" shall mean any work of authorship, including
|
|
75
|
+
the original version of the Work and any modifications or additions
|
|
76
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
77
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
78
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
79
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
80
|
+
means any form of electronic, verbal, or written communication sent
|
|
81
|
+
to the Licensor or its representatives, including but not limited to
|
|
82
|
+
communication on electronic mailing lists, source code control systems,
|
|
83
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
84
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
85
|
+
excluding communication that is conspicuously marked or otherwise
|
|
86
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
87
|
+
|
|
88
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
89
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
90
|
+
subsequently incorporated within the Work.
|
|
91
|
+
|
|
92
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
93
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
94
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
95
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
96
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
97
|
+
Work and such Derivative Works in Source or Object form.
|
|
98
|
+
|
|
99
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
100
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
101
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
102
|
+
(except as stated in this section) patent license to make, have made,
|
|
103
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
104
|
+
where such license applies only to those patent claims licensable
|
|
105
|
+
by such Contributor that are necessarily infringed by their
|
|
106
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
107
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
108
|
+
institute patent litigation against any entity (including a
|
|
109
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
110
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
111
|
+
or contributory patent infringement, then any patent licenses
|
|
112
|
+
granted to You under this License for that Work shall terminate
|
|
113
|
+
as of the date such litigation is filed.
|
|
114
|
+
|
|
115
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
116
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
117
|
+
modifications, and in Source or Object form, provided that You
|
|
118
|
+
meet the following conditions:
|
|
119
|
+
|
|
120
|
+
(a) You must give any other recipients of the Work or
|
|
121
|
+
Derivative Works a copy of this License; and
|
|
122
|
+
|
|
123
|
+
(b) You must cause any modified files to carry prominent notices
|
|
124
|
+
stating that You changed the files; and
|
|
125
|
+
|
|
126
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
127
|
+
that You distribute, all copyright, patent, trademark, and
|
|
128
|
+
attribution notices from the Source form of the Work,
|
|
129
|
+
excluding those notices that do not pertain to any part of
|
|
130
|
+
the Derivative Works; and
|
|
131
|
+
|
|
132
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
133
|
+
distribution, then any Derivative Works that You distribute must
|
|
134
|
+
include a readable copy of the attribution notices contained
|
|
135
|
+
within such NOTICE file, excluding those notices that do not
|
|
136
|
+
pertain to any part of the Derivative Works, in at least one
|
|
137
|
+
of the following places: within a NOTICE text file distributed
|
|
138
|
+
as part of the Derivative Works; within the Source form or
|
|
139
|
+
documentation, if provided along with the Derivative Works; or,
|
|
140
|
+
within a display generated by the Derivative Works, if and
|
|
141
|
+
wherever such third-party notices normally appear. The contents
|
|
142
|
+
of the NOTICE file are for informational purposes only and
|
|
143
|
+
do not modify the License. You may add Your own attribution
|
|
144
|
+
notices within Derivative Works that You distribute, alongside
|
|
145
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
146
|
+
that such additional attribution notices cannot be construed
|
|
147
|
+
as modifying the License.
|
|
148
|
+
|
|
149
|
+
You may add Your own copyright statement to Your modifications and
|
|
150
|
+
may provide additional or different license terms and conditions
|
|
151
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
152
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
153
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
154
|
+
the conditions stated in this License.
|
|
155
|
+
|
|
156
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
157
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
158
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
159
|
+
this License, without any additional terms or conditions.
|
|
160
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
161
|
+
the terms of any separate license agreement you may have executed
|
|
162
|
+
with Licensor regarding such Contributions.
|
|
163
|
+
|
|
164
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
165
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
166
|
+
except as required for reasonable and customary use in describing the
|
|
167
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
168
|
+
|
|
169
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
170
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
171
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
172
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
173
|
+
implied, including, without limitation, any warranties or conditions
|
|
174
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
175
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
176
|
+
appropriateness of using or redistributing the Work and assume any
|
|
177
|
+
risks associated with Your exercise of permissions under this License.
|
|
178
|
+
|
|
179
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
180
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
181
|
+
unless required by applicable law (such as deliberate and grossly
|
|
182
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
183
|
+
liable to You for damages, including any direct, indirect, special,
|
|
184
|
+
incidental, or consequential damages of any character arising as a
|
|
185
|
+
result of this License or out of the use or inability to use the
|
|
186
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
187
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
188
|
+
other commercial damages or losses), even if such Contributor
|
|
189
|
+
has been advised of the possibility of such damages.
|
|
190
|
+
|
|
191
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
192
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
193
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
194
|
+
or other liability obligations and/or rights consistent with this
|
|
195
|
+
License. However, in accepting such obligations, You may act only
|
|
196
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
197
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
198
|
+
defend, and hold each Contributor harmless for any liability
|
|
199
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
200
|
+
of your accepting any such warranty or additional liability.
|
|
201
|
+
|
|
202
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# @lunnoa/client
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for building applications **on top of** [Lunnoa Automate](https://github.com/lunnoa-automate/lunnoa_automate).
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@lunnoa/client)
|
|
6
|
+
[](https://www.npmjs.com/package/@lunnoa/client)
|
|
7
|
+
|
|
8
|
+
## What is this?
|
|
9
|
+
|
|
10
|
+
`@lunnoa/client` is the official consumption SDK for the Lunnoa Automate **Public API**: a typed client for agents and chat (with SSE streaming), workflows and executions, entities (Objects), knowledge, queues, variables, connections, and projects — plus a codegen command that types the SDK against **your** deployment's entity types, workflows, and agents.
|
|
11
|
+
|
|
12
|
+
**The boundary with the other Lunnoa SDK:** [`@lunnoa/toolkit`](https://github.com/lunnoa-automate/lunnoa_toolkit) is for building integration apps that run *inside* the platform (`createAction` / `createApp`); **`@lunnoa/client` is for building applications *on top of* the platform** — including `define*` factories, `runs.start`, and CLI deploy of workflows/agents.
|
|
13
|
+
|
|
14
|
+
The SDK is deliberately **presentation-free** at the core: no components or widgets. Optional **headless** React hooks ship as `@lunnoa/client/react`. You build fully custom UIs in your own design system; the SDK encodes the platform knowledge (protocols, schemas, conventions). A frontend-authoring skill for AI coding agents ships with the package (see [`.cursor/skills/lunnoa-client/SKILL.md`](./.cursor/skills/lunnoa-client/SKILL.md)).
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @lunnoa/client
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Requirements:** Node.js ≥ 20 (or any runtime with `fetch` and web streams).
|
|
23
|
+
|
|
24
|
+
## Quickstart
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { LunnoaClient } from '@lunnoa/client';
|
|
28
|
+
|
|
29
|
+
const lunnoa = new LunnoaClient({
|
|
30
|
+
baseUrl: 'https://lunnoa.your-company.example',
|
|
31
|
+
apiKey: process.env.LUNNOA_API_KEY, // lna_... — server-side only
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const { data: invoices } = await lunnoa.entities.list({
|
|
35
|
+
objectTypeSlug: 'invoice',
|
|
36
|
+
state: 'pending',
|
|
37
|
+
expansion: ['attributes'],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
A SuperAdmin creates API keys in **Adminspace → API keys**, choosing the workspace and an RBAC role for the key's service account. The role is the key's entire capability model — grant the minimum permission set, not Admin.
|
|
42
|
+
|
|
43
|
+
## Two auth patterns
|
|
44
|
+
|
|
45
|
+
| Pattern | Credential | Where |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| **A. Backend holds the key** | `apiKey: 'lna_...'` via `createServerClient` | Your server, background jobs, server-rendered pages. The key acts as a workspace-scoped service account. |
|
|
48
|
+
| **B. End users are Lunnoa users** | User JWT via `createBrowserClient` + `lunnoa.auth.*` | Browser apps. Login, 2FA, refresh, and SSO discovery are wrapped; per-user permissions apply. |
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import {
|
|
52
|
+
createBrowserClient,
|
|
53
|
+
createServerClient,
|
|
54
|
+
isLoginRequires2FA,
|
|
55
|
+
} from '@lunnoa/client';
|
|
56
|
+
|
|
57
|
+
// Pattern A — server-side
|
|
58
|
+
const server = createServerClient({
|
|
59
|
+
baseUrl,
|
|
60
|
+
apiKey: process.env.LUNNOA_API_KEY!,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Pattern B — browser (tokens in localStorage by default; auto-refresh on 401)
|
|
64
|
+
const lunnoa = createBrowserClient({ baseUrl });
|
|
65
|
+
const result = await lunnoa.auth.login({ email, password });
|
|
66
|
+
if (isLoginRequires2FA(result)) {
|
|
67
|
+
await lunnoa.auth.verify2faLogin({
|
|
68
|
+
sessionToken: result.sessionToken,
|
|
69
|
+
token: totpCode,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const me = await lunnoa.auth.me();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**API keys never ship to browsers.** The SDK enforces this: constructing a client with an `lna_` key while `window` exists throws immediately. Browser apps either use Pattern B or call your own backend, which holds the key (backend-for-frontend).
|
|
76
|
+
|
|
77
|
+
For Pattern B the deployment must allow your origin via its `CORS_ALLOWED_ORIGINS` configuration. See the Authentication guide under `guides/develop/client/auth` in Lunnoa Docs for SSO redirect constraints and token stores.
|
|
78
|
+
|
|
79
|
+
### React (optional)
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import {
|
|
83
|
+
LunnoaAuthProvider,
|
|
84
|
+
useLunnoaAuth,
|
|
85
|
+
useLunnoaClient,
|
|
86
|
+
useExecutionProgress,
|
|
87
|
+
useNeedsInput,
|
|
88
|
+
useAgentChat,
|
|
89
|
+
useApprovalsInbox,
|
|
90
|
+
useEntityList,
|
|
91
|
+
} from '@lunnoa/client/react';
|
|
92
|
+
|
|
93
|
+
<LunnoaAuthProvider baseUrl={baseUrl}>
|
|
94
|
+
<App />
|
|
95
|
+
</LunnoaAuthProvider>
|
|
96
|
+
|
|
97
|
+
const { user, status, login, logout } = useLunnoaAuth();
|
|
98
|
+
const lunnoa = useLunnoaClient();
|
|
99
|
+
const { progress, status: progressStatus } = useExecutionProgress(executionId);
|
|
100
|
+
const { waiting, pendingInput, submitInput } = useNeedsInput(progress);
|
|
101
|
+
const { messages, send, stop, taskId } = useAgentChat(agentId); // needs @ai-sdk/react
|
|
102
|
+
const { items, decide } = useApprovalsInbox({ pollIntervalMs: 15_000 });
|
|
103
|
+
const { data, page, setPage } = useEntityList({ objectTypeSlug: 'invoice' });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Peers: `react` ≥ 18 (required for `/react`); `@ai-sdk/react` only for `useAgentChat`. Core `@lunnoa/client` stays headless.
|
|
107
|
+
|
|
108
|
+
## Resources
|
|
109
|
+
|
|
110
|
+
Most namespaces map to the Public API surface (`openapi.public.json`):
|
|
111
|
+
|
|
112
|
+
`auth` · `agents` · `tasks` · `agentChat` (SSE streaming) · `workflows` · `executions` · `actions` · `entities` · `entityTypes` · `knowledge` · `queues` · `queueItems` · `variables` · `connections` · `projects` · `workflowApps` · `discovery`
|
|
113
|
+
|
|
114
|
+
`approvals` uses the authenticated **workspace** API (`/api/approvals/...`), not Public API v1. The inbox is filtered to requests where the current user is an eligible approver.
|
|
115
|
+
|
|
116
|
+
Errors are `LunnoaApiError` with `status`, `body`, and convenience flags (`isUnauthorized`, `isForbidden`, `isRateLimited`). Paginated lists have async iteration (`entities.iterate(...)`, `queueItems.iterate(...)`).
|
|
117
|
+
|
|
118
|
+
## Worked examples
|
|
119
|
+
|
|
120
|
+
Runnable versions live in [`examples/`](./examples).
|
|
121
|
+
|
|
122
|
+
### Query and create entities
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const invoiceType = await lunnoa.entityTypes.getBySlug('invoice', {
|
|
126
|
+
expansion: ['attributeSchema', 'stateSchema'],
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const created = await lunnoa.entities.create({
|
|
130
|
+
name: 'INV-2026-0042',
|
|
131
|
+
objectTypeId: invoiceType.id,
|
|
132
|
+
attributes: { amount: 1250.5, currency: 'CHF' }, // keyed by field ID
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
for await (const invoice of lunnoa.entities.iterate({ objectTypeSlug: 'invoice' })) {
|
|
136
|
+
// pages fetched lazily
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Trigger a workflow and wait for the result
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const { id } = await lunnoa.workflows.execute(workflowId, { customerEmail: 'x@y.z' });
|
|
144
|
+
const execution = await lunnoa.executions.waitUntilFinished(id); // poll with backoff
|
|
145
|
+
console.log(execution.status, execution.output);
|
|
146
|
+
|
|
147
|
+
// or in one call:
|
|
148
|
+
const done = await lunnoa.workflows.executeAndWait(workflowId, inputs);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Run a single app action (ad-hoc Execution)
|
|
152
|
+
|
|
153
|
+
Creates a one-step Execution with `source: SDK` (same inbox as workflow runs). Discover `appId` / `actionId` / `inputConfig` via `workflowApps.list()`. Pass `connectionId` (the Connection instance UUID from Connections) when the action needs a connection and more than one exists for the app.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const result = await lunnoa.actions.run({
|
|
157
|
+
appId: 'http',
|
|
158
|
+
actionId: 'http_action_send-request',
|
|
159
|
+
// connectionId: '...', // Connection.id UUID when needed
|
|
160
|
+
input: { method: 'GET', url: 'https://example.com' },
|
|
161
|
+
});
|
|
162
|
+
console.log(result.status, result.output, result.executionPath);
|
|
163
|
+
|
|
164
|
+
// Same record via the Executions API:
|
|
165
|
+
const again = await lunnoa.executions.get(result.id, {
|
|
166
|
+
expansion: ['status', 'source', 'executionPath'],
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Resume a NEEDS_INPUT execution from a custom form
|
|
171
|
+
|
|
172
|
+
Workflows can pause and wait for human input. Render a form for the waiting step and resume:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const execution = await lunnoa.executions.get(executionId, {
|
|
176
|
+
expansion: ['status', 'executionPath'],
|
|
177
|
+
});
|
|
178
|
+
const waiting = execution.executionPath?.find((s) => s.status === 'NEEDS_INPUT');
|
|
179
|
+
|
|
180
|
+
await lunnoa.executions.submitInput(executionId, waiting!.nodeId, {
|
|
181
|
+
approved: true,
|
|
182
|
+
comment: 'Release the payment.',
|
|
183
|
+
});
|
|
184
|
+
const finished = await lunnoa.executions.waitUntilFinished(executionId);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The `executionPath` expansion is the business-readable step list (labels, per-step status, timings, loop iterations) custom UIs render progress from.
|
|
188
|
+
|
|
189
|
+
### Approvals inbox (Request Approval nodes)
|
|
190
|
+
|
|
191
|
+
List pending approvals the authenticated user can decide, then approve or reject. Prefer a user JWT (pattern B) so eligibility matches a real person. Requires `approvals:read` / `approvals:decide`.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const { items } = await lunnoa.approvals.inbox(); // pending + partially_approved
|
|
195
|
+
|
|
196
|
+
for (const person of items[0]?.eligibleApprovers ?? []) {
|
|
197
|
+
console.log(person.email, person.name); // who can still decide
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
await lunnoa.approvals.decide(items[0]!.approvalId, {
|
|
201
|
+
decision: 'approved',
|
|
202
|
+
comment: 'Within policy limits.',
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Or by execution + node when you already have those IDs:
|
|
206
|
+
await lunnoa.executions.submitApproval(executionId, nodeId, {
|
|
207
|
+
decision: 'rejected',
|
|
208
|
+
comment: 'Amount exceeds limit.',
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Do not use `submitInput` for Request Approval nodes; that path is for generic `NEEDS_INPUT` forms.
|
|
213
|
+
|
|
214
|
+
### Stream agent chat
|
|
215
|
+
|
|
216
|
+
The streaming module is hand-written (code generators handle SSE poorly) and speaks the same wire protocol as the bundled UI: AI SDK `UIMessage` chunks, SSE-framed, resumable.
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const taskId = crypto.randomUUID(); // first message creates the task
|
|
220
|
+
const stream = await lunnoa.agentChat.streamMessage(agentId, taskId, 'Hello!');
|
|
221
|
+
|
|
222
|
+
for await (const chunk of stream) {
|
|
223
|
+
if (chunk.type === 'text-delta') process.stdout.write(chunk.delta);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Reattach after a disconnect (returns null when nothing is running):
|
|
227
|
+
const resumed = await lunnoa.agentChat.resumeStream(agentId, taskId);
|
|
228
|
+
|
|
229
|
+
// Cancel a running turn (optionally persisting the partial reply):
|
|
230
|
+
await lunnoa.agentChat.stop(agentId, taskId);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`stream.toUIMessageStream()` returns a `ReadableStream<UIMessageChunk>` ready for the AI SDK's `readUIMessageStream` when you want assembled `UIMessage` snapshots for rendering.
|
|
234
|
+
|
|
235
|
+
## Deployment-specific codegen
|
|
236
|
+
|
|
237
|
+
Entity types, workflow inputs, and agents are defined per deployment, so the generic SDK can only type them loosely. The codegen command queries your deployment and emits typed accessors — the same developer experience as Prisma client or Supabase type generation:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npx @lunnoa/client codegen --url https://lunnoa.your-company.example --api-key lna_... --out ./src/lunnoa
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
This writes `lunnoa.generated.ts`:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { LunnoaClient } from '@lunnoa/client';
|
|
247
|
+
import { createDeploymentClient } from './lunnoa/lunnoa.generated';
|
|
248
|
+
|
|
249
|
+
const lunnoa = createDeploymentClient(new LunnoaClient({ baseUrl, apiKey }));
|
|
250
|
+
|
|
251
|
+
// Entity attributes and states are compile-time checked:
|
|
252
|
+
const open = await lunnoa.entities.invoice.list({ state: 'pending' });
|
|
253
|
+
await lunnoa.entities.invoice.create({
|
|
254
|
+
name: 'INV-1',
|
|
255
|
+
attributes: { amount: 99.5, status: 'pending' },
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Workflow inputs typed from the manual trigger's input schema:
|
|
259
|
+
await lunnoa.workflows.processInvoice.executeAndWait({ invoiceId: 'abc' });
|
|
260
|
+
|
|
261
|
+
// Agents by name:
|
|
262
|
+
const stream = await lunnoa.agents.supportAgent.streamMessage(taskId, 'Hi');
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Re-run codegen whenever entity types, workflows, or agents change on the deployment.
|
|
266
|
+
|
|
267
|
+
## Define, run, and CLI deploy
|
|
268
|
+
|
|
269
|
+
Author local definitions with `defineWorkflow` / `defineAgent`, run linear chains with `lunnoa.runs.start`, and upsert into a project with the CLI (prefer CLI over calling upsert from app code):
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
npx @lunnoa/client workflows deploy ./workflows/sync-orders.ts \
|
|
273
|
+
--url https://lunnoa.example --api-key lna_... --project-id <uuid>
|
|
274
|
+
npx @lunnoa/client agents deploy ./agents/triage.ts \
|
|
275
|
+
--url https://lunnoa.example --api-key lna_... --project-id <uuid>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
`defineAction` binds catalogue actions only; toolkit `createAction` is for in-platform apps. See Lunnoa Docs under `guides/develop/client/define`, `runs`, and `cli-deploy`.
|
|
279
|
+
|
|
280
|
+
## Regenerating the API types
|
|
281
|
+
|
|
282
|
+
The generic types are generated from the deployment's public OpenAPI spec (`spec/openapi.public.json`, produced by the platform's `export-openapi --public`):
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
npm run codegen:spec
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## AI-assisted UI building
|
|
289
|
+
|
|
290
|
+
The repo ships a frontend-authoring skill at [`.cursor/skills/lunnoa-client/SKILL.md`](./.cursor/skills/lunnoa-client/SKILL.md) that teaches coding agents (Cursor, Claude) how to build custom UIs against this SDK: auth patterns, discovery, codegen, and the four worked recipes above. Copy it into your app's `.cursor/skills/` folder.
|
|
291
|
+
|
|
292
|
+
## Versioning and stability
|
|
293
|
+
|
|
294
|
+
This package follows [semantic versioning](https://semver.org/). It targets the Lunnoa Automate **Public API v1**: endpoints marked stable by the platform's `x-public` contract. Public endpoints only change additively; breaking platform changes come with a deprecation window.
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
Licensed under **Apache-2.0 with Commons Clause**.
|
|
299
|
+
|
|
300
|
+
You may use, modify, and distribute the software under Apache 2.0 terms, with one additional restriction: you may not sell the software itself (the SDK as a standalone product). Building and operating applications that *use* the SDK is permitted.
|
|
301
|
+
|
|
302
|
+
## Development
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
git clone https://github.com/lunnoa-automate/lunnoa_client.git
|
|
306
|
+
cd lunnoa_client
|
|
307
|
+
pnpm install
|
|
308
|
+
pnpm test
|
|
309
|
+
pnpm build
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Build output (ESM + CJS + type declarations) is written to `dist/`. Only `dist/` is included in the published npm tarball.
|
|
313
|
+
|
|
314
|
+
## Publishing
|
|
315
|
+
|
|
316
|
+
Releases are fully automated with [semantic-release](https://github.com/semantic-release/semantic-release), the same setup as `@lunnoa/toolkit`: merge [Conventional Commits](https://www.conventionalcommits.org/) to `master`/`main`, CI runs tests and build, and the Release workflow computes the version, updates `CHANGELOG.md`, tags, creates the GitHub release, and publishes to npm via trusted publishing (OIDC).
|
|
317
|
+
|
|
318
|
+
| Commit prefix | Version bump |
|
|
319
|
+
| --- | --- |
|
|
320
|
+
| `fix:` | Patch |
|
|
321
|
+
| `feat:` | Minor |
|
|
322
|
+
| `feat!:` / `BREAKING CHANGE:` | Major |
|
|
323
|
+
|
|
324
|
+
### npm trusted publishing (OIDC)
|
|
325
|
+
|
|
326
|
+
Publishing uses [npm trusted publishers](https://docs.npmjs.com/trusted-publishers/) via GitHub Actions OIDC — no `NPM_TOKEN` secret is required.
|
|
327
|
+
|
|
328
|
+
Before the first release, configure a **Trusted Publisher** on [npmjs.com](https://www.npmjs.com) (org admin login for `@lunnoa`):
|
|
329
|
+
|
|
330
|
+
| Field | Value |
|
|
331
|
+
| --- | --- |
|
|
332
|
+
| Package | `@lunnoa/client` |
|
|
333
|
+
| Organization / user | `lunnoa-automate` |
|
|
334
|
+
| Repository | `lunnoa_client` |
|
|
335
|
+
| Workflow filename | `release.yml` |
|
|
336
|
+
| Environment | *(leave empty)* |
|
|
337
|
+
|
|
338
|
+
The release workflow grants `id-token: write` and uses **semantic-release v25** with Node 24.
|