@ptkl/toolkit 0.14.0 → 1.1.0
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 -2
- package/dist/commands/billing.js +111 -0
- package/dist/commands/config.js +33 -0
- package/dist/commands/forge.js +241 -13
- package/dist/commands/functions.js +87 -22
- package/dist/commands/index.js +21 -1
- package/dist/commands/integration.js +146 -0
- package/dist/commands/integrations/dms.js +625 -0
- package/dist/commands/integrations/mail.js +120 -0
- package/dist/commands/integrations/payments.js +199 -0
- package/dist/commands/integrations/serbia.js +610 -0
- package/dist/commands/integrations/timber.js +120 -0
- package/dist/commands/kortex.js +203 -12
- package/dist/commands/logs.js +4 -17
- package/dist/commands/project.js +147 -0
- package/dist/commands/ratchet.js +82 -0
- package/dist/commands/sandbox.js +122 -0
- package/dist/commands/satellite.js +111 -0
- package/dist/commands/template.js +96 -0
- package/dist/commands/thunder.js +123 -0
- package/dist/commands/users.js +31 -19
- package/dist/commands/workflow.js +225 -30
- package/dist/lib/forgeDevKernelPlugin.js +2 -1
- package/dist/lib/kortex/session.js +20 -16
- package/dist/lib/scaffold.js +51 -0
- package/dist/lib/sdk.js +88 -0
- package/package.json +1 -1
|
@@ -1,40 +1,235 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import * as sdk from "../lib/sdk.js";
|
|
3
|
+
import { registerCommand, withProfile } from "../lib/scaffold.js";
|
|
4
|
+
/** `ptkl workflow` — Workflow engine (RFC §4.2 "Workflow", `workflow/…` gateway prefix).
|
|
5
|
+
* Maps onto the SDK `Workflow` client (@ptkl/sdk/beta):
|
|
6
|
+
* - CRUD -> create/update/get/list/delete
|
|
7
|
+
* - trigger/publish/install -> trigger/publish/install
|
|
8
|
+
* - history -> getHistory/getHistoryEntry (execution history)
|
|
9
|
+
* - running -> getRunning/getRunningEntry (in-flight executions)
|
|
10
|
+
* - execution control -> pause/resume/kill/restart
|
|
11
|
+
* - node control -> pauseNode/resumeNode/killNode
|
|
12
|
+
* - errors -> getErrors/removeError/removeAllErrors */
|
|
13
|
+
function parseJSON(label, raw) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
console.error(`${label} must be valid JSON`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function readNodeControlOptions(opts) {
|
|
23
|
+
const iterationIdx = opts.iterationIdx !== undefined ? Number(opts.iterationIdx) : undefined;
|
|
24
|
+
const parentNodeId = opts.parentNodeId !== undefined ? Number(opts.parentNodeId) : undefined;
|
|
25
|
+
if (iterationIdx === undefined && parentNodeId === undefined)
|
|
26
|
+
return undefined;
|
|
27
|
+
return { ...(iterationIdx !== undefined ? { iterationIdx } : {}), ...(parentNodeId !== undefined ? { parentNodeId } : {}) };
|
|
28
|
+
}
|
|
29
|
+
function withNodeControlOptions(cmd) {
|
|
30
|
+
return cmd
|
|
31
|
+
.option("--iteration-idx <n>", "Iteration index (for nodes inside a loop)")
|
|
32
|
+
.option("--parent-node-id <id>", "Parent node ID (for nodes inside a loop)");
|
|
33
|
+
}
|
|
5
34
|
class WorkflowCommand {
|
|
6
35
|
register() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.addCommand(new OutputFormatCommand(new Command("list")
|
|
14
|
-
.description("List all workflows for the current project")).action(this.list))
|
|
15
|
-
.addCommand(new OutputFormatCommand(new Command("get")
|
|
36
|
+
const cmd = new Command("workflow").description("Manage project workflows");
|
|
37
|
+
cmd.addCommand(registerCommand(new Command("list").description("List all workflows for the current project")).action(withProfile(async (profile) => {
|
|
38
|
+
const res = await sdk.workflow(profile).list();
|
|
39
|
+
return res.data;
|
|
40
|
+
})));
|
|
41
|
+
cmd.addCommand(registerCommand(new Command("get")
|
|
16
42
|
.description("Get a workflow by name or UUID")
|
|
17
|
-
.requiredOption("-r, --ref <ref>", "Workflow name or UUID")).action(
|
|
43
|
+
.requiredOption("-r, --ref <ref>", "Workflow name or UUID")).action(withProfile(async (profile, opts) => {
|
|
44
|
+
const res = await sdk.workflow(profile).get(opts.ref);
|
|
45
|
+
return res.data;
|
|
46
|
+
})));
|
|
47
|
+
cmd.addCommand(registerCommand(new Command("settings")
|
|
48
|
+
.description("Get settings for a workflow")
|
|
49
|
+
.requiredOption("-r, --ref <ref>", "Workflow name or UUID")).action(withProfile(async (profile, opts) => {
|
|
50
|
+
const res = await sdk.workflow(profile).get(opts.ref);
|
|
51
|
+
return res.data.settings;
|
|
52
|
+
})));
|
|
53
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
54
|
+
.description("Create a new workflow")
|
|
55
|
+
.requiredOption("-d, --data <json>", "Workflow payload as a JSON string (name, dev_version, public_version, integrator, roles, settings)")).action(withProfile(async (profile, opts) => {
|
|
56
|
+
const data = parseJSON("--data", opts.data);
|
|
57
|
+
const res = await sdk.workflow(profile).create(data);
|
|
58
|
+
return res.data;
|
|
59
|
+
})));
|
|
60
|
+
cmd.addCommand(registerCommand(new Command("update")
|
|
61
|
+
.description("Update an existing workflow")
|
|
62
|
+
.argument("<id>", "Workflow UUID")
|
|
63
|
+
.requiredOption("-d, --data <json>", "Workflow payload as a JSON string (name, dev_version, public_version, integrator, roles, settings)")).action(withProfile(async (profile, id, opts) => {
|
|
64
|
+
const data = parseJSON("--data", opts.data);
|
|
65
|
+
const res = await sdk.workflow(profile).update(id, data);
|
|
66
|
+
return res.data;
|
|
67
|
+
})));
|
|
68
|
+
cmd.addCommand(registerCommand(new Command("delete")
|
|
69
|
+
.description("Delete a workflow")
|
|
70
|
+
.argument("<id>", "Workflow UUID")).action(withProfile(async (profile, id) => {
|
|
71
|
+
const res = await sdk.workflow(profile).delete(id);
|
|
72
|
+
return res.data;
|
|
73
|
+
})));
|
|
74
|
+
cmd.addCommand(registerCommand(new Command("trigger")
|
|
75
|
+
.description("Trigger a workflow's event handler by workflow ID")
|
|
76
|
+
.argument("<id>", "Workflow UUID")
|
|
77
|
+
.argument("<event>", "Event name")
|
|
78
|
+
.option("-d, --data <json>", "Event payload as a JSON string", "{}")).action(withProfile(async (profile, id, event, opts) => {
|
|
79
|
+
const data = parseJSON("--data", opts.data);
|
|
80
|
+
const res = await sdk.workflow(profile).trigger(id, event, data);
|
|
81
|
+
return res.data;
|
|
82
|
+
})));
|
|
83
|
+
cmd.addCommand(registerCommand(new Command("publish")
|
|
84
|
+
.description("Publish an event to every workflow subscribed to it")
|
|
85
|
+
.argument("<event>", "Event name")
|
|
86
|
+
.option("-d, --data <json>", "Event payload as a JSON string", "{}")).action(withProfile(async (profile, event, opts) => {
|
|
87
|
+
const data = parseJSON("--data", opts.data);
|
|
88
|
+
const res = await sdk.workflow(profile).publish(event, data);
|
|
89
|
+
return res.data;
|
|
90
|
+
})));
|
|
91
|
+
cmd.addCommand(registerCommand(new Command("install")
|
|
92
|
+
.description("Create and publish a workflow in one call (rejects if name+integrator already exists)")
|
|
93
|
+
.requiredOption("-d, --data <json>", "Install payload as a JSON string (name, settings, project_uuid, dev_version, public_version, integrator)")).action(withProfile(async (profile, opts) => {
|
|
94
|
+
const data = parseJSON("--data", opts.data);
|
|
95
|
+
const res = await sdk.workflow(profile).install(data);
|
|
96
|
+
return res.data;
|
|
97
|
+
})));
|
|
98
|
+
cmd.addCommand(this.registerHistory());
|
|
99
|
+
cmd.addCommand(this.registerRunning());
|
|
100
|
+
cmd.addCommand(registerCommand(new Command("pause")
|
|
101
|
+
.description("Pause a running workflow execution")
|
|
102
|
+
.argument("<exec>", "Execution UUID")).action(withProfile(async (profile, exec) => {
|
|
103
|
+
const res = await sdk.workflow(profile).pause(exec);
|
|
104
|
+
return res.data;
|
|
105
|
+
})));
|
|
106
|
+
cmd.addCommand(registerCommand(new Command("resume")
|
|
107
|
+
.description("Resume a paused workflow execution")
|
|
108
|
+
.argument("<exec>", "Execution UUID")).action(withProfile(async (profile, exec) => {
|
|
109
|
+
const res = await sdk.workflow(profile).resume(exec);
|
|
110
|
+
return res.data;
|
|
111
|
+
})));
|
|
112
|
+
cmd.addCommand(registerCommand(new Command("kill")
|
|
113
|
+
.description("Kill a running or paused workflow execution")
|
|
114
|
+
.argument("<exec>", "Execution UUID")).action(withProfile(async (profile, exec) => {
|
|
115
|
+
const res = await sdk.workflow(profile).kill(exec);
|
|
116
|
+
return res.data;
|
|
117
|
+
})));
|
|
118
|
+
cmd.addCommand(registerCommand(new Command("restart")
|
|
119
|
+
.description("Restart a failed/killed workflow execution from history")
|
|
120
|
+
.argument("<exec>", "Execution UUID")
|
|
121
|
+
.option("--clear-state", "Discard prior node state instead of a smart resume")).action(withProfile(async (profile, exec, opts) => {
|
|
122
|
+
const res = await sdk.workflow(profile).restart(exec, { clearState: !!opts.clearState });
|
|
123
|
+
return res.data;
|
|
124
|
+
})));
|
|
125
|
+
cmd.addCommand(this.registerNode());
|
|
126
|
+
cmd.addCommand(this.registerErrors());
|
|
127
|
+
return cmd;
|
|
128
|
+
}
|
|
129
|
+
registerHistory() {
|
|
130
|
+
const history = new Command("history").description("Inspect workflow execution history");
|
|
131
|
+
history.addCommand(registerCommand(new Command("list")
|
|
132
|
+
.description("List workflow execution history, grouped by context")
|
|
133
|
+
.option("--limit <n>", "Max results")
|
|
134
|
+
.option("--offset <n>", "Result offset")
|
|
135
|
+
.option("--status <status>", "Filter by execution status")
|
|
136
|
+
.option("--ref <ref>", "Filter by workflow ref (name or UUID)")
|
|
137
|
+
.option("--type <type>", "Filter by execution type")
|
|
138
|
+
.option("--workflow-name <name>", "Filter by workflow name")
|
|
139
|
+
.option("--context-uuid <uuid>", "Filter by context UUID")
|
|
140
|
+
.option("--date-from <date>", "Only include executions starting after this date")).action(withProfile(async (profile, opts) => {
|
|
141
|
+
const res = await sdk.workflow(profile).getHistory({
|
|
142
|
+
limit: opts.limit !== undefined ? Number(opts.limit) : undefined,
|
|
143
|
+
offset: opts.offset !== undefined ? Number(opts.offset) : undefined,
|
|
144
|
+
status: opts.status,
|
|
145
|
+
ref: opts.ref,
|
|
146
|
+
type: opts.type,
|
|
147
|
+
workflow_name: opts.workflowName,
|
|
148
|
+
context_uuid: opts.contextUuid,
|
|
149
|
+
date_from: opts.dateFrom,
|
|
150
|
+
});
|
|
151
|
+
return res.data;
|
|
152
|
+
})));
|
|
153
|
+
history.addCommand(registerCommand(new Command("get")
|
|
154
|
+
.description("Get a single workflow execution history entry")
|
|
155
|
+
.argument("<exec>", "Execution UUID")).action(withProfile(async (profile, exec) => {
|
|
156
|
+
const res = await sdk.workflow(profile).getHistoryEntry(exec);
|
|
157
|
+
return res.data;
|
|
158
|
+
})));
|
|
159
|
+
return history;
|
|
18
160
|
}
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
161
|
+
registerRunning() {
|
|
162
|
+
const running = new Command("running").description("Inspect currently running workflow executions");
|
|
163
|
+
running.addCommand(registerCommand(new Command("list")
|
|
164
|
+
.description("List currently running workflow executions")
|
|
165
|
+
.option("--limit <n>", "Max results")
|
|
166
|
+
.option("--offset <n>", "Result offset")
|
|
167
|
+
.option("--status <status>", "Filter by execution status")
|
|
168
|
+
.option("--type <type>", "Filter by execution type")
|
|
169
|
+
.option("--ref <ref>", "Filter by workflow ref (name or UUID)")
|
|
170
|
+
.option("--workflow-name <name>", "Filter by workflow name")
|
|
171
|
+
.option("--context-uuid <uuid>", "Filter by context UUID")).action(withProfile(async (profile, opts) => {
|
|
172
|
+
const res = await sdk.workflow(profile).getRunning({
|
|
173
|
+
limit: opts.limit !== undefined ? Number(opts.limit) : undefined,
|
|
174
|
+
offset: opts.offset !== undefined ? Number(opts.offset) : undefined,
|
|
175
|
+
status: opts.status,
|
|
176
|
+
type: opts.type,
|
|
177
|
+
ref: opts.ref,
|
|
178
|
+
workflow_name: opts.workflowName,
|
|
179
|
+
context_uuid: opts.contextUuid,
|
|
180
|
+
});
|
|
181
|
+
return res.data;
|
|
182
|
+
})));
|
|
183
|
+
running.addCommand(registerCommand(new Command("get")
|
|
184
|
+
.description("Get a single running workflow execution")
|
|
185
|
+
.argument("<exec>", "Execution UUID")).action(withProfile(async (profile, exec) => {
|
|
186
|
+
const res = await sdk.workflow(profile).getRunningEntry(exec);
|
|
187
|
+
return res.data;
|
|
188
|
+
})));
|
|
189
|
+
return running;
|
|
25
190
|
}
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
191
|
+
registerNode() {
|
|
192
|
+
const node = new Command("node").description("Node-level execution control within a running workflow");
|
|
193
|
+
node.addCommand(registerCommand(withNodeControlOptions(new Command("pause")
|
|
194
|
+
.description("Pause a single node within a running workflow execution")
|
|
195
|
+
.argument("<exec>", "Execution UUID")
|
|
196
|
+
.argument("<nodeId>", "Node ID"))).action(withProfile(async (profile, exec, nodeId, opts) => {
|
|
197
|
+
const res = await sdk.workflow(profile).pauseNode(exec, Number(nodeId), readNodeControlOptions(opts));
|
|
198
|
+
return res.data;
|
|
199
|
+
})));
|
|
200
|
+
node.addCommand(registerCommand(withNodeControlOptions(new Command("resume")
|
|
201
|
+
.description("Resume a single node within a running workflow execution")
|
|
202
|
+
.argument("<exec>", "Execution UUID")
|
|
203
|
+
.argument("<nodeId>", "Node ID"))).action(withProfile(async (profile, exec, nodeId, opts) => {
|
|
204
|
+
const res = await sdk.workflow(profile).resumeNode(exec, Number(nodeId), readNodeControlOptions(opts));
|
|
205
|
+
return res.data;
|
|
206
|
+
})));
|
|
207
|
+
node.addCommand(registerCommand(withNodeControlOptions(new Command("kill")
|
|
208
|
+
.description("Kill a single node within a running workflow execution")
|
|
209
|
+
.argument("<exec>", "Execution UUID")
|
|
210
|
+
.argument("<nodeId>", "Node ID"))).action(withProfile(async (profile, exec, nodeId, opts) => {
|
|
211
|
+
const res = await sdk.workflow(profile).killNode(exec, Number(nodeId), readNodeControlOptions(opts));
|
|
212
|
+
return res.data;
|
|
213
|
+
})));
|
|
214
|
+
return node;
|
|
31
215
|
}
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
216
|
+
registerErrors() {
|
|
217
|
+
const errors = new Command("errors").description("Manage workflow execution errors");
|
|
218
|
+
errors.addCommand(registerCommand(new Command("list").description("List workflow execution errors")).action(withProfile(async (profile) => {
|
|
219
|
+
const res = await sdk.workflow(profile).getErrors();
|
|
220
|
+
return res.data;
|
|
221
|
+
})));
|
|
222
|
+
errors.addCommand(registerCommand(new Command("remove")
|
|
223
|
+
.description("Remove a single workflow execution error")
|
|
224
|
+
.argument("<id>", "Error ID")).action(withProfile(async (profile, id) => {
|
|
225
|
+
const res = await sdk.workflow(profile).removeError(id);
|
|
226
|
+
return res.data;
|
|
227
|
+
})));
|
|
228
|
+
errors.addCommand(registerCommand(new Command("clear").description("Remove all workflow execution errors")).action(withProfile(async (profile) => {
|
|
229
|
+
const res = await sdk.workflow(profile).removeAllErrors();
|
|
230
|
+
return res.data;
|
|
231
|
+
})));
|
|
232
|
+
return errors;
|
|
38
233
|
}
|
|
39
234
|
}
|
|
40
235
|
export default new WorkflowCommand();
|
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
* in platform-forge/src/lib/dynamicImport.ts — uses a DOM overlay with an iframe
|
|
8
8
|
* instead of a popup window to avoid popup blockers.
|
|
9
9
|
*/
|
|
10
|
-
export function forgeDevKernelPlugin(appName, platformUrl) {
|
|
10
|
+
export function forgeDevKernelPlugin(appName, platformUrl, devHubPort) {
|
|
11
11
|
const appRef = appName ?? '';
|
|
12
12
|
const platUrl = platformUrl ? platformUrl.replace(/\/$/, '') : '';
|
|
13
13
|
const scriptContent = `(function(){
|
|
14
14
|
var _appRef=${JSON.stringify(appRef)};
|
|
15
15
|
var _platformUrl=${JSON.stringify(platUrl)};
|
|
16
16
|
window.$forge=window.forge||{};
|
|
17
|
+
${devHubPort ? ` window.__PTKL_DEV_HUB__="http://localhost:${devHubPort}";\n window.DEV_HUB_PORT=${devHubPort};` : ''}
|
|
17
18
|
function openPlatformPopup(url){return window.open(url,'_blank');}
|
|
18
19
|
function showWaitingOverlay(message){
|
|
19
20
|
var overlay=document.createElement('div');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
+
import { Kortex } from '@ptkl/sdk/beta';
|
|
4
5
|
import { getToolDefinitions, executeTool } from './tools.js';
|
|
5
6
|
import { MCPManager } from './mcp.js';
|
|
6
7
|
import { saveKortexConfig } from './config.js';
|
|
@@ -62,6 +63,7 @@ function getToolSummary(name, args) {
|
|
|
62
63
|
}
|
|
63
64
|
export default class Session {
|
|
64
65
|
client;
|
|
66
|
+
kortexClient;
|
|
65
67
|
opts;
|
|
66
68
|
bridge;
|
|
67
69
|
conversationUUID;
|
|
@@ -96,6 +98,11 @@ export default class Session {
|
|
|
96
98
|
'X-Agent-Context': 'cli',
|
|
97
99
|
},
|
|
98
100
|
});
|
|
101
|
+
// SDK Kortex client for all cloud (platform-persisted) conversation/message/agent
|
|
102
|
+
// calls. Local `/chat` streaming stays on the raw axios client above — the SDK has
|
|
103
|
+
// no equivalent for that stateless endpoint.
|
|
104
|
+
this.kortexClient = new Kortex({ host: opts.host, token: opts.token });
|
|
105
|
+
this.kortexClient.client.defaults.headers.common['X-Agent-Context'] = 'cli';
|
|
99
106
|
}
|
|
100
107
|
async start() {
|
|
101
108
|
await this.mcp.loadConfig(this.cwd);
|
|
@@ -166,7 +173,7 @@ export default class Session {
|
|
|
166
173
|
saveConversation(this.localConversation);
|
|
167
174
|
}
|
|
168
175
|
async createConversation() {
|
|
169
|
-
const resp = await this.
|
|
176
|
+
const resp = await this.kortexClient.createConversation({
|
|
170
177
|
title: `CLI session — ${new Date().toISOString().slice(0, 16)}`,
|
|
171
178
|
agent_uuid: this.opts.agentUUID,
|
|
172
179
|
});
|
|
@@ -175,7 +182,7 @@ export default class Session {
|
|
|
175
182
|
}
|
|
176
183
|
async injectSessionContext() {
|
|
177
184
|
try {
|
|
178
|
-
await this.
|
|
185
|
+
await this.kortexClient.injectMessage(this.conversationUUID, { role: 'context', content: `Working directory: ${this.cwd}` });
|
|
179
186
|
}
|
|
180
187
|
catch {
|
|
181
188
|
// Non-fatal
|
|
@@ -271,15 +278,14 @@ export default class Session {
|
|
|
271
278
|
];
|
|
272
279
|
}
|
|
273
280
|
else {
|
|
274
|
-
const response = await this.
|
|
281
|
+
const response = await this.kortexClient.streamMessage(this.conversationUUID, {
|
|
275
282
|
content: summaryPrompt,
|
|
276
283
|
agent_uuid: this.activeAgentUUID,
|
|
277
|
-
|
|
278
|
-
}, { responseType: 'stream' });
|
|
284
|
+
});
|
|
279
285
|
summary = await this.silentStream(response.data);
|
|
280
286
|
await this.createConversation();
|
|
281
287
|
try {
|
|
282
|
-
await this.
|
|
288
|
+
await this.kortexClient.injectMessage(this.conversationUUID, { role: 'context', content: summary });
|
|
283
289
|
}
|
|
284
290
|
catch { /* non-fatal */ }
|
|
285
291
|
}
|
|
@@ -385,7 +391,7 @@ export default class Session {
|
|
|
385
391
|
return true;
|
|
386
392
|
}
|
|
387
393
|
case '/agent': {
|
|
388
|
-
const resp = await this.
|
|
394
|
+
const resp = await this.kortexClient.listAgents({ limit: 50 }).catch(() => ({ data: { data: [] } }));
|
|
389
395
|
const userAgents = (resp.data?.data ?? []).map((a) => ({
|
|
390
396
|
uuid: a.uuid,
|
|
391
397
|
name: a.name,
|
|
@@ -442,7 +448,7 @@ export default class Session {
|
|
|
442
448
|
if (!this.conversationUUID)
|
|
443
449
|
return;
|
|
444
450
|
try {
|
|
445
|
-
const resp = await this.
|
|
451
|
+
const resp = await this.kortexClient.getConversation(this.conversationUUID);
|
|
446
452
|
if (resp.data.participants) {
|
|
447
453
|
this.participants = resp.data.participants;
|
|
448
454
|
}
|
|
@@ -455,7 +461,7 @@ export default class Session {
|
|
|
455
461
|
const isUUID = /^[0-9a-f-]{36}$/i.test(nameOrUUID);
|
|
456
462
|
if (!isUUID) {
|
|
457
463
|
try {
|
|
458
|
-
const resp = await this.
|
|
464
|
+
const resp = await this.kortexClient.listAgents({ limit: 50 });
|
|
459
465
|
const agents = resp.data?.data || [];
|
|
460
466
|
const matches = agents.filter((a) => a.name.toLowerCase().includes(nameOrUUID.toLowerCase()));
|
|
461
467
|
if (matches.length === 0) {
|
|
@@ -471,7 +477,7 @@ export default class Session {
|
|
|
471
477
|
}
|
|
472
478
|
}
|
|
473
479
|
try {
|
|
474
|
-
await this.
|
|
480
|
+
await this.kortexClient.addParticipant(this.conversationUUID, { agent_uuid: agentUUID, name: agentName });
|
|
475
481
|
this.participants.push({ agent_uuid: agentUUID, name: agentName });
|
|
476
482
|
this.bridge.showSystem(`Added ${agentName} to conversation.`);
|
|
477
483
|
}
|
|
@@ -490,7 +496,7 @@ export default class Session {
|
|
|
490
496
|
return;
|
|
491
497
|
}
|
|
492
498
|
try {
|
|
493
|
-
await this.
|
|
499
|
+
await this.kortexClient.removeParticipant(this.conversationUUID, found.agent_uuid);
|
|
494
500
|
this.participants = this.participants.filter(p => p.agent_uuid !== found.agent_uuid);
|
|
495
501
|
this.bridge.showSystem(`Removed ${found.name} from conversation.`);
|
|
496
502
|
}
|
|
@@ -523,14 +529,13 @@ export default class Session {
|
|
|
523
529
|
const body = {
|
|
524
530
|
content: toolResults ? '' : content,
|
|
525
531
|
agent_uuid: agentUUID || this.activeAgentUUID,
|
|
526
|
-
stream: true,
|
|
527
532
|
tools: this.tools,
|
|
528
533
|
};
|
|
529
534
|
if (toolResults) {
|
|
530
535
|
body.tool_results = toolResults;
|
|
531
536
|
body.content = '';
|
|
532
537
|
}
|
|
533
|
-
const response = await this.
|
|
538
|
+
const response = await this.kortexClient.streamMessage(this.conversationUUID, body);
|
|
534
539
|
const result = await this.processStream(response.data);
|
|
535
540
|
this.cumulativeTokens.prompt += result.tokenUsage.prompt_tokens;
|
|
536
541
|
this.cumulativeTokens.completion += result.tokenUsage.completion_tokens;
|
|
@@ -598,13 +603,12 @@ export default class Session {
|
|
|
598
603
|
}
|
|
599
604
|
return;
|
|
600
605
|
}
|
|
601
|
-
const response = await this.
|
|
606
|
+
const response = await this.kortexClient.streamMessage(this.conversationUUID, {
|
|
602
607
|
content: '',
|
|
603
608
|
agent_uuid: agentUUID || this.activeAgentUUID,
|
|
604
|
-
stream: true,
|
|
605
609
|
tools: this.tools,
|
|
606
610
|
tool_results: results,
|
|
607
|
-
}
|
|
611
|
+
});
|
|
608
612
|
const result = await this.processStream(response.data);
|
|
609
613
|
cumulativeUsage.prompt_tokens += result.tokenUsage.prompt_tokens;
|
|
610
614
|
cumulativeUsage.completion_tokens += result.tokenUsage.completion_tokens;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Util from "./util.js";
|
|
2
|
+
import OutputFormatCommand from "../commands/outputCommand.js";
|
|
3
|
+
// Re-exported so new commands only need to import from this one module.
|
|
4
|
+
export { OutputFormatCommand };
|
|
5
|
+
/** Attach the global `--env <dev|live>` option to a command. Mirrors the existing `--profile`
|
|
6
|
+
* handling in src/bin/toolkit.ts (a flag whose resolved value is stashed on `process.env` so
|
|
7
|
+
* downstream lib code — src/lib/sdk.ts's `resolveEnv()` — can read it without threading it
|
|
8
|
+
* through every function call). */
|
|
9
|
+
export function withEnvOption(command) {
|
|
10
|
+
return command.option("--env <env>", "Environment to target: dev | live", "dev");
|
|
11
|
+
}
|
|
12
|
+
/** Build an `OutputFormatCommand`-wrapped command that also carries the global `--env` option.
|
|
13
|
+
* This is the uniform shape new command groups should use:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* registerCommand(new Command("list").description("List things"))
|
|
17
|
+
* .action(withProfile(async (profile, opts) => {
|
|
18
|
+
* const client = sdk.platform(profile);
|
|
19
|
+
* return (await client.project().list()).data;
|
|
20
|
+
* }))
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function registerCommand(command) {
|
|
24
|
+
withEnvOption(command);
|
|
25
|
+
return new OutputFormatCommand(command);
|
|
26
|
+
}
|
|
27
|
+
/** Wrap a command action with profile resolution + error normalization. The active profile is
|
|
28
|
+
* resolved once (throwing the existing friendly "run `profile use`" error if none is set) and
|
|
29
|
+
* handed to `fn` as the first argument; the resolved `--env` (if the wrapped command carries the
|
|
30
|
+
* option from `withEnvOption`/`registerCommand`) is stashed on `process.env.PTKL_ACTIVE_ENV` for
|
|
31
|
+
* `src/lib/sdk.ts` to pick up. Errors are normalized the same way as the top-level handler in
|
|
32
|
+
* src/bin/toolkit.ts (prefer the API's error message over a raw stack). */
|
|
33
|
+
export function withProfile(fn) {
|
|
34
|
+
return async (...args) => {
|
|
35
|
+
try {
|
|
36
|
+
const last = args[args.length - 1];
|
|
37
|
+
const opts = last && typeof last.opts === "function" ? last.opts() : undefined;
|
|
38
|
+
if (opts?.env) {
|
|
39
|
+
process.env.PTKL_ACTIVE_ENV = opts.env;
|
|
40
|
+
}
|
|
41
|
+
const profile = Util.getCurrentProfile();
|
|
42
|
+
return await fn(profile, ...args);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const response = err?.response;
|
|
46
|
+
const message = response?.data?.message ?? err?.message ?? String(err);
|
|
47
|
+
console.error(message);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
package/dist/lib/sdk.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Central factory for v0.10 SDK clients, built from the active profile.
|
|
2
|
+
//
|
|
3
|
+
// Two gateways exist on the platform (see TOOLKIT_API_COVERAGE_RFC.md §2):
|
|
4
|
+
// - PlatformBaseClient -> baseURL = profile.host (native /v1/... + proxied services)
|
|
5
|
+
// - IntegrationsBaseClient -> baseURL = profile.host + /luma/integrations (integration interfaces + satellites)
|
|
6
|
+
// Every accessor below builds its client against the correct gateway base URL so
|
|
7
|
+
// commands never have to think about which host to hit.
|
|
8
|
+
import { Platform, Integrations, Kortex, Workflow, Sandbox, Ratchet, Thunder, Project, Config, Payments, Mail, DMS, Timber, SerbiaMinFin, } from "@ptkl/sdk/beta";
|
|
9
|
+
import Util from "./util.js";
|
|
10
|
+
/** Resolve the active `--env` (dev|live), defaulting to `dev`. Commands surface `--env` through
|
|
11
|
+
* the scaffold (see src/lib/scaffold.ts), which stores the resolved value in this env var —
|
|
12
|
+
* mirroring how the existing `--profile` flag is threaded via PTKL_ACTIVE_PROFILE. */
|
|
13
|
+
export function resolveEnv() {
|
|
14
|
+
return process.env.PTKL_ACTIVE_ENV || "dev";
|
|
15
|
+
}
|
|
16
|
+
function stripTrailingSlashes(url) {
|
|
17
|
+
return url.replace(/\/+$/, "");
|
|
18
|
+
}
|
|
19
|
+
function resolveProfile(profile) {
|
|
20
|
+
return profile ?? Util.getCurrentProfile();
|
|
21
|
+
}
|
|
22
|
+
/** Options for the native platform gateway (`profile.host`). */
|
|
23
|
+
export function platformOptions(profile) {
|
|
24
|
+
const p = resolveProfile(profile);
|
|
25
|
+
return {
|
|
26
|
+
host: p.host,
|
|
27
|
+
token: p.token,
|
|
28
|
+
env: resolveEnv(),
|
|
29
|
+
project: p.project,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Options for the integrations gateway (`profile.host/luma/integrations`). */
|
|
33
|
+
export function integrationsOptions(profile) {
|
|
34
|
+
const p = resolveProfile(profile);
|
|
35
|
+
return {
|
|
36
|
+
host: `${stripTrailingSlashes(p.host)}/luma/integrations`,
|
|
37
|
+
token: p.token,
|
|
38
|
+
env: resolveEnv(),
|
|
39
|
+
project: p.project,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// -- Native platform-gateway clients -----------------------------------------------------------
|
|
43
|
+
export function platform(profile) {
|
|
44
|
+
return new Platform(platformOptions(profile));
|
|
45
|
+
}
|
|
46
|
+
export function workflow(profile) {
|
|
47
|
+
return new Workflow(platformOptions(profile));
|
|
48
|
+
}
|
|
49
|
+
export function sandbox(profile) {
|
|
50
|
+
return new Sandbox(platformOptions(profile));
|
|
51
|
+
}
|
|
52
|
+
export function ratchet(profile) {
|
|
53
|
+
return new Ratchet(platformOptions(profile));
|
|
54
|
+
}
|
|
55
|
+
export function thunder(profile) {
|
|
56
|
+
return new Thunder(platformOptions(profile));
|
|
57
|
+
}
|
|
58
|
+
export function project(profile) {
|
|
59
|
+
return new Project(platformOptions(profile));
|
|
60
|
+
}
|
|
61
|
+
export function config(profile) {
|
|
62
|
+
return new Config(platformOptions(profile));
|
|
63
|
+
}
|
|
64
|
+
/** Kortex is proxied through the platform gateway (`/luma/kortex/v1/...`), not the integrations
|
|
65
|
+
* gateway — despite the name, it is not an "integration". */
|
|
66
|
+
export function kortex(profile) {
|
|
67
|
+
return new Kortex(platformOptions(profile));
|
|
68
|
+
}
|
|
69
|
+
// -- Integrations-gateway clients --------------------------------------------------------------
|
|
70
|
+
export function integrations(profile) {
|
|
71
|
+
return new Integrations(integrationsOptions(profile));
|
|
72
|
+
}
|
|
73
|
+
export function payments(profile) {
|
|
74
|
+
return new Payments(integrationsOptions(profile));
|
|
75
|
+
}
|
|
76
|
+
export function mail(profile) {
|
|
77
|
+
return new Mail(integrationsOptions(profile));
|
|
78
|
+
}
|
|
79
|
+
export function dms(profile) {
|
|
80
|
+
return new DMS(integrationsOptions(profile));
|
|
81
|
+
}
|
|
82
|
+
export function timber(profile) {
|
|
83
|
+
return new Timber(integrationsOptions(profile));
|
|
84
|
+
}
|
|
85
|
+
/** Serbia MinFin (fiscalization/VPFR/NBS umbrella client — see SerbiaMinFin in the SDK). */
|
|
86
|
+
export function serbia(profile) {
|
|
87
|
+
return new SerbiaMinFin(integrationsOptions(profile));
|
|
88
|
+
}
|