@kosuke-ai/kosuke 1.0.65 → 1.0.67
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/CHANGELOG.md +8 -0
- package/README.md +11 -0
- package/dist/agent/http.js +0 -5
- package/dist/agent/summary.js +29 -52
- package/dist/commands/agent.js +1 -1
- package/dist/commands/hand-written.js +15 -0
- package/dist/commands/integrations-request.js +128 -0
- package/dist/commands/integrations-shared.js +45 -0
- package/dist/commands/integrations.js +12 -44
- package/dist/generated/commands/activity/list.js +1 -1
- package/dist/generated/commands/index.js +267 -265
- package/dist/generated/commands/integrations/tools-request.js +87 -0
- package/dist/generated/commands/sessions/list--all.js +3 -20
- package/dist/generated/commands/tasks/list--all.js +0 -7
- package/dist/generated/commands/tasks/list--personal.js +0 -7
- package/dist/generated/commands/tasks/list.js +0 -7
- package/dist/integrations/api.js +12 -1
- package/dist/integrations/render.js +15 -4
- package/openapi.json +135 -48
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.67
|
|
4
|
+
|
|
5
|
+
- Add `kosuke integrations request` to send one request to a Composio toolkit's own API through your connection, for an action no listed tool does; `integrations list --toolkit` says whether a toolkit takes them and its API base URL.
|
|
6
|
+
|
|
7
|
+
## 1.0.66
|
|
8
|
+
|
|
9
|
+
- Remove `--needs-you` and `--viewer` from `sessions list`, and the `needsYouReason` field from its rows: what waits on you is a Sensei card, which `kosuke sensei cards list` lists. An older CLI that still sends them gets the plain list. `agent summary get` no longer prints a Needs You section.
|
|
10
|
+
|
|
3
11
|
## 1.0.65
|
|
4
12
|
|
|
5
13
|
- `kosuke sessions list` takes `--include-merge-agent-runs` to list Merge agent run sessions, which it leaves out by default, and `kosuke sensei messages send` and `reply` describe that a project's Deploy agent can send a message and that a session's, the Merge agent's or a Cron's message gets the member's answer back.
|
package/README.md
CHANGED
|
@@ -203,6 +203,7 @@ kosuke integrations list --workspace <id> --toolkit gmail # that toolkit's to
|
|
|
203
203
|
kosuke integrations tools get <tool> --workspace <id> # one tool's input schema
|
|
204
204
|
kosuke integrations call <tool> --workspace <id> --account notion-personal --args '{"query":"roadmap"}'
|
|
205
205
|
kosuke integrations call youtube_upload_video --workspace <id> --args-file video.json --file videoFilePath=./clip.mp4
|
|
206
|
+
kosuke integrations request googlecalendar --workspace <id> --method GET --path /calendars/primary --purpose "read the calendar colors"
|
|
206
207
|
```
|
|
207
208
|
|
|
208
209
|
`list` with no filter prints each toolkit's connections (alias, scope, label,
|
|
@@ -217,6 +218,16 @@ reference: `--file <argument>=<path>` uploads the local file and fills it in,
|
|
|
217
218
|
once per file, and a file inside a list or object names its path, such as
|
|
218
219
|
`attachment.0`. The file goes straight to storage, up to 5 GiB.
|
|
219
220
|
|
|
221
|
+
`request` is for an action no listed tool does: it sends one GET, POST, PUT or
|
|
222
|
+
PATCH to a Composio toolkit's own API through your connection, and Composio adds
|
|
223
|
+
the credentials on the server. `--path` is relative to the API base URL that
|
|
224
|
+
`list --toolkit <slug>` prints, with `--query name=value` and `--body-file <json>`
|
|
225
|
+
beside it. `--purpose` is required: one line on what no listed tool does, with no
|
|
226
|
+
names, emails or event titles, stored with the usage row. It is refused before any
|
|
227
|
+
vendor call for Kosuke's own integrations, toolkits limited to their reviewed
|
|
228
|
+
tools, DELETE and a path that is not plainly relative. A write that gets no answer
|
|
229
|
+
exits 1 and is never sent again: its outcome is unknown.
|
|
230
|
+
|
|
220
231
|
With an API key, `--workspace` is required (you must belong to it), and `call`
|
|
221
232
|
runs only your own personal connections. Inside an agent's turn the credential
|
|
222
233
|
decides the workspace and the flag is optional. A Connector Token is refused.
|
package/dist/agent/http.js
CHANGED
package/dist/agent/summary.js
CHANGED
|
@@ -2,11 +2,11 @@ import { providers } from '../generated/providers.js';
|
|
|
2
2
|
import { readOverview } from '../integrations/api.js';
|
|
3
3
|
import { createApiClient } from '../runtime/client.js';
|
|
4
4
|
import { isTurnToken } from '../runtime/credentials.js';
|
|
5
|
-
import { HttpError,
|
|
5
|
+
import { HttpError, paginationTotal } from './http.js';
|
|
6
6
|
/**
|
|
7
|
-
* `kosuke agent summary`:
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* `kosuke agent summary`: which providers and integrations are connected and what is
|
|
8
|
+
* New, in a few dozen lines an agent reads at the start of a conversation. What waits
|
|
9
|
+
* on the member is a Sensei card, which `kosuke sensei cards list` reads. Kept to about 1,500 tokens: each list is capped and names the
|
|
10
10
|
* command that reads the rest, and it claims only as many events as the other
|
|
11
11
|
* lines leave room for.
|
|
12
12
|
*/
|
|
@@ -21,7 +21,6 @@ const PROVIDERS_TIMEOUT_MS = 4000;
|
|
|
21
21
|
* platform must cost the digest this section, never the digest.
|
|
22
22
|
*/
|
|
23
23
|
const INTEGRATIONS_TIMEOUT_MS = 3000;
|
|
24
|
-
const NEEDS_YOU_SHOWN = 5;
|
|
25
24
|
/** Connections listed before "and N more"; a member's own seven fit. */
|
|
26
25
|
const INTEGRATIONS_SHOWN = 8;
|
|
27
26
|
/** However much room is left: past this, the digest stops being a glance. */
|
|
@@ -35,18 +34,18 @@ const BUDGET_CHARS = 4500;
|
|
|
35
34
|
const ACTIVITY_FRAME_CHARS = 150;
|
|
36
35
|
// Caps on the words, never on the URL: a clipped URL opens nothing, and a
|
|
37
36
|
// preview origin alone can take most of a line.
|
|
38
|
-
const TITLE_MAX = 90;
|
|
39
37
|
const TEXT_MAX = 140;
|
|
40
38
|
const NAME_MAX = 40;
|
|
41
39
|
/** `/projects/<uuid>/chat-sessions?session=<uuid>`, or a Backlog ticket's path, which is longer. */
|
|
42
40
|
const SESSION_PATH_CHARS = 120;
|
|
43
41
|
/** Room for an origin longer than any the digest has seen, such as a preview's. */
|
|
44
42
|
const ORIGIN_CHARS_MIN = 64;
|
|
43
|
+
/**
|
|
44
|
+
* Reads the covered workspaces before the claim, so their line's length decides how many
|
|
45
|
+
* events fit. A peek of one: it marks nothing seen.
|
|
46
|
+
*/
|
|
45
47
|
// `satisfies`, so a query key the schema renames fails here, not at run time.
|
|
46
|
-
const
|
|
47
|
-
...NEEDS_YOU_FILTER,
|
|
48
|
-
limit: NEEDS_YOU_SHOWN,
|
|
49
|
-
};
|
|
48
|
+
const COVERAGE_QUERY = { unseen: true, limit: 1 };
|
|
50
49
|
const str = (value) => typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
51
50
|
function rows(body) {
|
|
52
51
|
const list = body?.data;
|
|
@@ -63,26 +62,19 @@ function clip(text, max) {
|
|
|
63
62
|
/**
|
|
64
63
|
* The longest an event line can be, so the digest claims only events it has
|
|
65
64
|
* room to print whole. Its session URL starts with the app's origin, which
|
|
66
|
-
* the digest knows only from the API's
|
|
65
|
+
* the digest knows only from the API's.
|
|
67
66
|
*/
|
|
68
|
-
function eventLineMax(apiUrl
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const url = Math.max(ORIGIN_CHARS_MIN, ...origins) + SESSION_PATH_CHARS;
|
|
67
|
+
function eventLineMax(apiUrl) {
|
|
68
|
+
let origin = 0;
|
|
69
|
+
try {
|
|
70
|
+
origin = new URL(apiUrl).origin.length;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// An unparsable API URL keeps the floor.
|
|
74
|
+
}
|
|
75
|
+
const url = Math.max(ORIGIN_CHARS_MIN, origin) + SESSION_PATH_CHARS;
|
|
78
76
|
return '- [/] '.length + 2 * NAME_MAX + TEXT_MAX + ', '.length + url;
|
|
79
77
|
}
|
|
80
|
-
/** `[workspace/project] title, reason, url`, one line per session. */
|
|
81
|
-
function sessionLine(row) {
|
|
82
|
-
const title = clip(str(row.title) ?? 'Untitled session', TITLE_MAX);
|
|
83
|
-
const reason = str(row.needsYouReason) ?? 'needs you';
|
|
84
|
-
return [`- ${where(row)} ${title}`, reason, str(row.url)].filter(Boolean).join(', ');
|
|
85
|
-
}
|
|
86
78
|
/** `[workspace/project] text: subject, url`, the same words Settings → Activity shows. */
|
|
87
79
|
function eventLine(event) {
|
|
88
80
|
const text = str(event.text) ?? str(event.kind) ?? 'Event';
|
|
@@ -290,8 +282,8 @@ function integrationLine(toolkit, connection) {
|
|
|
290
282
|
return `- ${clip(toolkit, NAME_MAX)}: ${connection.alias}, ${connection.scope}, "${label}", ${identity}`;
|
|
291
283
|
}
|
|
292
284
|
/** Never clipped: a workspace missing here would read as one the digest did not cover. */
|
|
293
|
-
function coverageLine(
|
|
294
|
-
const covered =
|
|
285
|
+
function coverageLine(read) {
|
|
286
|
+
const covered = read?.meta?.workspaces;
|
|
295
287
|
const names = Array.isArray(covered)
|
|
296
288
|
? covered.map((workspace) => str(workspace?.name)).filter((name) => name !== null)
|
|
297
289
|
: [];
|
|
@@ -299,32 +291,18 @@ function coverageLine(sessions) {
|
|
|
299
291
|
}
|
|
300
292
|
/** @internal */
|
|
301
293
|
export function planSummary(options) {
|
|
302
|
-
const {
|
|
294
|
+
const { covered, apiUrl, now, workspace, peek = false } = options;
|
|
303
295
|
const scope = workspace ? ` --workspace ${workspace}` : '';
|
|
304
296
|
const stamp = new Date(now).toISOString().slice(0, 16).replace('T', ' ') + ' UTC';
|
|
305
297
|
const head = [`Sensei summary, ${stamp}, ${apiUrl}`, ''];
|
|
306
|
-
const needing = rows(sessions);
|
|
307
|
-
const needTotal = paginationTotal(sessions) ?? needing.length;
|
|
308
|
-
if (needTotal === 0) {
|
|
309
|
-
head.push('No session needs you.');
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
head.push(`${needTotal} session${needTotal === 1 ? ' needs' : 's need'} you:`);
|
|
313
|
-
const shown = needing.slice(0, NEEDS_YOU_SHOWN);
|
|
314
|
-
head.push(...shown.map(sessionLine));
|
|
315
|
-
if (needTotal > shown.length) {
|
|
316
|
-
head.push(`(and ${needTotal - shown.length} more: kosuke sessions list --needs-you --owners me${scope})`);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
head.push('');
|
|
320
298
|
if (options.providers?.length)
|
|
321
299
|
head.push('Providers:', ...options.providers, '');
|
|
322
300
|
if (options.integrations?.length) {
|
|
323
301
|
head.push('Integrations (`kosuke integrations list` shows their tools):', ...options.integrations, '');
|
|
324
302
|
}
|
|
325
|
-
const coverage = coverageLine(
|
|
303
|
+
const coverage = coverageLine(covered);
|
|
326
304
|
const room = BUDGET_CHARS - head.join('\n').length - coverage.length - ACTIVITY_FRAME_CHARS - scope.length;
|
|
327
|
-
const lineMax = eventLineMax(apiUrl
|
|
305
|
+
const lineMax = eventLineMax(apiUrl);
|
|
328
306
|
const claim = Math.max(0, Math.min(EVENTS_SHOWN, Math.floor(room / (lineMax + 1))));
|
|
329
307
|
return {
|
|
330
308
|
head,
|
|
@@ -368,7 +346,7 @@ export function renderSummary(plan, activity) {
|
|
|
368
346
|
}
|
|
369
347
|
/**
|
|
370
348
|
* The whole digest, or one line saying why not, so the agent reading it
|
|
371
|
-
* knows to query the CLI itself.
|
|
349
|
+
* knows to query the CLI itself. The coverage, the providers and the integrations are read first:
|
|
372
350
|
* their lines decide how many events fit, and the Activity read marks events
|
|
373
351
|
* seen, so a digest that failed after it would lose them.
|
|
374
352
|
*/
|
|
@@ -383,17 +361,16 @@ export async function fetchSummary(options) {
|
|
|
383
361
|
const signal = AbortSignal.timeout(options.timeoutMs ?? SUMMARY_TIMEOUT_MS);
|
|
384
362
|
try {
|
|
385
363
|
const workspace = options.workspace ? { workspace: options.workspace } : {};
|
|
386
|
-
const [
|
|
387
|
-
client.GET('/api/
|
|
388
|
-
params: { query: { ...
|
|
364
|
+
const [coverage, providers, integrations] = await Promise.all([
|
|
365
|
+
client.GET('/api/activity', {
|
|
366
|
+
params: { query: { ...COVERAGE_QUERY, ...workspace } },
|
|
389
367
|
signal,
|
|
390
368
|
}),
|
|
391
369
|
fetchProviders(client, options.workspace, AbortSignal.any([signal, AbortSignal.timeout(PROVIDERS_TIMEOUT_MS)])),
|
|
392
370
|
fetchIntegrations(client, options.workspace, options.apiKey, AbortSignal.any([signal, AbortSignal.timeout(INTEGRATIONS_TIMEOUT_MS)])),
|
|
393
371
|
]);
|
|
394
|
-
const sessions = body(needsYou);
|
|
395
372
|
const plan = planSummary({
|
|
396
|
-
|
|
373
|
+
covered: body(coverage),
|
|
397
374
|
providers,
|
|
398
375
|
integrations,
|
|
399
376
|
apiUrl: options.apiUrl,
|
package/dist/commands/agent.js
CHANGED
|
@@ -5,7 +5,7 @@ export function attachAgentCommands(root, runtime, deps = {}) {
|
|
|
5
5
|
const { fetch, now, stdout = (line) => process.stdout.write(line + '\n') } = deps;
|
|
6
6
|
root.command('agent').description('What an agent reads about your Sensei account.');
|
|
7
7
|
leafAt(root, HAND_WRITTEN.agentSummaryGet.command)
|
|
8
|
-
.description('Print
|
|
8
|
+
.description('Print your connected providers and integrations and your oldest New Activity as a short digest for an agent to read. ' +
|
|
9
9
|
'Marks seen only the events it prints, and none with --peek; the rest stay New.')
|
|
10
10
|
.option('--workspace <id>', 'Only this workspace.')
|
|
11
11
|
.option('--peek', 'Print the events without marking them seen.')
|
|
@@ -74,6 +74,21 @@ export const HAND_WRITTEN = {
|
|
|
74
74
|
agents: 'all',
|
|
75
75
|
workspace: true,
|
|
76
76
|
},
|
|
77
|
+
integrationsRequest: {
|
|
78
|
+
command: ['integrations', 'request'],
|
|
79
|
+
positionals: ['toolkit'],
|
|
80
|
+
flags: [
|
|
81
|
+
'--method',
|
|
82
|
+
'--path',
|
|
83
|
+
'--purpose',
|
|
84
|
+
'--query',
|
|
85
|
+
'--body-file',
|
|
86
|
+
'--account',
|
|
87
|
+
'--workspace',
|
|
88
|
+
],
|
|
89
|
+
agents: 'all',
|
|
90
|
+
workspace: true,
|
|
91
|
+
},
|
|
77
92
|
sessionsJobsWatch: {
|
|
78
93
|
command: ['sessions', 'jobs', 'watch'],
|
|
79
94
|
positionals: ['projectId', 'sessionId', 'jobId'],
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { InvalidArgumentError } from 'commander';
|
|
2
|
+
import { leafAt } from '../runtime/attach.js';
|
|
3
|
+
import { failureOf, isRow, transportFailure, UNKNOWN_OUTCOME, } from '../integrations/api.js';
|
|
4
|
+
import { HAND_WRITTEN } from './hand-written.js';
|
|
5
|
+
import { accountText, CALL_TIMEOUT_MS, DELEGATED_RUN_HEADER, delegatedRunOf, toolkitSlug, UsageError, WORKSPACE_HELP, workspaceFor, } from './integrations-shared.js';
|
|
6
|
+
/**
|
|
7
|
+
* `kosuke integrations request`: one request to a Composio toolkit's own API, for an action no
|
|
8
|
+
* listed tool does. The platform judges the method and the path, so what it refuses still shows on
|
|
9
|
+
* Admin's Missing actions; only what it could not read stops here.
|
|
10
|
+
*/
|
|
11
|
+
const REQUESTS_PATH = '/api/agent-integrations/requests';
|
|
12
|
+
const MAX_PATH_CHARS = 2048;
|
|
13
|
+
const MAX_PURPOSE_CHARS = 120;
|
|
14
|
+
function methodWord(raw) {
|
|
15
|
+
if (raw === undefined)
|
|
16
|
+
throw new UsageError('--method is required: GET, POST, PUT or PATCH.');
|
|
17
|
+
if (!/^[A-Za-z]{1,16}$/.test(raw))
|
|
18
|
+
throw new UsageError('--method: GET, POST, PUT or PATCH.');
|
|
19
|
+
return raw.toUpperCase();
|
|
20
|
+
}
|
|
21
|
+
function pathText(raw) {
|
|
22
|
+
if (raw === undefined)
|
|
23
|
+
throw new UsageError('--path is required.');
|
|
24
|
+
if (raw === '' || raw.startsWith('--') || raw.length > MAX_PATH_CHARS) {
|
|
25
|
+
throw new UsageError(`--path: a path relative to the toolkit's API base URL, up to ${MAX_PATH_CHARS} characters.`);
|
|
26
|
+
}
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
function queryPair(raw, previous = []) {
|
|
30
|
+
const at = raw.indexOf('=');
|
|
31
|
+
if (at < 1)
|
|
32
|
+
throw new InvalidArgumentError('Expected name=value.');
|
|
33
|
+
return [...previous, [raw.slice(0, at), raw.slice(at + 1)]];
|
|
34
|
+
}
|
|
35
|
+
function purposeText(raw) {
|
|
36
|
+
if (raw === undefined) {
|
|
37
|
+
throw new UsageError('--purpose is required: one line on what the member wanted that no listed tool does.');
|
|
38
|
+
}
|
|
39
|
+
if (raw.trim() === '' || raw.startsWith('--') || raw.length > MAX_PURPOSE_CHARS) {
|
|
40
|
+
throw new UsageError(`--purpose: one line of 1 to ${MAX_PURPOSE_CHARS} characters.`);
|
|
41
|
+
}
|
|
42
|
+
return raw;
|
|
43
|
+
}
|
|
44
|
+
export function attachIntegrationsRequest(root, runtime, { guarded, fail, report, readStdin, readText, callTimeoutMs, env, }) {
|
|
45
|
+
leafAt(root, HAND_WRITTEN.integrationsRequest.command)
|
|
46
|
+
.description("Send one request straight to a Composio toolkit's own API through your connection, for an " +
|
|
47
|
+
'action no listed tool does, and print its answer. Composio adds the credentials on the ' +
|
|
48
|
+
'server, so no token is needed or shown. The connection it ran on is named on stderr. ' +
|
|
49
|
+
'A refusal or a vendor error exits 1.')
|
|
50
|
+
.argument('<toolkit>', 'The toolkit, as `list` prints it, such as googlecalendar.', toolkitSlug)
|
|
51
|
+
// Required, but checked in the action: commander's own refusal exits 1, not the usage exit 2.
|
|
52
|
+
.option('--method <method>', 'Required. GET, POST, PUT or PATCH. GET is a read.')
|
|
53
|
+
.option('--path <path>', "Required. Relative to the toolkit's API base URL, which `list --toolkit <slug>` prints. It " +
|
|
54
|
+
'starts with /, with no %, no .. and no empty segment.')
|
|
55
|
+
.option('--purpose <text>', 'Required. One line on what the member wanted that no listed tool does, with no names, emails ' +
|
|
56
|
+
'or event titles. It is stored with the usage row.')
|
|
57
|
+
.option('--query <name=value>', 'A query parameter. Repeat it for several.', queryPair)
|
|
58
|
+
.option('--body-file <path>', 'Read a JSON object to send as the body, or - for stdin.')
|
|
59
|
+
.option('--account <account>', 'The connection to run on: an alias, id or scope:label. Needed when you have several.', accountText)
|
|
60
|
+
.option('--workspace <id>', WORKSPACE_HELP)
|
|
61
|
+
.addHelpText('after', '\nUse a listed tool when one does the action: this is for what none does. POST, PUT and PATCH\n' +
|
|
62
|
+
'are writes and pass the same checks as a listed write tool. DELETE is refused, and so are\n' +
|
|
63
|
+
'toolkits limited to their reviewed tools; `list --toolkit <slug>` says which.\n' +
|
|
64
|
+
'\nWith an API key, a request runs only on your own personal connections.\n' +
|
|
65
|
+
`\nA request waits up to ${CALL_TIMEOUT_MS / 1000} s for its answer. A write that gets no answer is never sent\n` +
|
|
66
|
+
'again: its outcome is unknown, so read the current state first.\n' +
|
|
67
|
+
'\nExit codes:\n 0 the vendor answered with a success\n 1 refused, the vendor reported an error, or the outcome of a write is unknown\n 2 usage error: --method, --path, --purpose or --workspace missing or unusable, or a body that is not a JSON object')
|
|
68
|
+
.action(guarded(async (toolkit, flags) => {
|
|
69
|
+
const method = methodWord(flags.method);
|
|
70
|
+
const path = pathText(flags.path);
|
|
71
|
+
const purpose = purposeText(flags.purpose);
|
|
72
|
+
const body = flags.bodyFile === undefined ? undefined : await readBody(flags.bodyFile);
|
|
73
|
+
const client = runtime.client({ answerTimeoutMs: callTimeoutMs });
|
|
74
|
+
const workspace = workspaceFor(runtime, flags.workspace);
|
|
75
|
+
const delegatedRun = delegatedRunOf(env);
|
|
76
|
+
// A GET changes nothing, so a lost answer is plain; anything else may have landed.
|
|
77
|
+
const read = method === 'GET';
|
|
78
|
+
const verb = read ? 'GET' : 'POST';
|
|
79
|
+
let data;
|
|
80
|
+
try {
|
|
81
|
+
const result = await client.POST(REQUESTS_PATH, {
|
|
82
|
+
params: { query: workspace ? { workspace } : {} },
|
|
83
|
+
...(delegatedRun && { headers: { [DELEGATED_RUN_HEADER]: delegatedRun } }),
|
|
84
|
+
body: {
|
|
85
|
+
toolkit,
|
|
86
|
+
// Checked by the server, which records what it refuses.
|
|
87
|
+
method: method,
|
|
88
|
+
path,
|
|
89
|
+
purpose,
|
|
90
|
+
...(flags.query ? { query: flags.query } : {}),
|
|
91
|
+
...(body ? { body } : {}),
|
|
92
|
+
...(flags.account ? { account: flags.account } : {}),
|
|
93
|
+
},
|
|
94
|
+
signal: AbortSignal.timeout(callTimeoutMs),
|
|
95
|
+
});
|
|
96
|
+
if (!result.response.ok) {
|
|
97
|
+
if (!read && result.response.status >= 500)
|
|
98
|
+
return fail(UNKNOWN_OUTCOME);
|
|
99
|
+
return fail(failureOf(result.response.status, result.error, verb));
|
|
100
|
+
}
|
|
101
|
+
data = isRow(result.data) ? result.data.data : undefined;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return fail(transportFailure(error, verb));
|
|
105
|
+
}
|
|
106
|
+
report(`${toolkit} requests`, flags.account, data);
|
|
107
|
+
}));
|
|
108
|
+
/** Reads `--body-file`, or stdin for `-`: a JSON object, since that is all a body may be. */
|
|
109
|
+
async function readBody(path) {
|
|
110
|
+
let text;
|
|
111
|
+
try {
|
|
112
|
+
text = path === '-' ? await readStdin() : await readText(path);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw new UsageError(`Could not read the body file ${path}.`);
|
|
116
|
+
}
|
|
117
|
+
let parsed;
|
|
118
|
+
try {
|
|
119
|
+
parsed = JSON.parse(text);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
throw new UsageError('The body is not valid JSON.');
|
|
123
|
+
}
|
|
124
|
+
if (!isRow(parsed))
|
|
125
|
+
throw new UsageError('The body must be a JSON object.');
|
|
126
|
+
return parsed;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { InvalidArgumentError } from 'commander';
|
|
2
|
+
import { isTurnToken } from '../runtime/credentials.js';
|
|
3
|
+
/** What `kosuke integrations call` and `kosuke integrations request` share. */
|
|
4
|
+
/**
|
|
5
|
+
* One value for every call: the execute route's `maxDuration`, the longest the platform lets
|
|
6
|
+
* one run. The platform decides from the tool and the account where a call runs, so the CLI cannot
|
|
7
|
+
* give the others a shorter wait. They end sooner on the platform's side, a Composio read at its
|
|
8
|
+
* 60 s budget, and wait no longer than their answer takes.
|
|
9
|
+
*/
|
|
10
|
+
export const CALL_TIMEOUT_MS = 330_000;
|
|
11
|
+
const TOOLKIT_PATTERN = /^[a-z0-9_]{1,64}$/;
|
|
12
|
+
const MAX_ACCOUNT_CHARS = 100;
|
|
13
|
+
/** The header a call made by a Delegated Run carries, so the platform counts it as a delegate's. */
|
|
14
|
+
export const DELEGATED_RUN_HEADER = 'x-kosuke-delegated-run';
|
|
15
|
+
/** The Delegated Run this process runs in, set by the sandbox for a full-access run, or null. */
|
|
16
|
+
export function delegatedRunOf(env) {
|
|
17
|
+
const value = env.KOSUKE_DELEGATED_RUN_ID?.trim();
|
|
18
|
+
return value && /^[A-Za-z0-9_-]{1,64}$/.test(value) ? value : null;
|
|
19
|
+
}
|
|
20
|
+
/** Wrong flags or arguments, found before any request. */
|
|
21
|
+
export class UsageError extends Error {
|
|
22
|
+
}
|
|
23
|
+
export function toolkitSlug(raw) {
|
|
24
|
+
if (!TOOLKIT_PATTERN.test(raw)) {
|
|
25
|
+
throw new InvalidArgumentError('Expected a toolkit slug such as gmail, as `list` prints it.');
|
|
26
|
+
}
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
export function accountText(raw) {
|
|
30
|
+
// A flag swallowed as the value (`--account --args`) shows as a leading dash.
|
|
31
|
+
if (raw.trim() === '' || raw.startsWith('-') || raw.length > MAX_ACCOUNT_CHARS) {
|
|
32
|
+
throw new InvalidArgumentError(`Expected an alias, a connection id or scope:label, up to ${MAX_ACCOUNT_CHARS} characters.`);
|
|
33
|
+
}
|
|
34
|
+
return raw;
|
|
35
|
+
}
|
|
36
|
+
export const WORKSPACE_HELP = 'The workspace to use. Required with an API key, which is refused when you are not a member of it. ' +
|
|
37
|
+
'Inside an agent turn the credential decides, and this is optional.';
|
|
38
|
+
/** A turn's token decides its workspace; a member's API key has to name one. */
|
|
39
|
+
export function workspaceFor(runtime, given) {
|
|
40
|
+
if (given)
|
|
41
|
+
return given;
|
|
42
|
+
if (isTurnToken(runtime.credentials().apiKey))
|
|
43
|
+
return undefined;
|
|
44
|
+
throw new UsageError('--workspace <id> is required with an API key. `kosuke workspaces list` shows the ids.');
|
|
45
|
+
}
|
|
@@ -2,13 +2,14 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import { InvalidArgumentError } from 'commander';
|
|
3
3
|
import { leafAt } from '../runtime/attach.js';
|
|
4
4
|
import { HAND_WRITTEN } from './hand-written.js';
|
|
5
|
-
import {
|
|
5
|
+
import { attachIntegrationsRequest } from './integrations-request.js';
|
|
6
|
+
import { accountText, CALL_TIMEOUT_MS, DELEGATED_RUN_HEADER, delegatedRunOf, toolkitSlug, UsageError, WORKSPACE_HELP, workspaceFor, } from './integrations-shared.js';
|
|
6
7
|
import { jsonRequested } from '../runtime/runtime.js';
|
|
7
8
|
import { connectionOf, failureOf, isRow, oneLine, readOverview, rowsOf, TOOLS_PATH, transportFailure, } from '../integrations/api.js';
|
|
8
9
|
import { FILE_UPLOAD_PATH, fileSize, MAX_FILE_BYTES, md5Of, mimetypeOf, parseFileArgument, putFile, setAt, uploadName, } from '../integrations/file-upload.js';
|
|
9
10
|
import { choiceLines, renderOverview } from '../integrations/render.js';
|
|
10
11
|
/**
|
|
11
|
-
* `kosuke integrations list|call` and `kosuke integrations tools get`: the connected tools,
|
|
12
|
+
* `kosuke integrations list|call|request` and `kosuke integrations tools get`: the connected tools,
|
|
12
13
|
* listed and run from a laptop or an agent's shell. Hand-written because the output is text
|
|
13
14
|
* and the exit code says whether the tool worked, which the generated, hidden
|
|
14
15
|
* `integrations tools list` and `integrations tools call` (raw JSON passthroughs, kept
|
|
@@ -19,55 +20,23 @@ import { choiceLines, renderOverview } from '../integrations/render.js';
|
|
|
19
20
|
*/
|
|
20
21
|
const EXECUTE_PATH = '/api/agent-integrations/execute';
|
|
21
22
|
const READ_TIMEOUT_MS = 30_000;
|
|
22
|
-
/**
|
|
23
|
-
* One value for every call: the execute route's `maxDuration`, the longest the platform lets
|
|
24
|
-
* one run. The platform decides from the tool and the account where a call runs, so the CLI cannot
|
|
25
|
-
* give the others a shorter wait. They end sooner on the platform's side, a Composio read at its
|
|
26
|
-
* 60 s budget, and wait no longer than their answer takes.
|
|
27
|
-
*/
|
|
28
|
-
const CALL_TIMEOUT_MS = 330_000;
|
|
29
23
|
/** One file's PUT to storage; the storage URL lets an upload start for an hour. */
|
|
30
24
|
const UPLOAD_TIMEOUT_MS = 60 * 60_000;
|
|
31
25
|
const EXIT_FAILED = 1;
|
|
32
26
|
const EXIT_USAGE = 2;
|
|
33
|
-
const TOOLKIT_PATTERN = /^[a-z0-9_]{1,64}$/;
|
|
34
27
|
const MAX_SEARCH_CHARS = 100;
|
|
35
|
-
const MAX_ACCOUNT_CHARS = 100;
|
|
36
|
-
/** The header a call made by a Delegated Run carries, so the platform counts it as a delegate's. */
|
|
37
|
-
const DELEGATED_RUN_HEADER = 'x-kosuke-delegated-run';
|
|
38
|
-
/** The Delegated Run this process runs in, set by the sandbox for a full-access run, or null. */
|
|
39
|
-
function delegatedRunOf(env) {
|
|
40
|
-
const value = env.KOSUKE_DELEGATED_RUN_ID?.trim();
|
|
41
|
-
return value && /^[A-Za-z0-9_-]{1,64}$/.test(value) ? value : null;
|
|
42
|
-
}
|
|
43
|
-
/** Wrong flags or arguments, found before any request. */
|
|
44
|
-
class UsageError extends Error {
|
|
45
|
-
}
|
|
46
28
|
async function readAllStdin() {
|
|
47
29
|
const chunks = [];
|
|
48
30
|
for await (const chunk of process.stdin)
|
|
49
31
|
chunks.push(Buffer.from(chunk));
|
|
50
32
|
return Buffer.concat(chunks).toString('utf8');
|
|
51
33
|
}
|
|
52
|
-
function toolkitSlug(raw) {
|
|
53
|
-
if (!TOOLKIT_PATTERN.test(raw)) {
|
|
54
|
-
throw new InvalidArgumentError('Expected a toolkit slug such as gmail, as `list` prints it.');
|
|
55
|
-
}
|
|
56
|
-
return raw;
|
|
57
|
-
}
|
|
58
34
|
function searchText(raw) {
|
|
59
35
|
if (raw.trim() === '' || raw.length > MAX_SEARCH_CHARS) {
|
|
60
36
|
throw new InvalidArgumentError(`Expected 1 to ${MAX_SEARCH_CHARS} characters.`);
|
|
61
37
|
}
|
|
62
38
|
return raw;
|
|
63
39
|
}
|
|
64
|
-
function accountText(raw) {
|
|
65
|
-
// A flag swallowed as the value (`--account --args`) shows as a leading dash.
|
|
66
|
-
if (raw.trim() === '' || raw.startsWith('-') || raw.length > MAX_ACCOUNT_CHARS) {
|
|
67
|
-
throw new InvalidArgumentError(`Expected an alias, a connection id or scope:label, up to ${MAX_ACCOUNT_CHARS} characters.`);
|
|
68
|
-
}
|
|
69
|
-
return raw;
|
|
70
|
-
}
|
|
71
40
|
function fileArguments(raw, previous = []) {
|
|
72
41
|
const parsed = parseFileArgument(raw);
|
|
73
42
|
if (!parsed) {
|
|
@@ -81,16 +50,6 @@ function limitNumber(raw) {
|
|
|
81
50
|
}
|
|
82
51
|
return Number(raw);
|
|
83
52
|
}
|
|
84
|
-
const WORKSPACE_HELP = 'The workspace to use. Required with an API key, which is refused when you are not a member of it. ' +
|
|
85
|
-
'Inside an agent turn the credential decides, and this is optional.';
|
|
86
|
-
/** A turn's token decides its workspace; a member's API key has to name one. */
|
|
87
|
-
function workspaceFor(runtime, given) {
|
|
88
|
-
if (given)
|
|
89
|
-
return given;
|
|
90
|
-
if (isTurnToken(runtime.credentials().apiKey))
|
|
91
|
-
return undefined;
|
|
92
|
-
throw new UsageError('--workspace <id> is required with an API key. `kosuke workspaces list` shows the ids.');
|
|
93
|
-
}
|
|
94
53
|
/** The 409 that asks for `--account`: its choices, one per line. */
|
|
95
54
|
function accountChoiceText(error, tool, given) {
|
|
96
55
|
if (!isRow(error))
|
|
@@ -302,6 +261,15 @@ export function attachIntegrationsCommands(root, runtime, deps = {}) {
|
|
|
302
261
|
}
|
|
303
262
|
report(name, flags.account, data);
|
|
304
263
|
}));
|
|
264
|
+
attachIntegrationsRequest(root, runtime, {
|
|
265
|
+
guarded,
|
|
266
|
+
fail,
|
|
267
|
+
report,
|
|
268
|
+
readStdin,
|
|
269
|
+
readText,
|
|
270
|
+
callTimeoutMs,
|
|
271
|
+
env,
|
|
272
|
+
});
|
|
305
273
|
/**
|
|
306
274
|
* Reserves one file's upload, sends the file to storage and answers its reference, or reports
|
|
307
275
|
* the failure and answers null. Nothing is called yet, so a failure here changes nothing.
|
|
@@ -48,7 +48,7 @@ export const operation = {
|
|
|
48
48
|
"flag": "kind",
|
|
49
49
|
"kind": "string",
|
|
50
50
|
"required": false,
|
|
51
|
-
"description": "Comma-separated kinds (job_awaiting_response, pr_checks_failed, pr_checks_passed, main_checks_failed, main_checks_passed, pr_merged, branch_behind,
|
|
51
|
+
"description": "Comma-separated kinds (job_awaiting_response, pr_checks_failed, pr_checks_passed, main_checks_failed, main_checks_passed, pr_merged, branch_behind, cron_run_succeeded, cron_run_failed, deployed, recovery_deploy_started, workspace_device_disconnected, session_started, session_message_sent, session_archived, session_deleted, session_assigned, session_status_changed, session_priority_changed, cron_created, cron_updated, cron_deleted, member_invited, member_removed, member_role_changed, integration_custom_tool_saved, integration_custom_tool_enabled, integration_custom_tool_disabled, integration_custom_tool_deleted, integration_custom_tool_restored), or 'change' for every Change and 'action' for every Member Action."
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
"name": "limit",
|