@dench.com/cli 3.2.4-staging.309 → 3.3.0-staging.314
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 +95 -0
- package/app-sdk.d.ts +132 -0
- package/dench.ts +67 -42
- package/lib/app-sdk-catalog.generated.ts +11 -0
- package/lib/command-registry.ts +65 -0
- package/lib/signal-agents.ts +454 -0
- package/lib/unipile-toolkits.ts +55 -0
- package/package.json +2 -1
- package/signals.ts +109 -0
- package/tools.ts +125 -15
package/tools.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* paid-workspace gateway key resolved from the active agent session by
|
|
8
8
|
* the top-level dispatcher.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* Dench-brokered connections are not pure gateway passthroughs:
|
|
11
11
|
* - the connection LISTING: Gmail, Outlook, Calendar and LinkedIn (Unipile)
|
|
12
12
|
* and Slack (Dench's in-house Slack app) are brokered by Dench, not
|
|
13
13
|
* Composio, so `status` also reads them from Convex and merges the two
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* - `connect slack`: prints the in-house Slack install URL
|
|
16
16
|
* (`/api/slack/install?slug=…`) instead of a Composio OAuth redirect —
|
|
17
17
|
* the in-house connection always takes preference over Composio Slack.
|
|
18
|
+
* - Gmail, Outlook, Calendar and LinkedIn connect through the same Unipile
|
|
19
|
+
* hosted-auth actions as the web app, authenticated by the Dench session.
|
|
18
20
|
*
|
|
19
21
|
* Subcommands:
|
|
20
22
|
*
|
|
@@ -51,6 +53,10 @@ import {
|
|
|
51
53
|
parseJson,
|
|
52
54
|
shift as shiftRaw,
|
|
53
55
|
} from "./lib/cli-args";
|
|
56
|
+
import {
|
|
57
|
+
normalizeUnipileToolkitSlug,
|
|
58
|
+
unipileConnectKindFromToolkitSlug,
|
|
59
|
+
} from "./lib/unipile-toolkits";
|
|
54
60
|
|
|
55
61
|
// ---------------------------------------------------------------------------
|
|
56
62
|
// Public dispatcher
|
|
@@ -62,6 +68,7 @@ export type ToolCliContext = {
|
|
|
62
68
|
bearerToken?: string;
|
|
63
69
|
gatewayBaseUrl?: string;
|
|
64
70
|
gatewayHeaders?: Record<string, string>;
|
|
71
|
+
gatewayAuthError?: string;
|
|
65
72
|
/**
|
|
66
73
|
* Convex client + bearer for the Unipile half of the list. Absent on the
|
|
67
74
|
* help path and whenever the caller could not be authenticated, in which
|
|
@@ -80,7 +87,7 @@ export type ToolCliContext = {
|
|
|
80
87
|
|
|
81
88
|
type GatewayAuthContext = Pick<
|
|
82
89
|
ToolCliContext,
|
|
83
|
-
"bearerToken" | "gatewayBaseUrl" | "gatewayHeaders"
|
|
90
|
+
"bearerToken" | "gatewayBaseUrl" | "gatewayHeaders" | "gatewayAuthError"
|
|
84
91
|
>;
|
|
85
92
|
|
|
86
93
|
type UnipileAuthContext = Pick<ToolCliContext, "convex" | "sessionToken">;
|
|
@@ -129,6 +136,15 @@ const getUnipileToolRef = makeFunctionReference<"query">(
|
|
|
129
136
|
const runUnipileToolRef = makeFunctionReference<"action">(
|
|
130
137
|
"functions/unipileToolsNode:runTool",
|
|
131
138
|
);
|
|
139
|
+
const connectMailboxRef = makeFunctionReference<"action">(
|
|
140
|
+
"functions/emailMailboxUnipileNode:createHostedAuthLink",
|
|
141
|
+
);
|
|
142
|
+
const connectLinkedinRef = makeFunctionReference<"action">(
|
|
143
|
+
"functions/linkedinUnipileNode:createHostedAuthLink",
|
|
144
|
+
);
|
|
145
|
+
const connectCalendarRef = makeFunctionReference<"action">(
|
|
146
|
+
"functions/calendarUnipileNode:createCalendarHostedAuthLink",
|
|
147
|
+
);
|
|
132
148
|
|
|
133
149
|
/**
|
|
134
150
|
* Gmail, Outlook, Calendar and LinkedIn are brokered by Dench, and Composio
|
|
@@ -234,6 +250,15 @@ export async function fetchConnectedAppsSummary(
|
|
|
234
250
|
unipileAvailable: unipile.available,
|
|
235
251
|
...(unipile.error ? { unipileError: unipile.error } : {}),
|
|
236
252
|
};
|
|
253
|
+
if (ctx.gatewayAuthError) {
|
|
254
|
+
return {
|
|
255
|
+
available: false,
|
|
256
|
+
count: unipile.connections.length,
|
|
257
|
+
connections: unipile.connections,
|
|
258
|
+
...unipileFields,
|
|
259
|
+
reason: ctx.gatewayAuthError,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
237
262
|
let payload: unknown;
|
|
238
263
|
try {
|
|
239
264
|
payload = await callGateway(ctx, "GET", "/v1/composio/connections");
|
|
@@ -251,7 +276,9 @@ export async function fetchConnectedAppsSummary(
|
|
|
251
276
|
: { ...failure, error: errorMessage(error) };
|
|
252
277
|
}
|
|
253
278
|
const connections = [
|
|
254
|
-
...extractConnections(payload)
|
|
279
|
+
...extractConnections(payload)
|
|
280
|
+
.map(compactConnection)
|
|
281
|
+
.filter((connection) => !normalizeUnipileToolkitSlug(connection.toolkit)),
|
|
255
282
|
...unipile.connections,
|
|
256
283
|
];
|
|
257
284
|
return {
|
|
@@ -267,12 +294,30 @@ export async function fetchConnectedAppsSummary(
|
|
|
267
294
|
// ---------------------------------------------------------------------------
|
|
268
295
|
|
|
269
296
|
async function runStatusSubcommand(ctx: ToolCliContext): Promise<void> {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
297
|
+
const requestedToolkit = ctx.args[0]?.startsWith("--")
|
|
298
|
+
? undefined
|
|
299
|
+
: ctx.args[0];
|
|
300
|
+
if (requestedToolkit) ctx.args.shift();
|
|
301
|
+
const unipileToolkit = requestedToolkit
|
|
302
|
+
? normalizeUnipileToolkitSlug(requestedToolkit)
|
|
303
|
+
: null;
|
|
304
|
+
const filterToolkit = unipileToolkit ?? requestedToolkit;
|
|
305
|
+
|
|
306
|
+
let connectionsSummary: Awaited<ReturnType<typeof fetchConnectedAppsSummary>>;
|
|
307
|
+
if (unipileToolkit) {
|
|
308
|
+
const unipile = await fetchUnipileConnections(ctx);
|
|
309
|
+
connectionsSummary = {
|
|
310
|
+
available: unipile.available,
|
|
311
|
+
count: unipile.connections.length,
|
|
312
|
+
connections: unipile.connections,
|
|
313
|
+
unipileAvailable: unipile.available,
|
|
314
|
+
...(unipile.error ? { unipileError: unipile.error } : {}),
|
|
315
|
+
};
|
|
316
|
+
} else {
|
|
317
|
+
connectionsSummary = await fetchConnectedAppsSummary(ctx);
|
|
318
|
+
}
|
|
274
319
|
let toolkitsPayload: unknown = null;
|
|
275
|
-
if (filterToolkit && connectionsSummary.available) {
|
|
320
|
+
if (filterToolkit && !unipileToolkit && connectionsSummary.available) {
|
|
276
321
|
const search = encodeURIComponent(filterToolkit);
|
|
277
322
|
toolkitsPayload = await callGateway(
|
|
278
323
|
ctx,
|
|
@@ -286,12 +331,15 @@ async function runStatusSubcommand(ctx: ToolCliContext): Promise<void> {
|
|
|
286
331
|
// with the Unipile mailbox instead of nothing.
|
|
287
332
|
const filteredConnections = filterToolkit
|
|
288
333
|
? allConnections.filter(
|
|
289
|
-
(conn) =>
|
|
334
|
+
(conn) =>
|
|
335
|
+
conn.toolkit.toLowerCase() === filterToolkit.toLowerCase() ||
|
|
336
|
+
(unipileToolkit === "calendar" &&
|
|
337
|
+
["google-calendar", "outlook-calendar"].includes(conn.toolkit)),
|
|
290
338
|
)
|
|
291
339
|
: allConnections;
|
|
292
340
|
|
|
293
341
|
const summary = {
|
|
294
|
-
ok: true,
|
|
342
|
+
ok: unipileToolkit ? connectionsSummary.unipileAvailable : true,
|
|
295
343
|
available: connectionsSummary.available,
|
|
296
344
|
toolkit: filterToolkit ?? null,
|
|
297
345
|
count: filteredConnections.length,
|
|
@@ -642,6 +690,57 @@ async function runConnectSubcommand(ctx: ToolCliContext): Promise<void> {
|
|
|
642
690
|
await runSlackConnectSubcommand(ctx, normalizedToolkit);
|
|
643
691
|
return;
|
|
644
692
|
}
|
|
693
|
+
const unipile = unipileConnectKindFromToolkitSlug(toolkit);
|
|
694
|
+
if (unipile) {
|
|
695
|
+
if (!ctx.convex || !ctx.sessionToken) {
|
|
696
|
+
throw new ToolCliError(
|
|
697
|
+
"Sign in with `dench signin` or use a member-owned Dench API key to connect this integration.",
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
if (ctx.args.includes("--callback-url")) {
|
|
701
|
+
throw new ToolCliError(
|
|
702
|
+
"Unipile connections use Dench's managed callback. --callback-url is only supported for Composio integrations.",
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
const result = asRecord(
|
|
706
|
+
await ctx.convex.action(
|
|
707
|
+
unipile.kind === "mailbox"
|
|
708
|
+
? connectMailboxRef
|
|
709
|
+
: unipile.kind === "linkedin"
|
|
710
|
+
? connectLinkedinRef
|
|
711
|
+
: connectCalendarRef,
|
|
712
|
+
{
|
|
713
|
+
sessionToken: ctx.sessionToken,
|
|
714
|
+
...(unipile.kind === "mailbox" ? { provider: unipile.provider } : {}),
|
|
715
|
+
},
|
|
716
|
+
),
|
|
717
|
+
);
|
|
718
|
+
const redirectUrl = stringField(result, "link");
|
|
719
|
+
if (!redirectUrl) {
|
|
720
|
+
throw new ToolCliError("Unipile did not return a connection link.");
|
|
721
|
+
}
|
|
722
|
+
const message = `Connect ${toolkit} here: ${redirectUrl}`;
|
|
723
|
+
if (ctx.jsonOutput) {
|
|
724
|
+
console.log(
|
|
725
|
+
JSON.stringify(
|
|
726
|
+
{
|
|
727
|
+
ok: true,
|
|
728
|
+
source: "unipile",
|
|
729
|
+
toolkit: normalizeUnipileToolkitSlug(toolkit),
|
|
730
|
+
redirectUrl,
|
|
731
|
+
expiresAt: result?.expiresAt,
|
|
732
|
+
connectionId: null,
|
|
733
|
+
message,
|
|
734
|
+
},
|
|
735
|
+
null,
|
|
736
|
+
2,
|
|
737
|
+
),
|
|
738
|
+
);
|
|
739
|
+
} else {
|
|
740
|
+
console.log(message);
|
|
741
|
+
}
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
645
744
|
const callbackUrl =
|
|
646
745
|
getFlag(ctx.args, "--callback-url") ??
|
|
647
746
|
process.env.DENCH_OAUTH_CALLBACK_URL?.trim() ??
|
|
@@ -1075,6 +1174,8 @@ function formatStatusSummary(summary: {
|
|
|
1075
1174
|
connections: CompactConnection[];
|
|
1076
1175
|
unipileAvailable?: boolean;
|
|
1077
1176
|
unipileError?: string;
|
|
1177
|
+
reason?: string;
|
|
1178
|
+
error?: string;
|
|
1078
1179
|
}): string {
|
|
1079
1180
|
const lines: string[] = [];
|
|
1080
1181
|
if (summary.toolkit) {
|
|
@@ -1096,6 +1197,11 @@ function formatStatusSummary(summary: {
|
|
|
1096
1197
|
})`,
|
|
1097
1198
|
);
|
|
1098
1199
|
}
|
|
1200
|
+
if (summary.reason || summary.error) {
|
|
1201
|
+
lines.push(
|
|
1202
|
+
` (could not check Composio integrations: ${summary.reason ?? summary.error})`,
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1099
1205
|
return lines.join("\n");
|
|
1100
1206
|
}
|
|
1101
1207
|
|
|
@@ -1242,7 +1348,7 @@ function redactForDisplay(value: unknown, key?: string): unknown {
|
|
|
1242
1348
|
// Help text
|
|
1243
1349
|
// ---------------------------------------------------------------------------
|
|
1244
1350
|
|
|
1245
|
-
function toolHelp() {
|
|
1351
|
+
export function toolHelp() {
|
|
1246
1352
|
console.log(`Dench tool commands
|
|
1247
1353
|
|
|
1248
1354
|
Usage:
|
|
@@ -1255,14 +1361,18 @@ Usage:
|
|
|
1255
1361
|
|
|
1256
1362
|
Notes:
|
|
1257
1363
|
All commands authenticate with DENCH_API_KEY or the active \`dench signin\`
|
|
1258
|
-
agent session.
|
|
1364
|
+
agent session. Composio commands use paid-workspace gateway credentials.
|
|
1365
|
+
Native Gmail/Outlook/Calendar/LinkedIn connect/status need no gateway key;
|
|
1366
|
+
connect requires a workspace member or a member-owned Dench API key.
|
|
1259
1367
|
Results carry a "source". "composio" rows are brokered by Composio; "unipile"
|
|
1260
1368
|
rows (gmail, outlook, calendar, linkedin) and "dench" rows (slack) are
|
|
1261
1369
|
connected by Dench itself. ALL of them run through \`dench tool run\` with the
|
|
1262
1370
|
same slug + --args contract. \`dench tool connect slack\` prints the in-house
|
|
1263
|
-
Slack install URL (org admin, one click)
|
|
1264
|
-
|
|
1265
|
-
|
|
1371
|
+
Slack install URL (org admin, one click). For gmail/outlook/calendar/linkedin,
|
|
1372
|
+
connect prints a Unipile hosted-auth link using the web app's configuration.
|
|
1373
|
+
Sign in as a workspace member and open the link to authorize the account.
|
|
1374
|
+
Calendar status accepts calendar, google-calendar, or outlook-calendar.
|
|
1375
|
+
Other toolkits connect through Composio; --callback-url applies only to them.
|
|
1266
1376
|
Slack is ALWAYS in-house: SLACK_* slugs (SLACK_SEND_MESSAGE with Block Kit
|
|
1267
1377
|
blocks/buttons, SLACK_FETCH_HISTORY, SLACK_LIST_CHANNELS, …) run through the
|
|
1268
1378
|
org's own Slack app install and can post to / read any channel.
|