@keemakr/ui-sdk 1.5.0-dev-20261020180147 → 1.5.0-dev-20261020203449
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/examples/campaigns/README.md +9 -0
- package/examples/campaigns/approvals/index.ts +23 -0
- package/examples/campaigns/approvals/launch.ts +38 -0
- package/examples/campaigns/demo-approvals.ts +35 -0
- package/examples/campaigns/entry.json +25 -1
- package/examples/campaigns/tsconfig.json +8 -1
- package/package.json +1 -1
|
@@ -6,6 +6,8 @@ This example has:
|
|
|
6
6
|
- a nested campaign detail screen that inherits that availability;
|
|
7
7
|
- a separate Campaign settings surface available only in Dashboard;
|
|
8
8
|
- one in-memory pause action;
|
|
9
|
+
- one approval kind, `launch_campaign` (a **change** card): `approvals/index.ts` proposes it with
|
|
10
|
+
`kee.approvals.propose` and acts on the decision with `onApprovalResolved`;
|
|
9
11
|
- one brief kind, `campaign_ready` (an **action** item): `brief/index.ts` writes it onto a member's
|
|
10
12
|
Home brief with `kee.brief.upsert` and takes it off with `kee.brief.close` — see
|
|
11
13
|
docs/building-department-agents.md §3d;
|
|
@@ -20,6 +22,13 @@ npx keemakr-ui build
|
|
|
20
22
|
npx tsx demo.ts
|
|
21
23
|
```
|
|
22
24
|
|
|
25
|
+
Try the approval card the same way — the card a department admin sees, then an approve and a
|
|
26
|
+
retry that changes nothing:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx tsx demo-approvals.ts
|
|
30
|
+
```
|
|
31
|
+
|
|
23
32
|
Try the brief item the same way — the Home a fixture member would get:
|
|
24
33
|
|
|
25
34
|
```bash
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The campaigns example's approvals, wired to the agent SDK (C1.2).
|
|
2
|
+
//
|
|
3
|
+
// * proposeLaunch — from a tool or a background job: put a launch card in front of the
|
|
4
|
+
// department's admins (`kee.approvals.propose`).
|
|
5
|
+
// * the decision handler — `onApprovalResolved('launch_campaign', …)`; mount
|
|
6
|
+
// `approvalsHandler` at `POST /approvals/:dedupeKey/resolved` in the runtime. Core retries a
|
|
7
|
+
// decision for 24 hours with the same Idempotency-Key; the SDK runs the handler once per key.
|
|
8
|
+
|
|
9
|
+
import { approvalResolvedHandler, onApprovalResolved, type Kee } from '@keemakr/agent-sdk';
|
|
10
|
+
import { campaigns } from '../ui/data.js';
|
|
11
|
+
import { applyLaunchDecision, LAUNCH_KIND, launchCard, launchKey } from './launch.js';
|
|
12
|
+
|
|
13
|
+
export async function proposeLaunch(kee: Pick<Kee, 'approvals'>, campaignId: string) {
|
|
14
|
+
const campaign = campaigns.find((c) => c.id === campaignId);
|
|
15
|
+
if (!campaign) throw new Error(`no campaign ${campaignId}`);
|
|
16
|
+
return kee.approvals.propose(launchKey(campaign.id), launchCard(campaign));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
onApprovalResolved(LAUNCH_KIND, async (decision) => {
|
|
20
|
+
applyLaunchDecision(decision);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const approvalsHandler = approvalResolvedHandler();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The campaigns example's one approval kind: a person approves a campaign launch (C1.2).
|
|
2
|
+
//
|
|
3
|
+
// `launch_campaign` is a CHANGE card (entry.json `approvalKinds`): the module proposes it, a
|
|
4
|
+
// department admin decides it in Kee's queue, and core calls the module back with the decision —
|
|
5
|
+
// the module itself makes the change. This file is the plain part, with no SDK: the card, and what
|
|
6
|
+
// a decision does. ./index.ts wires it to @keemakr/agent-sdk.
|
|
7
|
+
|
|
8
|
+
import { campaigns, type Campaign } from '../ui/data.js';
|
|
9
|
+
|
|
10
|
+
/** The kind as entry.json declares it. */
|
|
11
|
+
export const LAUNCH_KIND = 'launch_campaign';
|
|
12
|
+
|
|
13
|
+
/** The dedupe key for a campaign's launch card: one open card per campaign. */
|
|
14
|
+
export function launchKey(campaignId: string): string {
|
|
15
|
+
return `launch:${campaignId}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The card to propose for a campaign. Plain words; the campaign id rides back in resumeRef. */
|
|
19
|
+
export function launchCard(campaign: Campaign) {
|
|
20
|
+
return {
|
|
21
|
+
kind: LAUNCH_KIND,
|
|
22
|
+
title: `Launch ${campaign.name}`,
|
|
23
|
+
recordRef: { objectType: 'screen:campaigns-example/campaign', id: campaign.id },
|
|
24
|
+
recordLabel: campaign.name,
|
|
25
|
+
resumeRef: campaign.id,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What a decision does: `launch` makes the campaign active; a reject leaves it paused. */
|
|
30
|
+
export function applyLaunchDecision(decision: {
|
|
31
|
+
decision: string;
|
|
32
|
+
resumeRef: string | null;
|
|
33
|
+
}): Campaign | null {
|
|
34
|
+
const campaign = campaigns.find((c) => c.id === decision.resumeRef);
|
|
35
|
+
if (!campaign) return null;
|
|
36
|
+
if (decision.decision === 'launch') campaign.status = 'active';
|
|
37
|
+
return campaign;
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Try the launch card with no core: the card a department admin sees, then an approve and a retry.
|
|
2
|
+
// npx tsx demo-approvals.ts
|
|
3
|
+
|
|
4
|
+
import { previewApprovalCard, simulateApprovalDecision } from '@keemakr/agent-sdk/testkit';
|
|
5
|
+
import entry from './entry.json' with { type: 'json' };
|
|
6
|
+
import './approvals/index.js';
|
|
7
|
+
import { launchCard, launchKey } from './approvals/launch.js';
|
|
8
|
+
import { campaigns } from './ui/data.js';
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
const campaign = campaigns[0]!;
|
|
12
|
+
campaign.status = 'paused';
|
|
13
|
+
const kind = entry.manifest.approvalKinds[0]!;
|
|
14
|
+
const card = launchCard(campaign);
|
|
15
|
+
console.log(previewApprovalCard(card, kind as never, { department: 'sales' }));
|
|
16
|
+
const first = await simulateApprovalDecision({
|
|
17
|
+
dedupeKey: launchKey(campaign.id),
|
|
18
|
+
card,
|
|
19
|
+
decision: 'approve',
|
|
20
|
+
optionId: 'launch',
|
|
21
|
+
});
|
|
22
|
+
const retry = await simulateApprovalDecision({
|
|
23
|
+
dedupeKey: launchKey(campaign.id),
|
|
24
|
+
card,
|
|
25
|
+
decision: 'approve',
|
|
26
|
+
optionId: 'launch',
|
|
27
|
+
idempotencyKey: first.idempotencyKey,
|
|
28
|
+
});
|
|
29
|
+
console.log({ status: campaign.status, retryWasDuplicate: retry.duplicate });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void main().catch((error: unknown) => {
|
|
33
|
+
console.error(error);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
});
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"manifest": {
|
|
11
11
|
"department": {
|
|
12
12
|
"key": "sales",
|
|
13
|
-
"label": "Sales"
|
|
13
|
+
"label": "Sales",
|
|
14
|
+
"role": "contributor"
|
|
14
15
|
},
|
|
15
16
|
"agents": [
|
|
16
17
|
{
|
|
@@ -48,6 +49,29 @@
|
|
|
48
49
|
"surface": "campaigns"
|
|
49
50
|
}
|
|
50
51
|
],
|
|
52
|
+
"approvalKinds": [
|
|
53
|
+
{
|
|
54
|
+
"kind": "launch_campaign",
|
|
55
|
+
"label": "Launch a campaign",
|
|
56
|
+
"class": "change",
|
|
57
|
+
"options": [
|
|
58
|
+
{
|
|
59
|
+
"id": "launch",
|
|
60
|
+
"label": "Launch it",
|
|
61
|
+
"style": "primary"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"rejectReasons": [
|
|
65
|
+
{
|
|
66
|
+
"id": "not_ready",
|
|
67
|
+
"label": "Not ready"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"audience": "role:dept_admin",
|
|
71
|
+
"expiresAfter": "P3D",
|
|
72
|
+
"sensitivity": "internal"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
51
75
|
"briefItems": [
|
|
52
76
|
{
|
|
53
77
|
"kind": "campaign_ready",
|
|
@@ -7,5 +7,12 @@
|
|
|
7
7
|
"noEmit": true,
|
|
8
8
|
"types": ["node"]
|
|
9
9
|
},
|
|
10
|
-
"include": [
|
|
10
|
+
"include": [
|
|
11
|
+
"demo.ts",
|
|
12
|
+
"demo-approvals.ts",
|
|
13
|
+
"demo-brief.ts",
|
|
14
|
+
"ui/**/*.ts",
|
|
15
|
+
"approvals/**/*.ts",
|
|
16
|
+
"brief/**/*.ts"
|
|
17
|
+
]
|
|
11
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keemakr/ui-sdk",
|
|
3
|
-
"version": "1.5.0-dev-
|
|
3
|
+
"version": "1.5.0-dev-20261020203449",
|
|
4
4
|
"description": "Product screens for keemakr marketplace modules: a versioned, server-driven UI tree schema plus defineScreen() handlers. Module code never ships to the browser — keemakr-core validates the tree and renders it with platform components.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|