@ptkl/toolkit 0.11.0 → 1.0.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 +101 -0
- package/dist/bin/toolkit.js +0 -0
- package/dist/commands/billing.js +111 -0
- package/dist/commands/config.js +33 -0
- package/dist/commands/forge.js +731 -36
- package/dist/commands/functions.js +87 -22
- package/dist/commands/index.js +25 -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 +297 -0
- package/dist/commands/logs.js +96 -0
- 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/bridge.js +113 -0
- package/dist/lib/kortex/config.js +21 -0
- package/dist/lib/kortex/conversations.js +84 -0
- package/dist/lib/kortex/mcp.js +193 -0
- package/dist/lib/kortex/session.js +763 -0
- package/dist/lib/kortex/tools.js +406 -0
- package/dist/lib/kortex/ui/App.js +455 -0
- package/dist/lib/kortex/ui/SelectAgent.js +23 -0
- package/dist/lib/scaffold.js +51 -0
- package/dist/lib/sdk.js +88 -0
- package/package.json +11 -2
|
@@ -1,27 +1,92 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import * as sdk from "../lib/sdk.js";
|
|
5
|
+
import { registerCommand, withProfile } from "../lib/scaffold.js";
|
|
6
|
+
/** `ptkl functions` — platform function CRUD + invocation (RFC §6, "Functions").
|
|
7
|
+
* Maps onto the SDK `Functions` client (@ptkl/sdk/beta) for `list`/`get`/`update`/`run`/
|
|
8
|
+
* `signature` (`generateSignature`). The platform's `system/function` collection endpoint also
|
|
9
|
+
* supports POST for creation, but the v0.10 `Functions` client does not yet wrap that in a named
|
|
10
|
+
* method — `create` goes through the same authenticated client instance's underlying `.client`
|
|
11
|
+
* (a public AxiosInstance, see @ptkl/sdk/beta BaseClient) rather than a named method, the same
|
|
12
|
+
* stopgap pattern used by `ptkl project billing-modes`/`auto-topup`, pending a follow-up SDK WP
|
|
13
|
+
* to give `Functions` a `create()` method.
|
|
14
|
+
*
|
|
15
|
+
* Return-shape contract: every subcommand here resolves to the *payload*, never a raw
|
|
16
|
+
* AxiosResponse. `Functions.run()` already unwraps `.data` in the SDK; `list`/`get`/`update`/
|
|
17
|
+
* `generateSignature` do not (they resolve to the AxiosResponse), so this command layer unwraps
|
|
18
|
+
* `.data` itself for those — matching `create`, which reads `.data` off the raw axios call. This
|
|
19
|
+
* keeps `-f json`/`-f jsonpath`/`-f template` consistent across all six subcommands. */
|
|
20
|
+
function parseJSON(label, raw) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
console.error(`${label} must be valid JSON`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function readPayload(label, dataStr, file) {
|
|
30
|
+
if (file) {
|
|
31
|
+
return JSON.parse(readFileSync(resolve(file), "utf-8"));
|
|
15
32
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const client = new Api({ token: profile.token, host: profile.host }).function();
|
|
19
|
-
return await client.list();
|
|
33
|
+
if (dataStr) {
|
|
34
|
+
return parseJSON(label, dataStr);
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
console.error("Error: either --data or --file must be provided");
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
class FunctionsCommand {
|
|
40
|
+
register() {
|
|
41
|
+
const cmd = new Command("functions").description("Manage functions").version("0.1.0");
|
|
42
|
+
cmd.addCommand(registerCommand(new Command("list").description("List functions")).action(withProfile(async (profile) => {
|
|
43
|
+
const res = await sdk.platform(profile).function().list();
|
|
44
|
+
return res.data;
|
|
45
|
+
})));
|
|
46
|
+
cmd.addCommand(registerCommand(new Command("get")
|
|
47
|
+
.description("Get function")
|
|
48
|
+
.argument("<reference>", "Reference to the function which can be name, tag or uuid")).action(withProfile(async (profile, reference) => {
|
|
49
|
+
const res = await sdk.platform(profile).function().get(reference);
|
|
50
|
+
return res.data;
|
|
51
|
+
})));
|
|
52
|
+
cmd.addCommand(registerCommand(new Command("run")
|
|
53
|
+
.description("Run a platform function")
|
|
54
|
+
.argument("<reference>", "Reference to the function which can be name, tag or uuid")
|
|
55
|
+
.option("-i, --input <json>", "Input payload as a JSON string")
|
|
56
|
+
.option("-q, --query <json>", "Query params as a JSON object string")).action(withProfile(async (profile, reference, opts) => {
|
|
57
|
+
const { input: inputStr, query: queryStr } = opts;
|
|
58
|
+
const input = inputStr ? parseJSON("--input", inputStr) : undefined;
|
|
59
|
+
const query = queryStr ? parseJSON("--query", queryStr) : undefined;
|
|
60
|
+
return await sdk.platform(profile).function().run(reference, { input, query });
|
|
61
|
+
})));
|
|
62
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
63
|
+
.description("Create a new function")
|
|
64
|
+
.option("-d, --data <data>", "Full create payload as JSON string (overrides --file)")
|
|
65
|
+
.option("-i, --file <file>", "Path to a JSON file containing the full create payload")).action(withProfile(async (profile, opts) => {
|
|
66
|
+
const { data: dataStr, file } = opts;
|
|
67
|
+
const payload = readPayload("--data", dataStr, file);
|
|
68
|
+
const client = sdk.platform(profile).function();
|
|
69
|
+
const res = await client.client.post("/v1/system/function", payload);
|
|
70
|
+
return res.data;
|
|
71
|
+
})));
|
|
72
|
+
cmd.addCommand(registerCommand(new Command("update")
|
|
73
|
+
.description("Update an existing function")
|
|
74
|
+
.argument("<uuid>", "UUID of the function to update")
|
|
75
|
+
.option("-d, --data <data>", "Fields to update, as a JSON object string (overrides --file)")
|
|
76
|
+
.option("-i, --file <file>", "Path to a JSON file containing the fields to update")).action(withProfile(async (profile, uuid, opts) => {
|
|
77
|
+
const { data: dataStr, file } = opts;
|
|
78
|
+
const payload = readPayload("--data", dataStr, file);
|
|
79
|
+
const res = await sdk.platform(profile).function().update(uuid, payload);
|
|
80
|
+
return res.data;
|
|
81
|
+
})));
|
|
82
|
+
cmd.addCommand(registerCommand(new Command("signature")
|
|
83
|
+
.description("Generate the IDL signature for a function in a given environment")
|
|
84
|
+
.argument("<env>", "Environment to resolve the signature against, e.g. dev | live")
|
|
85
|
+
.argument("<reference>", "Reference to the function which can be name, tag or uuid")).action(withProfile(async (profile, env, reference) => {
|
|
86
|
+
const res = await sdk.platform(profile).function().generateSignature(reference, env);
|
|
87
|
+
return res.data;
|
|
88
|
+
})));
|
|
89
|
+
return cmd;
|
|
25
90
|
}
|
|
26
91
|
}
|
|
27
|
-
export default new FunctionsCommand;
|
|
92
|
+
export default new FunctionsCommand();
|
package/dist/commands/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { Command } from "commander";
|
|
|
2
2
|
// commands
|
|
3
3
|
import profile from "./profile.js";
|
|
4
4
|
import Util from "../lib/util.js";
|
|
5
|
-
import
|
|
5
|
+
import apiUsers from "./apiUsers.js";
|
|
6
|
+
import users from "./users.js";
|
|
6
7
|
import functions from "./functions.js";
|
|
7
8
|
import apps from "./apps.js";
|
|
8
9
|
import role from "./role.js";
|
|
@@ -11,8 +12,20 @@ import component from "./component.js";
|
|
|
11
12
|
import workflow from "./workflow.js";
|
|
12
13
|
import generateTypes from "./generate-types.js";
|
|
13
14
|
import validateIDL from "./validate-idl.js";
|
|
15
|
+
import kortex from "./kortex.js";
|
|
16
|
+
import logs from "./logs.js";
|
|
17
|
+
import project from "./project.js";
|
|
18
|
+
import template from "./template.js";
|
|
19
|
+
import config from "./config.js";
|
|
20
|
+
import ratchet from "./ratchet.js";
|
|
21
|
+
import thunder from "./thunder.js";
|
|
22
|
+
import sandbox from "./sandbox.js";
|
|
23
|
+
import billing from "./billing.js";
|
|
24
|
+
import integration from "./integration.js";
|
|
25
|
+
import satellite from "./satellite.js";
|
|
14
26
|
export const commands = [
|
|
15
27
|
profile.register(),
|
|
28
|
+
apiUsers.register(),
|
|
16
29
|
users.register(),
|
|
17
30
|
functions.register(),
|
|
18
31
|
apps.register(),
|
|
@@ -22,6 +35,17 @@ export const commands = [
|
|
|
22
35
|
workflow.register(),
|
|
23
36
|
generateTypes.register(),
|
|
24
37
|
validateIDL.register(),
|
|
38
|
+
logs.register(),
|
|
39
|
+
project.register(),
|
|
40
|
+
template.register(),
|
|
41
|
+
config.register(),
|
|
42
|
+
ratchet.register(),
|
|
43
|
+
thunder.register(),
|
|
44
|
+
sandbox.register(),
|
|
45
|
+
billing.register(),
|
|
46
|
+
integration.register(),
|
|
47
|
+
satellite.register(),
|
|
48
|
+
kortex.register(),
|
|
25
49
|
new Command('init')
|
|
26
50
|
.description("Init protokol toolkit")
|
|
27
51
|
.action(Util.init)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { Satellites } from "@ptkl/sdk/beta";
|
|
3
|
+
import * as sdk from "../lib/sdk.js";
|
|
4
|
+
import { registerCommand, withProfile } from "../lib/scaffold.js";
|
|
5
|
+
import payments from "./integrations/payments.js";
|
|
6
|
+
// Typed interface subtrees (WP-121…125) attach themselves via `integrationSub()` when their
|
|
7
|
+
// `register()` is invoked below — imported here (rather than from src/commands/index.ts, which is
|
|
8
|
+
// out of this WP's sanctioned paths) so `ptkl integration` stays the single wiring point for its
|
|
9
|
+
// own subtree, per the module comment above. Circular-safe: `mail` only calls back into
|
|
10
|
+
// `isActive`/`integrationSub` from inside its own `register()`, which this file invokes after
|
|
11
|
+
// both modules have finished evaluating.
|
|
12
|
+
import mail from "./integrations/mail.js";
|
|
13
|
+
import dms from "./integrations/dms.js";
|
|
14
|
+
import timber from "./integrations/timber.js";
|
|
15
|
+
import serbia from "./integrations/serbia.js";
|
|
16
|
+
/** `ptkl integration` — the integrations gateway (RFC §4.3 / §6.1). Integrations are installed +
|
|
17
|
+
* activated **per project** (subscription-gated), so they live under one namespace instead of as
|
|
18
|
+
* flat top-level commands — mirroring the SDK exactly: `Integrations` (`@ptkl/sdk/beta`) is a
|
|
19
|
+
* façade mapping an id -> typed client via `getInterfaceOf(id)`, with uniform
|
|
20
|
+
* `list()`/`isInstalled()`/`isActive()`.
|
|
21
|
+
*
|
|
22
|
+
* Three invocation layers (RFC §6.1):
|
|
23
|
+
* 1. Lifecycle (this file) — uniform for every integration: list/install/uninstall/
|
|
24
|
+
* activate/deactivate/onboarding/marketplace/explore.
|
|
25
|
+
* 2. Typed interfaces (WP-121…125: payments/mail/dms/timber/serbia) — attached to the shared
|
|
26
|
+
* `integration` command via `integrationSub()` below.
|
|
27
|
+
* 3. Generic passthrough (this file's `run`) — satellite JSON-RPC execute, for satellites and
|
|
28
|
+
* anything without a typed client. Same door as `ptkl satellite execute`.
|
|
29
|
+
*/
|
|
30
|
+
// The shared `integration` command instance. Built once at module load so later interface
|
|
31
|
+
// subtrees (WP-121…125) can attach to it regardless of module-import order — see `integrationSub`.
|
|
32
|
+
const integrationCommand = new Command("integration").description("Manage platform integrations: lifecycle (install/activate/…), typed interfaces and generic run");
|
|
33
|
+
/** Shared attach point for the typed interface subtrees added by later WPs (payments/mail/dms/
|
|
34
|
+
* timber/serbia — WP-121…125). Each of those WPs builds its own `Command` (e.g. `new
|
|
35
|
+
* Command("payments")...`) the same way any other command group is built, then calls
|
|
36
|
+
* `integrationSub(cmd)` once to graft it onto `ptkl integration` — instead of editing this file.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* // src/commands/integration/payments.ts
|
|
40
|
+
* import { integrationSub } from "../integration.js";
|
|
41
|
+
* const cmd = new Command("payments").description("...");
|
|
42
|
+
* cmd.addCommand(...);
|
|
43
|
+
* integrationSub(cmd);
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Returns the same command that was passed in, so the call can be chained/exported if useful. */
|
|
47
|
+
export function integrationSub(sub) {
|
|
48
|
+
integrationCommand.addCommand(sub);
|
|
49
|
+
return sub;
|
|
50
|
+
}
|
|
51
|
+
function parseJSON(label, raw) {
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(raw);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
console.error(`${label} must be valid JSON`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function satellites(profile) {
|
|
61
|
+
return new Satellites(sdk.integrationsOptions(profile));
|
|
62
|
+
}
|
|
63
|
+
/** Precheck used by the typed interface subcommands (WP-121…125) before calling through to a
|
|
64
|
+
* provider. Installed-but-inactive integrations 403 at the API; this turns that into the friendly
|
|
65
|
+
* hint from RFC §6.1 instead, so the install/activate requirement is discoverable rather than
|
|
66
|
+
* surfacing as a raw 403. Exits the process (matching `withProfile`'s error handling) when the
|
|
67
|
+
* integration isn't active for the current project. */
|
|
68
|
+
export async function isActive(profile, id) {
|
|
69
|
+
const active = await sdk.integrations(profile).isActive(id);
|
|
70
|
+
if (!active) {
|
|
71
|
+
console.error(`${id} is not active for this project — run \`ptkl integration activate ${id}\``);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
class IntegrationCommand {
|
|
76
|
+
register() {
|
|
77
|
+
const cmd = integrationCommand;
|
|
78
|
+
cmd.addCommand(registerCommand(new Command("list").description("List integrations installed on the current project")).action(withProfile(async (profile) => {
|
|
79
|
+
return await sdk.integrations(profile).list();
|
|
80
|
+
})));
|
|
81
|
+
cmd.addCommand(registerCommand(new Command("install")
|
|
82
|
+
.description("Install an integration on the current project")
|
|
83
|
+
.argument("<id>", "Integration id, e.g. protokol-payments")
|
|
84
|
+
.option("-d, --data <json>", "Optional install-time configuration payload as a JSON string")).action(withProfile(async (profile, id, opts) => {
|
|
85
|
+
const data = opts.data ? parseJSON("--data", opts.data) : undefined;
|
|
86
|
+
return await sdk.integrations(profile).install(id, data);
|
|
87
|
+
})));
|
|
88
|
+
cmd.addCommand(registerCommand(new Command("uninstall")
|
|
89
|
+
.description("Uninstall an integration from the current project")
|
|
90
|
+
.argument("<id>", "Integration id")).action(withProfile(async (profile, id) => {
|
|
91
|
+
return await sdk.integrations(profile).uninstall(id);
|
|
92
|
+
})));
|
|
93
|
+
cmd.addCommand(registerCommand(new Command("activate")
|
|
94
|
+
.description("Activate an installed integration")
|
|
95
|
+
.argument("<id>", "Integration id")).action(withProfile(async (profile, id) => {
|
|
96
|
+
return await sdk.integrations(profile).activate(id);
|
|
97
|
+
})));
|
|
98
|
+
cmd.addCommand(registerCommand(new Command("deactivate")
|
|
99
|
+
.description("Deactivate an installed integration")
|
|
100
|
+
.argument("<id>", "Integration id")).action(withProfile(async (profile, id) => {
|
|
101
|
+
return await sdk.integrations(profile).deactivate(id);
|
|
102
|
+
})));
|
|
103
|
+
cmd.addCommand(registerCommand(new Command("onboarding")
|
|
104
|
+
.description("Advance/update the onboarding state of an installed integration")
|
|
105
|
+
.argument("<id>", "Integration id")
|
|
106
|
+
.requiredOption("-s, --step <step>", "Onboarding step id")
|
|
107
|
+
.option("-d, --data <json>", "Optional step payload as a JSON string")).action(withProfile(async (profile, id, opts) => {
|
|
108
|
+
const data = opts.data ? parseJSON("--data", opts.data) : undefined;
|
|
109
|
+
return await sdk.integrations(profile).onboarding(id, {
|
|
110
|
+
step: opts.step,
|
|
111
|
+
...(data !== undefined ? { data } : {}),
|
|
112
|
+
});
|
|
113
|
+
})));
|
|
114
|
+
cmd.addCommand(registerCommand(new Command("marketplace").description("List marketplace-available integrations (subscription/geo aware)")).action(withProfile(async (profile) => {
|
|
115
|
+
return await sdk.integrations(profile).marketplace();
|
|
116
|
+
})));
|
|
117
|
+
cmd.addCommand(registerCommand(new Command("explore").description("List explorable integration templates (subscription/geo aware)")).action(withProfile(async (profile) => {
|
|
118
|
+
return await sdk.integrations(profile).explore();
|
|
119
|
+
})));
|
|
120
|
+
cmd.addCommand(this.registerRun());
|
|
121
|
+
// Typed interface subtrees (WP-121…125) — each grafts itself onto `cmd` via
|
|
122
|
+
// `integrationSub()` when its own `.register()` runs.
|
|
123
|
+
payments.register();
|
|
124
|
+
mail.register();
|
|
125
|
+
dms.register();
|
|
126
|
+
timber.register();
|
|
127
|
+
serbia.register();
|
|
128
|
+
return cmd;
|
|
129
|
+
}
|
|
130
|
+
/** Generic passthrough: `ptkl integration run <id> <method> --params '{"inputs":{…}}'` ->
|
|
131
|
+
* `satellites/{id}/commands/{method}/execute` (JSON-RPC 2.0). Same door as `ptkl satellite
|
|
132
|
+
* execute` (RFC §6.1, layer 3) — the fallback for satellites and any provider without a typed
|
|
133
|
+
* client. */
|
|
134
|
+
registerRun() {
|
|
135
|
+
return registerCommand(new Command("run")
|
|
136
|
+
.description("Invoke a satellite command on an integration (generic JSON-RPC passthrough)")
|
|
137
|
+
.argument("<id>", "Integration/satellite id")
|
|
138
|
+
.argument("<method>", "Command name to execute")
|
|
139
|
+
.option("-p, --params <json>", "Execute payload as a JSON string ({ inputs, context, session, caller_prn }), defaults to {}")).action(withProfile(async (profile, id, method, opts) => {
|
|
140
|
+
await isActive(profile, id);
|
|
141
|
+
const payload = opts.params ? parseJSON("--params", opts.params) : {};
|
|
142
|
+
return await satellites(profile).execute(id, method, payload);
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export default new IntegrationCommand();
|