@kortix/sdk 0.14.15 → 0.14.17
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 +19 -5
- package/dist/core/client/kortix.d.ts.map +1 -1
- package/dist/core/client/project-core.d.ts.map +1 -1
- package/dist/core/rest/projects-client/artifacts.d.ts +7 -1
- package/dist/core/rest/projects-client/artifacts.d.ts.map +1 -1
- package/dist/core/rest/projects-client/artifacts.js.map +1 -1
- package/dist/core/rest/projects-client/drives.d.ts +23 -0
- package/dist/core/rest/projects-client/drives.d.ts.map +1 -1
- package/dist/core/rest/projects-client/drives.js +11 -0
- package/dist/core/rest/projects-client/drives.js.map +1 -1
- package/dist/core/rest/projects-client/index.d.ts +1 -0
- package/dist/core/rest/projects-client/index.d.ts.map +1 -1
- package/dist/core/rest/projects-client/index.js +1 -0
- package/dist/core/rest/projects-client/index.js.map +1 -1
- package/dist/core/rest/projects-client/project-search.d.ts +39 -0
- package/dist/core/rest/projects-client/project-search.d.ts.map +1 -0
- package/dist/core/rest/projects-client/project-search.js +26 -0
- package/dist/core/rest/projects-client/project-search.js.map +1 -0
- package/dist/core/rest/projects-client/projects.d.ts +11 -5
- package/dist/core/rest/projects-client/projects.d.ts.map +1 -1
- package/dist/core/rest/projects-client/projects.js +0 -3
- package/dist/core/rest/projects-client/projects.js.map +1 -1
- package/dist/core/rest/projects-client/session-sandbox.d.ts +30 -0
- package/dist/core/rest/projects-client/session-sandbox.d.ts.map +1 -1
- package/dist/core/rest/projects-client/session-sandbox.js.map +1 -1
- package/dist/core/turns/classify.d.ts +6 -0
- package/dist/core/turns/classify.d.ts.map +1 -1
- package/dist/core/turns/classify.js +1 -0
- package/dist/core/turns/classify.js.map +1 -1
- package/dist/core/turns/index.d.ts +6 -0
- package/dist/core/turns/index.d.ts.map +1 -1
- package/dist/core/turns/index.js +3 -0
- package/dist/core/turns/index.js.map +1 -1
- package/dist/core/turns/peer-message-prompt.d.ts +35 -0
- package/dist/core/turns/peer-message-prompt.d.ts.map +1 -0
- package/dist/core/turns/peer-message-prompt.js +27 -0
- package/dist/core/turns/peer-message-prompt.js.map +1 -0
- package/dist/core/turns/session-report.d.ts +12 -0
- package/dist/core/turns/session-report.d.ts.map +1 -0
- package/dist/core/turns/session-report.js +101 -0
- package/dist/core/turns/session-report.js.map +1 -0
- package/dist/core/turns/subagent-notice.d.ts +53 -0
- package/dist/core/turns/subagent-notice.d.ts.map +1 -0
- package/dist/core/turns/subagent-notice.js +127 -0
- package/dist/core/turns/subagent-notice.js.map +1 -0
- package/dist/core/turns/tools/index.d.ts +4 -1
- package/dist/core/turns/tools/index.d.ts.map +1 -1
- package/dist/core/turns/tools/index.js +4 -1
- package/dist/core/turns/tools/index.js.map +1 -1
- package/dist/core/turns/tools/kortix-tool-card.d.ts +84 -0
- package/dist/core/turns/tools/kortix-tool-card.d.ts.map +1 -0
- package/dist/core/turns/tools/kortix-tool-card.js +187 -0
- package/dist/core/turns/tools/kortix-tool-card.js.map +1 -0
- package/dist/core/turns/tools/workflow-run.d.ts +109 -0
- package/dist/core/turns/tools/workflow-run.d.ts.map +1 -0
- package/dist/core/turns/tools/workflow-run.js +243 -0
- package/dist/core/turns/tools/workflow-run.js.map +1 -0
- package/dist/core/turns/view-model.d.ts +13 -0
- package/dist/core/turns/view-model.d.ts.map +1 -1
- package/dist/core/turns/view-model.js +16 -1
- package/dist/core/turns/view-model.js.map +1 -1
- package/dist/kortix.esm.min.js +52 -42
- package/dist/kortix.global.js +52 -42
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/query-keys.d.ts +3 -0
- package/dist/react/query-keys.d.ts.map +1 -1
- package/dist/react/query-keys.js +2 -0
- package/dist/react/query-keys.js.map +1 -1
- package/dist/react/use-artifacts.d.ts +123 -77
- package/dist/react/use-artifacts.d.ts.map +1 -1
- package/dist/react/use-artifacts.js +263 -6
- package/dist/react/use-artifacts.js.map +1 -1
- package/dist/react/use-project-files.d.ts +9 -1
- package/dist/react/use-project-files.d.ts.map +1 -1
- package/dist/react/use-project-files.js +13 -1
- package/dist/react/use-project-files.js.map +1 -1
- package/dist/react/use-project-search.d.ts +15 -0
- package/dist/react/use-project-search.d.ts.map +1 -0
- package/dist/react/use-project-search.js +24 -0
- package/dist/react/use-project-search.js.map +1 -0
- package/dist/react/use-session-log.d.ts.map +1 -1
- package/dist/react/use-session-log.js +14 -1
- package/dist/react/use-session-log.js.map +1 -1
- package/dist/react/use-session.d.ts +8 -1
- package/dist/react/use-session.d.ts.map +1 -1
- package/dist/react/use-session.js +16 -0
- package/dist/react/use-session.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type PeerMessagePromptInfo } from './peer-message-prompt.js';
|
|
2
|
+
/**
|
|
3
|
+
* The notices the API delivers into a session as a prompt, written by
|
|
4
|
+
* `subagentNoticeText` in `apps/api/src/projects/subagent-notice.ts`. A host
|
|
5
|
+
* draws each as a one-line row instead of a turn the person typed:
|
|
6
|
+
*
|
|
7
|
+
* A background subagent you started has finished. This message is from the platform, not from the user.
|
|
8
|
+
* (or) Your teammate <handle> finished its turn and is idle. This message is from the platform, not from the user.
|
|
9
|
+
* task_id: <child session id>
|
|
10
|
+
* status: completed | error | failed | stopped
|
|
11
|
+
*
|
|
12
|
+
* <kortix_system type="session-report" source="subagent"><session-report>…</session-report></kortix_system>
|
|
13
|
+
*
|
|
14
|
+
* Tasks <handle> still owns: #3 subject (in progress); … . (a teammate only)
|
|
15
|
+
* …
|
|
16
|
+
*
|
|
17
|
+
* `apps/api/src/projects/session-notice-batch.ts` coalesces the notices that
|
|
18
|
+
* arrive together into one prompt, joined by a blank line (at most 20): these,
|
|
19
|
+
* and the idle notice a `send_message({ notify_when_idle })` asked for
|
|
20
|
+
* (`peerMessagePromptText` kind `idle_notice`).
|
|
21
|
+
*/
|
|
22
|
+
export interface SubagentNotice {
|
|
23
|
+
/** `teammate`: a teammate of an agent team went idle; `subagent`: a background subagent ended. */
|
|
24
|
+
kind: 'subagent' | 'teammate';
|
|
25
|
+
sessionId: string;
|
|
26
|
+
status: 'completed' | 'failed' | 'stopped';
|
|
27
|
+
/** A teammate's handle, from its lead line; null for a subagent. */
|
|
28
|
+
handle: string | null;
|
|
29
|
+
/** The project agent the child ran as, or null. */
|
|
30
|
+
agent: string | null;
|
|
31
|
+
/** The child's title, without the "(@agent subagent)" suffix, or null. */
|
|
32
|
+
title: string | null;
|
|
33
|
+
/** The child's final report (Markdown), or its error. */
|
|
34
|
+
result: string;
|
|
35
|
+
/** The first line of `result` that holds words. */
|
|
36
|
+
excerpt: string;
|
|
37
|
+
/** A teammate's unfinished tasks ("#3 Write the fix (in progress); #4 …"), or null when it owns none. */
|
|
38
|
+
ownedTasks: string | null;
|
|
39
|
+
}
|
|
40
|
+
/** One notice of a delivered notice prompt. */
|
|
41
|
+
export type NoticeBatchItem = {
|
|
42
|
+
kind: 'subagent' | 'teammate';
|
|
43
|
+
notice: SubagentNotice;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'peer_idle';
|
|
46
|
+
info: PeerMessagePromptInfo;
|
|
47
|
+
};
|
|
48
|
+
/** The first line with words, without Markdown heading, list and emphasis marks. */
|
|
49
|
+
export declare function noticeFirstLine(text: string): string;
|
|
50
|
+
/** The background subagent or teammate notice a text carries (one notice, not a batch), or null. */
|
|
51
|
+
export declare function parseSubagentNotice(text: string | null | undefined): SubagentNotice | null;
|
|
52
|
+
export declare function parseNoticeBatch(text: string | null | undefined): NoticeBatchItem[] | null;
|
|
53
|
+
//# sourceMappingURL=subagent-notice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-notice.d.ts","sourceRoot":"","sources":["../../../src/core/turns/subagent-notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI3F;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,cAAc;IAC7B,kGAAkG;IAClG,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC3C,oEAAoE;IACpE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,mDAAmD;IACnD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,0EAA0E;IAC1E,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,yGAAyG;IACzG,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAavD,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASpD;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc,GAAG,IAAI,CAoC1F;AAiCD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,EAAE,GAAG,IAAI,CA4B1F"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { parsePeerMessagePrompt } from './peer-message-prompt.js';
|
|
2
|
+
import { extractSessionReport } from './session-report.js';
|
|
3
|
+
import { textBetween } from './text-scan.js';
|
|
4
|
+
const SUBAGENT_LEAD = 'A background subagent you started has finished.';
|
|
5
|
+
const TEAMMATE_LEAD = /^Your teammate (\S+) finished its turn and is idle\./;
|
|
6
|
+
const PEER_IDLE_HEAD = '[idle notice from ';
|
|
7
|
+
const STATUSES = new Set(['completed', 'failed', 'stopped']);
|
|
8
|
+
/** `session-notice-batch.ts` `NOTICE_BATCH_MAX`; a longer prompt is not a batch it wrote. */
|
|
9
|
+
const MAX_NOTICES = 20;
|
|
10
|
+
function block(text, tag) {
|
|
11
|
+
return textBetween(text, `<${tag}>`, `</${tag}>`)?.trim() ?? null;
|
|
12
|
+
}
|
|
13
|
+
/** The first line with words, without Markdown heading, list and emphasis marks. */
|
|
14
|
+
export function noticeFirstLine(text) {
|
|
15
|
+
for (const raw of text.split('\n')) {
|
|
16
|
+
const line = raw
|
|
17
|
+
.replace(/^\s*(?:#{1,6}\s+|[-*+]\s+|>\s*|\d+\.\s+)/, '')
|
|
18
|
+
.replace(/[*_`]+/g, '')
|
|
19
|
+
.trim();
|
|
20
|
+
if (line)
|
|
21
|
+
return line;
|
|
22
|
+
}
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
/** The background subagent or teammate notice a text carries (one notice, not a batch), or null. */
|
|
26
|
+
export function parseSubagentNotice(text) {
|
|
27
|
+
if (!text)
|
|
28
|
+
return null;
|
|
29
|
+
const body = text.trimStart();
|
|
30
|
+
const teammate = TEAMMATE_LEAD.exec(body);
|
|
31
|
+
if (!teammate && !body.startsWith(SUBAGENT_LEAD))
|
|
32
|
+
return null;
|
|
33
|
+
const report = extractSessionReport(body);
|
|
34
|
+
const head = body.slice(0, 600);
|
|
35
|
+
const sessionId = /^task_id:\s*(\S+)/m.exec(head)?.[1] ?? report?.sessionId ?? '';
|
|
36
|
+
if (!sessionId)
|
|
37
|
+
return null;
|
|
38
|
+
const stated = /^status:\s*(\w+)/m.exec(head)?.[1];
|
|
39
|
+
// The API writes `error` for a turn that ended on an error; it reads as a failure.
|
|
40
|
+
const normalized = stated === 'error' ? 'failed' : stated;
|
|
41
|
+
const status = normalized && STATUSES.has(normalized)
|
|
42
|
+
? normalized
|
|
43
|
+
: report?.status === 'FAILED'
|
|
44
|
+
? 'failed'
|
|
45
|
+
: 'completed';
|
|
46
|
+
const resultXml = report?.result ?? '';
|
|
47
|
+
const answer = block(resultXml, 'task_result');
|
|
48
|
+
const error = block(resultXml, 'task_error');
|
|
49
|
+
const result = (status === 'completed' ? answer : (error ?? answer)) ?? resultXml;
|
|
50
|
+
const title = report?.prompt?.replace(/\s*\(@[^)]*\bsubagent\)\s*$/i, '').trim() || null;
|
|
51
|
+
const handle = teammate?.[1] ?? null;
|
|
52
|
+
const owned = handle ? /^Tasks \S+ still owns: (.+?)\.?$/m.exec(body)?.[1]?.trim() : undefined;
|
|
53
|
+
return {
|
|
54
|
+
kind: teammate ? 'teammate' : 'subagent',
|
|
55
|
+
sessionId,
|
|
56
|
+
status,
|
|
57
|
+
handle,
|
|
58
|
+
agent: report?.project?.trim() || null,
|
|
59
|
+
title,
|
|
60
|
+
result,
|
|
61
|
+
excerpt: noticeFirstLine(result),
|
|
62
|
+
ownedTasks: owned || null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** True when a notice of any kind starts at `index` of `text`. */
|
|
66
|
+
function startsNotice(text, index) {
|
|
67
|
+
return (text.startsWith(SUBAGENT_LEAD, index) ||
|
|
68
|
+
text.startsWith(PEER_IDLE_HEAD, index) ||
|
|
69
|
+
(text.startsWith('Your teammate ', index) && TEAMMATE_LEAD.test(text.slice(index, index + 300))));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The notices a delivered prompt carries, in order, or null when the prompt is
|
|
73
|
+
* anything else. A notice starts at the start of the prompt or right after the
|
|
74
|
+
* blank line that joins two notices, so a notice line quoted inside a report
|
|
75
|
+
* never splits one. Every piece must parse: one that does not makes the whole
|
|
76
|
+
* prompt "not a batch", and it renders as the turn it is.
|
|
77
|
+
*/
|
|
78
|
+
/** The blocks a notice quotes verbatim from its child: a lead inside one starts nothing. */
|
|
79
|
+
const QUOTE_TAGS = ['kortix_system', 'task_result', 'task_error'];
|
|
80
|
+
function count(text, needle) {
|
|
81
|
+
let n = 0;
|
|
82
|
+
for (let at = text.indexOf(needle); at !== -1; at = text.indexOf(needle, at + needle.length))
|
|
83
|
+
n += 1;
|
|
84
|
+
return n;
|
|
85
|
+
}
|
|
86
|
+
/** `index` lies inside an open `<kortix_system>`, `<task_result>` or `<task_error>` block. */
|
|
87
|
+
function insideQuote(body, index) {
|
|
88
|
+
const before = body.slice(0, index);
|
|
89
|
+
return QUOTE_TAGS.some((tag) => count(before, `<${tag}`) > count(before, `</${tag}>`));
|
|
90
|
+
}
|
|
91
|
+
export function parseNoticeBatch(text) {
|
|
92
|
+
if (!text)
|
|
93
|
+
return null;
|
|
94
|
+
const body = text.trim();
|
|
95
|
+
if (!startsNotice(body, 0))
|
|
96
|
+
return null;
|
|
97
|
+
const starts = [0];
|
|
98
|
+
for (let at = body.indexOf('\n\n'); at !== -1; at = body.indexOf('\n\n', at + 2)) {
|
|
99
|
+
// Several blank lines in a row: the notice starts at the first non-newline.
|
|
100
|
+
let index = at + 2;
|
|
101
|
+
while (body[index] === '\n')
|
|
102
|
+
index += 1;
|
|
103
|
+
// A lead inside a quoted report is the report's words, not a new notice: a child's
|
|
104
|
+
// report could otherwise forge a row (and the session id a click opens).
|
|
105
|
+
if (index > starts[starts.length - 1] && startsNotice(body, index) && !insideQuote(body, index))
|
|
106
|
+
starts.push(index);
|
|
107
|
+
if (starts.length > MAX_NOTICES)
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const items = [];
|
|
111
|
+
for (const [i, start] of starts.entries()) {
|
|
112
|
+
const piece = body.slice(start, starts[i + 1] ?? body.length).trim();
|
|
113
|
+
if (piece.startsWith(PEER_IDLE_HEAD)) {
|
|
114
|
+
const info = parsePeerMessagePrompt(piece);
|
|
115
|
+
if (!info || info.kind !== 'idle_notice')
|
|
116
|
+
return null;
|
|
117
|
+
items.push({ kind: 'peer_idle', info });
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const notice = parseSubagentNotice(piece);
|
|
121
|
+
if (!notice)
|
|
122
|
+
return null;
|
|
123
|
+
items.push({ kind: notice.kind, notice });
|
|
124
|
+
}
|
|
125
|
+
return items;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=subagent-notice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-notice.js","sourceRoot":"","sources":["../../../src/core/turns/subagent-notice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAA8B,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA8C1C,MAAM,aAAa,GAAG,iDAAiD,CAAC;AACxE,MAAM,aAAa,GAAG,sDAAsD,CAAC;AAC7E,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAC7D,6FAA6F;AAC7F,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,SAAS,KAAK,CAAC,IAAY,EAAE,GAAW;IACtC,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC;AACpE,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,GAAG;aACb,OAAO,CAAC,0CAA0C,EAAE,EAAE,CAAC;aACvD,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;aACtB,IAAI,EAAE,CAAC;QACV,IAAI,IAAI;YAAE,OAAO,IAAI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,CAAC;IAC5C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* and what its output says. Primary-arg extraction, file verbs, search-query
|
|
4
4
|
* humanizing, patch verbs, success/partial/failed outcomes, and parsers for
|
|
5
5
|
* web search, scrape, skill, memory, read, question, presentation and worker
|
|
6
|
-
* output,
|
|
6
|
+
* output, the `image_gen` card's state, the platform tools' `KortixToolResult`
|
|
7
|
+
* card, and the `workflow` run document. Pure data → data, no framework.
|
|
7
8
|
*/
|
|
8
9
|
export * from './agent-helpers.js';
|
|
9
10
|
export * from './file-verb.js';
|
|
10
11
|
export * from './image-gen-view.js';
|
|
12
|
+
export * from './kortix-tool-card.js';
|
|
11
13
|
export * from './memory-helpers.js';
|
|
12
14
|
export * from './patch-summary.js';
|
|
13
15
|
export * from './presentation-helpers.js';
|
|
@@ -20,4 +22,5 @@ export * from './tool-meta.js';
|
|
|
20
22
|
export * from './tool-outcome.js';
|
|
21
23
|
export * from './tool-output-format.js';
|
|
22
24
|
export * from './web-helpers.js';
|
|
25
|
+
export * from './workflow-run.js';
|
|
23
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/tools/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* and what its output says. Primary-arg extraction, file verbs, search-query
|
|
4
4
|
* humanizing, patch verbs, success/partial/failed outcomes, and parsers for
|
|
5
5
|
* web search, scrape, skill, memory, read, question, presentation and worker
|
|
6
|
-
* output,
|
|
6
|
+
* output, the `image_gen` card's state, the platform tools' `KortixToolResult`
|
|
7
|
+
* card, and the `workflow` run document. Pure data → data, no framework.
|
|
7
8
|
*/
|
|
8
9
|
export * from './agent-helpers.js';
|
|
9
10
|
export * from './file-verb.js';
|
|
10
11
|
export * from './image-gen-view.js';
|
|
12
|
+
export * from './kortix-tool-card.js';
|
|
11
13
|
export * from './memory-helpers.js';
|
|
12
14
|
export * from './patch-summary.js';
|
|
13
15
|
export * from './presentation-helpers.js';
|
|
@@ -20,4 +22,5 @@ export * from './tool-meta.js';
|
|
|
20
22
|
export * from './tool-outcome.js';
|
|
21
23
|
export * from './tool-output-format.js';
|
|
22
24
|
export * from './web-helpers.js';
|
|
25
|
+
export * from './workflow-run.js';
|
|
23
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/turns/tools/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/turns/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The My Kortix platform tools' result, parsed defensively.
|
|
3
|
+
*
|
|
4
|
+
* The shape is `KortixToolResult` in `packages/api-contract/src/kortix-tool-card.ts`.
|
|
5
|
+
* The SDK does not depend on that package, so the types are mirrored here and
|
|
6
|
+
* every field is checked. A result that does not parse is `null`, and a host
|
|
7
|
+
* renders the call as its generic tool card instead of a half-drawn one.
|
|
8
|
+
*/
|
|
9
|
+
/** `KORTIX_PLATFORM_TOOL_NAMES` in `packages/api-contract/src/kortix-tool-card.ts`. */
|
|
10
|
+
export declare const KORTIX_PLATFORM_TOOLS: readonly ["kortix_agents", "kortix_sessions", "kortix_schedules", "kortix_connectors", "kortix_people", "kortix_access", "kortix_usage", "kortix_change_requests", "kortix_memory"];
|
|
11
|
+
export type KortixPlatformTool = (typeof KORTIX_PLATFORM_TOOLS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* The multi-agent tools (`packages/api-contract/src/multi-agent.ts`): the same
|
|
14
|
+
* `KortixToolResult`, with `data` = the contract object the card body draws.
|
|
15
|
+
* `task_create`, `task_list`, `task_get` and `task_update` are also the names of
|
|
16
|
+
* older plugin tools: a host tells the two apart by the output (`isTeamTaskCall` in `@kortix/ui`).
|
|
17
|
+
*/
|
|
18
|
+
export declare const MULTI_AGENT_TOOLS: readonly ["send_message", "list_agents", "task_create", "task_list", "task_get", "task_update", "task_stop"];
|
|
19
|
+
export type MultiAgentTool = (typeof MULTI_AGENT_TOOLS)[number];
|
|
20
|
+
/** Every tool whose result is a `KortixToolResult` card. */
|
|
21
|
+
export type KortixCardTool = KortixPlatformTool | MultiAgentTool;
|
|
22
|
+
export type KortixCardStatus = 'done' | 'running' | 'needs_you' | 'denied' | 'error';
|
|
23
|
+
export interface KortixCardRow {
|
|
24
|
+
title: string;
|
|
25
|
+
detail?: string;
|
|
26
|
+
badge?: string;
|
|
27
|
+
/** In-app path (`/projects/…`). A row never links outside the app. */
|
|
28
|
+
href?: string;
|
|
29
|
+
}
|
|
30
|
+
/** A `before` of `null` is a new setting; an `after` of `null` is a removed one. */
|
|
31
|
+
export interface KortixCardChange {
|
|
32
|
+
field: string;
|
|
33
|
+
before: string | null;
|
|
34
|
+
after: string | null;
|
|
35
|
+
}
|
|
36
|
+
export interface KortixCardLink {
|
|
37
|
+
label: string;
|
|
38
|
+
/** An in-app path, or an absolute `https://` URL (a connector sign-in link). */
|
|
39
|
+
href: string;
|
|
40
|
+
/** True for an absolute `https://` URL: it opens in a new tab and is the card's primary action. */
|
|
41
|
+
external: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface KortixToolCard {
|
|
44
|
+
title: string;
|
|
45
|
+
subtitle?: string;
|
|
46
|
+
status: KortixCardStatus;
|
|
47
|
+
rows: KortixCardRow[];
|
|
48
|
+
changes: KortixCardChange[];
|
|
49
|
+
links: KortixCardLink[];
|
|
50
|
+
}
|
|
51
|
+
export interface KortixGrantor {
|
|
52
|
+
name: string;
|
|
53
|
+
role: string;
|
|
54
|
+
}
|
|
55
|
+
export interface KortixToolError {
|
|
56
|
+
kind: 'denied' | 'not_found' | 'invalid' | 'failed';
|
|
57
|
+
message: string;
|
|
58
|
+
grantors: KortixGrantor[];
|
|
59
|
+
}
|
|
60
|
+
export interface KortixToolResult {
|
|
61
|
+
ok: boolean;
|
|
62
|
+
tool: KortixCardTool;
|
|
63
|
+
action: string;
|
|
64
|
+
card: KortixToolCard;
|
|
65
|
+
error?: KortixToolError;
|
|
66
|
+
/** What the model reads. Only the multi-agent card bodies draw it, each through its own defensive parser. */
|
|
67
|
+
data?: unknown;
|
|
68
|
+
}
|
|
69
|
+
/** The platform tool a call name names: `kortix_agents`, also as `kortix-agents` or `oc-kortix_agents`. */
|
|
70
|
+
export declare function kortixPlatformTool(name: string): KortixPlatformTool | undefined;
|
|
71
|
+
/** A multi-agent tool a call name names: `send_message`, also as `send-message` or `oc-send_message`. */
|
|
72
|
+
export declare function multiAgentTool(name: string): MultiAgentTool | undefined;
|
|
73
|
+
/** Any tool that answers with a `KortixToolResult` card. */
|
|
74
|
+
export declare function kortixCardTool(name: string): KortixCardTool | undefined;
|
|
75
|
+
/** An in-app path: one leading `/`, never `//` (a protocol-relative URL leaves the app). */
|
|
76
|
+
export declare function inAppHref(value: unknown): string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* The result in a platform call's output (or its error text, when the call threw
|
|
79
|
+
* it): one JSON object. `null` when the text is not that object. `callName` names
|
|
80
|
+
* the tool when the result leaves `tool` out.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseKortixToolResult(raw: string | undefined, callName?: string): KortixToolResult | null;
|
|
83
|
+
export declare function isReadAction(action: unknown): boolean;
|
|
84
|
+
//# sourceMappingURL=kortix-tool-card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kortix-tool-card.d.ts","sourceRoot":"","sources":["../../../../src/core/turns/tools/kortix-tool-card.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uFAAuF;AACvF,eAAO,MAAM,qBAAqB,qLAUxB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,8GAQpB,CAAC;AACX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG,c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AC;IACrB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,6GAA6G;IAC7G,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAcD,2GAA2G;AAC3G,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAK/E;AAED,yGAAyG;AACzG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAGvE;AAED,4DAA4D;AAC5D,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAEvE;AAED,4FAA4F;AAC5F,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG5D;AAqED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAuCzG;AAKD,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The My Kortix platform tools' result, parsed defensively.
|
|
3
|
+
*
|
|
4
|
+
* The shape is `KortixToolResult` in `packages/api-contract/src/kortix-tool-card.ts`.
|
|
5
|
+
* The SDK does not depend on that package, so the types are mirrored here and
|
|
6
|
+
* every field is checked. A result that does not parse is `null`, and a host
|
|
7
|
+
* renders the call as its generic tool card instead of a half-drawn one.
|
|
8
|
+
*/
|
|
9
|
+
/** `KORTIX_PLATFORM_TOOL_NAMES` in `packages/api-contract/src/kortix-tool-card.ts`. */
|
|
10
|
+
export const KORTIX_PLATFORM_TOOLS = [
|
|
11
|
+
'kortix_agents',
|
|
12
|
+
'kortix_sessions',
|
|
13
|
+
'kortix_schedules',
|
|
14
|
+
'kortix_connectors',
|
|
15
|
+
'kortix_people',
|
|
16
|
+
'kortix_access',
|
|
17
|
+
'kortix_usage',
|
|
18
|
+
'kortix_change_requests',
|
|
19
|
+
'kortix_memory',
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* The multi-agent tools (`packages/api-contract/src/multi-agent.ts`): the same
|
|
23
|
+
* `KortixToolResult`, with `data` = the contract object the card body draws.
|
|
24
|
+
* `task_create`, `task_list`, `task_get` and `task_update` are also the names of
|
|
25
|
+
* older plugin tools: a host tells the two apart by the output (`isTeamTaskCall` in `@kortix/ui`).
|
|
26
|
+
*/
|
|
27
|
+
export const MULTI_AGENT_TOOLS = [
|
|
28
|
+
'send_message',
|
|
29
|
+
'list_agents',
|
|
30
|
+
'task_create',
|
|
31
|
+
'task_list',
|
|
32
|
+
'task_get',
|
|
33
|
+
'task_update',
|
|
34
|
+
'task_stop',
|
|
35
|
+
];
|
|
36
|
+
const STATUSES = new Set(['done', 'running', 'needs_you', 'denied', 'error']);
|
|
37
|
+
const ERROR_KINDS = new Set(['denied', 'not_found', 'invalid', 'failed']);
|
|
38
|
+
/** A card holds a short list; a longer one is the tool's mistake, not a page to render. */
|
|
39
|
+
const MAX_ITEMS = 50;
|
|
40
|
+
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
41
|
+
const text = (value) => typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
42
|
+
/** The platform tool a call name names: `kortix_agents`, also as `kortix-agents` or `oc-kortix_agents`. */
|
|
43
|
+
export function kortixPlatformTool(name) {
|
|
44
|
+
const normalized = name.replace(/^oc[-_]/, '').replace(/-/g, '_');
|
|
45
|
+
return KORTIX_PLATFORM_TOOLS.includes(normalized)
|
|
46
|
+
? normalized
|
|
47
|
+
: undefined;
|
|
48
|
+
}
|
|
49
|
+
/** A multi-agent tool a call name names: `send_message`, also as `send-message` or `oc-send_message`. */
|
|
50
|
+
export function multiAgentTool(name) {
|
|
51
|
+
const normalized = name.replace(/^oc[-_]/, '').replace(/-/g, '_');
|
|
52
|
+
return MULTI_AGENT_TOOLS.includes(normalized) ? normalized : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** Any tool that answers with a `KortixToolResult` card. */
|
|
55
|
+
export function kortixCardTool(name) {
|
|
56
|
+
return kortixPlatformTool(name) ?? multiAgentTool(name);
|
|
57
|
+
}
|
|
58
|
+
/** An in-app path: one leading `/`, never `//` (a protocol-relative URL leaves the app). */
|
|
59
|
+
export function inAppHref(value) {
|
|
60
|
+
const href = text(value);
|
|
61
|
+
return href && href.startsWith('/') && !href.startsWith('//') && !href.includes('\\') ? href : undefined;
|
|
62
|
+
}
|
|
63
|
+
function externalHref(value) {
|
|
64
|
+
const href = text(value);
|
|
65
|
+
if (!href)
|
|
66
|
+
return undefined;
|
|
67
|
+
try {
|
|
68
|
+
return new URL(href).protocol === 'https:' ? href : undefined;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function list(value, item) {
|
|
75
|
+
if (!Array.isArray(value))
|
|
76
|
+
return [];
|
|
77
|
+
const out = [];
|
|
78
|
+
for (const entry of value.slice(0, MAX_ITEMS)) {
|
|
79
|
+
const parsed = item(entry);
|
|
80
|
+
if (parsed !== undefined)
|
|
81
|
+
out.push(parsed);
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function row(entry) {
|
|
86
|
+
if (!isObject(entry))
|
|
87
|
+
return undefined;
|
|
88
|
+
const title = text(entry.title);
|
|
89
|
+
if (!title)
|
|
90
|
+
return undefined;
|
|
91
|
+
const detail = text(entry.detail);
|
|
92
|
+
const badge = text(entry.badge);
|
|
93
|
+
const href = inAppHref(entry.href);
|
|
94
|
+
return { title, ...(detail ? { detail } : {}), ...(badge ? { badge } : {}), ...(href ? { href } : {}) };
|
|
95
|
+
}
|
|
96
|
+
const setting = (value) => value === null ? null : typeof value === 'string' ? value : typeof value === 'number' || typeof value === 'boolean' ? String(value) : undefined;
|
|
97
|
+
function change(entry) {
|
|
98
|
+
if (!isObject(entry))
|
|
99
|
+
return undefined;
|
|
100
|
+
const field = text(entry.field);
|
|
101
|
+
const before = setting(entry.before);
|
|
102
|
+
const after = setting(entry.after);
|
|
103
|
+
if (!field || before === undefined || after === undefined || (before === null && after === null))
|
|
104
|
+
return undefined;
|
|
105
|
+
return { field, before, after };
|
|
106
|
+
}
|
|
107
|
+
function link(entry) {
|
|
108
|
+
if (!isObject(entry))
|
|
109
|
+
return undefined;
|
|
110
|
+
const label = text(entry.label);
|
|
111
|
+
if (!label)
|
|
112
|
+
return undefined;
|
|
113
|
+
const internal = inAppHref(entry.href);
|
|
114
|
+
if (internal)
|
|
115
|
+
return { label, href: internal, external: false };
|
|
116
|
+
const external = externalHref(entry.href);
|
|
117
|
+
return external ? { label, href: external, external: true } : undefined;
|
|
118
|
+
}
|
|
119
|
+
function grantor(entry) {
|
|
120
|
+
if (!isObject(entry))
|
|
121
|
+
return undefined;
|
|
122
|
+
const name = text(entry.name);
|
|
123
|
+
return name ? { name, role: text(entry.role) ?? '' } : undefined;
|
|
124
|
+
}
|
|
125
|
+
function toolError(value) {
|
|
126
|
+
if (!isObject(value) || !ERROR_KINDS.has(value.kind))
|
|
127
|
+
return undefined;
|
|
128
|
+
return {
|
|
129
|
+
kind: value.kind,
|
|
130
|
+
message: text(value.message) ?? '',
|
|
131
|
+
grantors: list(value.grantors, grantor),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The result in a platform call's output (or its error text, when the call threw
|
|
136
|
+
* it): one JSON object. `null` when the text is not that object. `callName` names
|
|
137
|
+
* the tool when the result leaves `tool` out.
|
|
138
|
+
*/
|
|
139
|
+
export function parseKortixToolResult(raw, callName) {
|
|
140
|
+
const source = raw?.trim();
|
|
141
|
+
if (!source || !source.startsWith('{'))
|
|
142
|
+
return null;
|
|
143
|
+
let value;
|
|
144
|
+
try {
|
|
145
|
+
value = JSON.parse(source);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if (!isObject(value) || typeof value.ok !== 'boolean' || !isObject(value.card))
|
|
151
|
+
return null;
|
|
152
|
+
const tool = typeof value.tool === 'string' ? kortixCardTool(value.tool) : callName !== undefined ? kortixCardTool(callName) : undefined;
|
|
153
|
+
const title = text(value.card.title);
|
|
154
|
+
if (!tool || !title)
|
|
155
|
+
return null;
|
|
156
|
+
const error = toolError(value.error);
|
|
157
|
+
// A refusal reads as one whatever status the card names: the error kind is the fact.
|
|
158
|
+
const status = error?.kind === 'denied'
|
|
159
|
+
? 'denied'
|
|
160
|
+
: STATUSES.has(value.card.status)
|
|
161
|
+
? value.card.status
|
|
162
|
+
: value.ok
|
|
163
|
+
? 'done'
|
|
164
|
+
: 'error';
|
|
165
|
+
const subtitle = text(value.card.subtitle);
|
|
166
|
+
return {
|
|
167
|
+
ok: value.ok,
|
|
168
|
+
tool,
|
|
169
|
+
action: text(value.action) ?? '',
|
|
170
|
+
card: {
|
|
171
|
+
title,
|
|
172
|
+
...(subtitle ? { subtitle } : {}),
|
|
173
|
+
status,
|
|
174
|
+
rows: list(value.card.rows, row),
|
|
175
|
+
changes: list(value.card.changes, change),
|
|
176
|
+
links: list(value.card.links, link),
|
|
177
|
+
},
|
|
178
|
+
...(error ? { error } : {}),
|
|
179
|
+
...(value.data !== undefined ? { data: value.data } : {}),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** The actions that only read; every other action changes something (the SDK narration uses the same set). */
|
|
183
|
+
const READ_ACTIONS = new Set(['', 'list', 'get', 'read', 'find', 'show', 'view', 'events', 'runs', 'test', 'search', 'check', 'status', 'pending', 'who']);
|
|
184
|
+
export function isReadAction(action) {
|
|
185
|
+
return READ_ACTIONS.has(typeof action === 'string' ? action : '');
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=kortix-tool-card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kortix-tool-card.js","sourceRoot":"","sources":["../../../../src/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CAAC,IAAI,EAAE,GAAG,CAAC;YAChC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;YACzC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC;SACpC;QACD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,8GAA8G;AAC9G,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3J,MAAM,UAAU,YAAY,CAAC,MAAe;IAC1C,OAAO,YAAY,CAAC,GAAG,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `workflow` tool's run document, parsed defensively, and the pure helpers
|
|
3
|
+
* a run card draws from (web, TUI, mobile).
|
|
4
|
+
*
|
|
5
|
+
* The shape is `WorkflowRunMetadata` (`core/rest/projects-client/multi-agent.ts`,
|
|
6
|
+
* held equal to `packages/api-contract/src/kortix-tool-card.ts`). It arrives as a
|
|
7
|
+
* tool part's metadata (`ToolView.metadata`) or from `GET …/workflows`, so every
|
|
8
|
+
* field is checked. pi pushes it live with every change of the run, and the
|
|
9
|
+
* final copy when the call returns.
|
|
10
|
+
*/
|
|
11
|
+
import type { WorkflowRunAgent, WorkflowRunPhase, WorkflowRunStatus } from '../../rest/projects-client/multi-agent.js';
|
|
12
|
+
/** A phase's status. `pending`: declared in the script's `meta.phases`, not started yet. */
|
|
13
|
+
export type WorkflowPhaseStatus = WorkflowRunPhase['status'];
|
|
14
|
+
/**
|
|
15
|
+
* A run as a card draws it: `WorkflowRunMetadata` after `parseWorkflowRun`, with
|
|
16
|
+
* `logs` always a list and the newest 5 lines at most.
|
|
17
|
+
*/
|
|
18
|
+
export interface WorkflowRun {
|
|
19
|
+
runId: string;
|
|
20
|
+
title: string;
|
|
21
|
+
status: WorkflowRunStatus;
|
|
22
|
+
phases: WorkflowRunPhase[];
|
|
23
|
+
agents: WorkflowRunAgent[];
|
|
24
|
+
startedAt?: number;
|
|
25
|
+
endedAt?: number;
|
|
26
|
+
error?: string;
|
|
27
|
+
/** The most agents this run may start. */
|
|
28
|
+
maxAgents?: number;
|
|
29
|
+
/** A saved workflow run by name. */
|
|
30
|
+
name?: string;
|
|
31
|
+
/** The script's newest `log()` lines, oldest first. */
|
|
32
|
+
logs: string[];
|
|
33
|
+
/** More than 25 agents: the card warns, as Claude Code's "Large workflow". */
|
|
34
|
+
large?: true;
|
|
35
|
+
/** The run this one resumed. */
|
|
36
|
+
resumedFrom?: string;
|
|
37
|
+
/** The run goes on in its own runner session; this call returned at once. */
|
|
38
|
+
background?: {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
};
|
|
41
|
+
/** `pause` held new agents back; running agents finish. Cleared by `resume`. */
|
|
42
|
+
paused?: true;
|
|
43
|
+
}
|
|
44
|
+
/** The run in a `workflow` call's metadata; `null` when the metadata is not a run. */
|
|
45
|
+
export declare function parseWorkflowRun(metadata: unknown): WorkflowRun | null;
|
|
46
|
+
/** True for pi's `workflow` tool, under any of its spellings, and for no other name ending in `workflow`. */
|
|
47
|
+
export declare function isWorkflowTool(name: string): boolean;
|
|
48
|
+
/** The filter of the agent list, as Claude Code's `f` cycles it. */
|
|
49
|
+
export type AgentFilter = 'all' | 'running' | 'failed' | 'done';
|
|
50
|
+
export declare const AGENT_FILTERS: readonly AgentFilter[];
|
|
51
|
+
/** Whether an agent belongs under a filter. `stopped` is listed under `all` only. */
|
|
52
|
+
export declare function agentMatches(agent: WorkflowRunAgent, filter: AgentFilter): boolean;
|
|
53
|
+
export interface AgentCounts {
|
|
54
|
+
total: number;
|
|
55
|
+
running: number;
|
|
56
|
+
failed: number;
|
|
57
|
+
done: number;
|
|
58
|
+
}
|
|
59
|
+
export declare function countAgents(agents: readonly WorkflowRunAgent[]): AgentCounts;
|
|
60
|
+
/** One group of the progress list: a phase and its agents, or the agents started before any phase. */
|
|
61
|
+
export interface AgentGroup {
|
|
62
|
+
/** `null`: the agents that belong to no phase. They come first and have no header. */
|
|
63
|
+
phase: WorkflowRunPhase | null;
|
|
64
|
+
agents: WorkflowRunAgent[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The agents grouped under their phases, in the run's phase order. An agent whose
|
|
68
|
+
* phase the list does not name gets a group of its own after the named ones, as a
|
|
69
|
+
* `phase()` title with no `meta.phases` entry does in Claude Code.
|
|
70
|
+
*/
|
|
71
|
+
export declare function groupAgents(run: Pick<WorkflowRun, 'phases' | 'agents'>): AgentGroup[];
|
|
72
|
+
/** `12s`, `3m 04s`, `1h 05m`. Seconds and minutes are zero-padded so a ticking label keeps its width. */
|
|
73
|
+
export declare function formatElapsed(ms: number): string;
|
|
74
|
+
/** How long a run or an agent took, or has taken by `now`; undefined when its start is unknown or it never ran. */
|
|
75
|
+
export declare function elapsedMs(item: {
|
|
76
|
+
startedAt?: number;
|
|
77
|
+
endedAt?: number;
|
|
78
|
+
}, live: boolean, now: number): number | undefined;
|
|
79
|
+
export type StructuredSummary = {
|
|
80
|
+
kind: 'object';
|
|
81
|
+
keys: number;
|
|
82
|
+
pretty: string;
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'array';
|
|
85
|
+
items: number;
|
|
86
|
+
pretty: string;
|
|
87
|
+
} | {
|
|
88
|
+
kind: 'value';
|
|
89
|
+
pretty: string;
|
|
90
|
+
} | {
|
|
91
|
+
kind: 'text';
|
|
92
|
+
pretty: string;
|
|
93
|
+
};
|
|
94
|
+
/** A `structured` agent's summary: the JSON it holds, or its text when it does not parse (a cut answer). */
|
|
95
|
+
export declare function structuredSummary(summary: string): StructuredSummary;
|
|
96
|
+
export type WorkflowResult = {
|
|
97
|
+
kind: 'json';
|
|
98
|
+
text: string;
|
|
99
|
+
} | {
|
|
100
|
+
kind: 'markdown';
|
|
101
|
+
text: string;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The script's return value in a finished call's output (`<workflow_result>…</workflow_result>`):
|
|
105
|
+
* pretty JSON when it parses as an object or a list, else Markdown. Null when the output has no
|
|
106
|
+
* result block (an older run, or a run that failed).
|
|
107
|
+
*/
|
|
108
|
+
export declare function parseWorkflowResult(output: string): WorkflowResult | null;
|
|
109
|
+
//# sourceMappingURL=workflow-run.d.ts.map
|