skedyul 1.2.40 → 1.2.43
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/dist/cli/commands/agents.d.ts +1 -0
- package/dist/cli/commands/chat.d.ts +1 -0
- package/dist/cli/commands/crm.d.ts +1 -0
- package/dist/cli/commands/skills.d.ts +1 -0
- package/dist/cli/index.js +17636 -6197
- package/dist/cli/utils/auth.js +495 -0
- package/dist/cli/utils/mock-context.d.ts +22 -0
- package/dist/cli/utils/sse.d.ts +100 -0
- package/dist/compiler/compiler.d.ts +12 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/types.d.ts +173 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/schema-loader.d.ts +156 -0
- package/dist/config/types/model.d.ts +28 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/resolver.d.ts +51 -0
- package/dist/context/types.d.ts +217 -0
- package/dist/dedicated/server.js +60 -15
- package/dist/esm/index.mjs +9815 -458
- package/dist/events/index.d.ts +1 -0
- package/dist/events/types.d.ts +528 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +9912 -458
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/service.d.ts +78 -0
- package/dist/memory/types.d.ts +169 -0
- package/dist/schemas/agent-schema-v3.d.ts +437 -0
- package/dist/schemas/agent-schema-v3.js +539 -0
- package/dist/schemas/agent-schema-v3.mjs +497 -0
- package/dist/schemas/agent-schema.d.ts +1504 -0
- package/dist/schemas/agent-schema.js +7896 -0
- package/dist/schemas/agent-schema.mjs +7867 -0
- package/dist/schemas/crm-schema.d.ts +448 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas.d.ts +69 -36
- package/dist/server.js +60 -15
- package/dist/serverless/server.mjs +60 -15
- package/dist/skills/index.d.ts +1 -0
- package/dist/skills/types.d.ts +355 -0
- package/dist/skills/types.js +281 -0
- package/dist/skills/types.mjs +234 -0
- package/dist/triggers/index.d.ts +2 -0
- package/dist/triggers/resolver.d.ts +31 -0
- package/dist/triggers/types.d.ts +313 -0
- package/dist/types/data-blocks.d.ts +105 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/tool-response.d.ts +202 -0
- package/dist/types/tool.d.ts +157 -28
- package/dist/workflows/index.d.ts +1 -0
- package/dist/workflows/types.d.ts +295 -0
- package/package.json +19 -1
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/cli/utils/auth.ts
|
|
31
|
+
var auth_exports = {};
|
|
32
|
+
__export(auth_exports, {
|
|
33
|
+
callCliApi: () => callCliApi,
|
|
34
|
+
clearAllProfiles: () => clearAllProfiles,
|
|
35
|
+
clearCredentials: () => clearCredentials,
|
|
36
|
+
deleteProfile: () => deleteProfile,
|
|
37
|
+
ensureUniqueProfileName: () => ensureUniqueProfileName,
|
|
38
|
+
generateProfileName: () => generateProfileName,
|
|
39
|
+
getActiveProfileName: () => getActiveProfileName,
|
|
40
|
+
getConfig: () => getConfig,
|
|
41
|
+
getCredentials: () => getCredentials,
|
|
42
|
+
getLocalConfig: () => getLocalConfig,
|
|
43
|
+
getNgrokAuthtoken: () => getNgrokAuthtoken,
|
|
44
|
+
getProfile: () => getProfile,
|
|
45
|
+
getProfiles: () => getProfiles,
|
|
46
|
+
getServerUrl: () => getServerUrl,
|
|
47
|
+
listProfiles: () => listProfiles,
|
|
48
|
+
saveConfig: () => saveConfig,
|
|
49
|
+
saveCredentials: () => saveCredentials,
|
|
50
|
+
saveProfile: () => saveProfile,
|
|
51
|
+
saveProfiles: () => saveProfiles,
|
|
52
|
+
setActiveProfile: () => setActiveProfile,
|
|
53
|
+
setNgrokAuthtoken: () => setNgrokAuthtoken,
|
|
54
|
+
startOAuthCallback: () => startOAuthCallback
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(auth_exports);
|
|
57
|
+
var fs = __toESM(require("fs"));
|
|
58
|
+
var path = __toESM(require("path"));
|
|
59
|
+
var os = __toESM(require("os"));
|
|
60
|
+
var http = __toESM(require("http"));
|
|
61
|
+
var SKEDYUL_HOME_DIR = path.join(os.homedir(), ".skedyul");
|
|
62
|
+
var PROFILES_FILE = path.join(SKEDYUL_HOME_DIR, "profiles.json");
|
|
63
|
+
var CONFIG_FILE = path.join(SKEDYUL_HOME_DIR, "config.json");
|
|
64
|
+
var LEGACY_CREDENTIALS_FILE = path.join(SKEDYUL_HOME_DIR, "credentials.json");
|
|
65
|
+
var LOCAL_CONFIG_FILE = ".skedyul.local.json";
|
|
66
|
+
var DEFAULT_SERVER_URL = "https://admin.skedyul.it";
|
|
67
|
+
function ensureHomeDir() {
|
|
68
|
+
if (!fs.existsSync(SKEDYUL_HOME_DIR)) {
|
|
69
|
+
fs.mkdirSync(SKEDYUL_HOME_DIR, { recursive: true, mode: 448 });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function generateProfileName(serverUrl) {
|
|
73
|
+
try {
|
|
74
|
+
const url = new URL(serverUrl);
|
|
75
|
+
const hostname = url.hostname.toLowerCase();
|
|
76
|
+
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
77
|
+
return "local";
|
|
78
|
+
}
|
|
79
|
+
if (hostname.includes("staging")) {
|
|
80
|
+
return "staging";
|
|
81
|
+
}
|
|
82
|
+
if (hostname === "admin.skedyul.it" || hostname === "app.skedyul.com") {
|
|
83
|
+
return "production";
|
|
84
|
+
}
|
|
85
|
+
const parts = hostname.split(".");
|
|
86
|
+
if (parts.length > 0) {
|
|
87
|
+
return parts[0].replace(/[^a-z0-9-]/g, "");
|
|
88
|
+
}
|
|
89
|
+
return "default";
|
|
90
|
+
} catch {
|
|
91
|
+
return "default";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function ensureUniqueProfileName(baseName, existingProfiles) {
|
|
95
|
+
if (!existingProfiles[baseName]) {
|
|
96
|
+
return baseName;
|
|
97
|
+
}
|
|
98
|
+
let counter = 2;
|
|
99
|
+
while (existingProfiles[`${baseName}-${counter}`]) {
|
|
100
|
+
counter++;
|
|
101
|
+
}
|
|
102
|
+
return `${baseName}-${counter}`;
|
|
103
|
+
}
|
|
104
|
+
function migrateLegacyCredentials() {
|
|
105
|
+
if (!fs.existsSync(LEGACY_CREDENTIALS_FILE)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (fs.existsSync(PROFILES_FILE)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const content = fs.readFileSync(LEGACY_CREDENTIALS_FILE, "utf-8");
|
|
113
|
+
const legacy = JSON.parse(content);
|
|
114
|
+
const profileName = generateProfileName(legacy.serverUrl);
|
|
115
|
+
const profile = {
|
|
116
|
+
serverUrl: legacy.serverUrl,
|
|
117
|
+
token: legacy.token,
|
|
118
|
+
userId: legacy.userId,
|
|
119
|
+
username: legacy.username,
|
|
120
|
+
email: legacy.email,
|
|
121
|
+
expiresAt: legacy.expiresAt,
|
|
122
|
+
createdAt: legacy.createdAt
|
|
123
|
+
};
|
|
124
|
+
const profilesFile = {
|
|
125
|
+
profiles: {
|
|
126
|
+
[profileName]: profile
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
ensureHomeDir();
|
|
130
|
+
fs.writeFileSync(PROFILES_FILE, JSON.stringify(profilesFile, null, 2), {
|
|
131
|
+
mode: 384
|
|
132
|
+
});
|
|
133
|
+
const config = getConfig();
|
|
134
|
+
config.activeProfile = profileName;
|
|
135
|
+
saveConfig(config);
|
|
136
|
+
fs.unlinkSync(LEGACY_CREDENTIALS_FILE);
|
|
137
|
+
console.error(`Migrated credentials to profile: ${profileName}`);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error("Failed to migrate legacy credentials:", error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function getProfiles() {
|
|
143
|
+
migrateLegacyCredentials();
|
|
144
|
+
if (!fs.existsSync(PROFILES_FILE)) {
|
|
145
|
+
return { profiles: {} };
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const content = fs.readFileSync(PROFILES_FILE, "utf-8");
|
|
149
|
+
return JSON.parse(content);
|
|
150
|
+
} catch {
|
|
151
|
+
return { profiles: {} };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function saveProfiles(profilesFile) {
|
|
155
|
+
ensureHomeDir();
|
|
156
|
+
fs.writeFileSync(PROFILES_FILE, JSON.stringify(profilesFile, null, 2), {
|
|
157
|
+
mode: 384
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function getProfile(name) {
|
|
161
|
+
const profilesFile = getProfiles();
|
|
162
|
+
const profile = profilesFile.profiles[name];
|
|
163
|
+
if (!profile) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (profile.expiresAt) {
|
|
167
|
+
const expiresAt = new Date(profile.expiresAt);
|
|
168
|
+
if (expiresAt < /* @__PURE__ */ new Date()) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return profile;
|
|
173
|
+
}
|
|
174
|
+
function saveProfile(name, profile) {
|
|
175
|
+
const profilesFile = getProfiles();
|
|
176
|
+
profilesFile.profiles[name] = profile;
|
|
177
|
+
saveProfiles(profilesFile);
|
|
178
|
+
}
|
|
179
|
+
function deleteProfile(name) {
|
|
180
|
+
const profilesFile = getProfiles();
|
|
181
|
+
if (!profilesFile.profiles[name]) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
delete profilesFile.profiles[name];
|
|
185
|
+
saveProfiles(profilesFile);
|
|
186
|
+
const config = getConfig();
|
|
187
|
+
if (config.activeProfile === name) {
|
|
188
|
+
const remainingProfiles = Object.keys(profilesFile.profiles);
|
|
189
|
+
config.activeProfile = remainingProfiles[0] ?? void 0;
|
|
190
|
+
saveConfig(config);
|
|
191
|
+
}
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
function listProfiles() {
|
|
195
|
+
const profilesFile = getProfiles();
|
|
196
|
+
const config = getConfig();
|
|
197
|
+
const activeProfile = config.activeProfile;
|
|
198
|
+
return Object.entries(profilesFile.profiles).map(([name, profile]) => {
|
|
199
|
+
let isExpired = false;
|
|
200
|
+
if (profile.expiresAt) {
|
|
201
|
+
isExpired = new Date(profile.expiresAt) < /* @__PURE__ */ new Date();
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
name,
|
|
205
|
+
profile,
|
|
206
|
+
isActive: name === activeProfile,
|
|
207
|
+
isExpired
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function clearAllProfiles() {
|
|
212
|
+
if (fs.existsSync(PROFILES_FILE)) {
|
|
213
|
+
fs.unlinkSync(PROFILES_FILE);
|
|
214
|
+
}
|
|
215
|
+
const config = getConfig();
|
|
216
|
+
delete config.activeProfile;
|
|
217
|
+
saveConfig(config);
|
|
218
|
+
}
|
|
219
|
+
function getActiveProfileName() {
|
|
220
|
+
const config = getConfig();
|
|
221
|
+
return config.activeProfile ?? null;
|
|
222
|
+
}
|
|
223
|
+
function setActiveProfile(name) {
|
|
224
|
+
const profilesFile = getProfiles();
|
|
225
|
+
if (!profilesFile.profiles[name]) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
const config = getConfig();
|
|
229
|
+
config.activeProfile = name;
|
|
230
|
+
saveConfig(config);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
function getCredentials() {
|
|
234
|
+
const activeProfileName = getActiveProfileName();
|
|
235
|
+
if (!activeProfileName) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const profile = getProfile(activeProfileName);
|
|
239
|
+
if (!profile) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
token: profile.token,
|
|
244
|
+
userId: profile.userId,
|
|
245
|
+
username: profile.username,
|
|
246
|
+
email: profile.email,
|
|
247
|
+
serverUrl: profile.serverUrl,
|
|
248
|
+
expiresAt: profile.expiresAt,
|
|
249
|
+
createdAt: profile.createdAt
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function saveCredentials(credentials, profileName) {
|
|
253
|
+
const name = profileName ?? generateProfileName(credentials.serverUrl);
|
|
254
|
+
const profilesFile = getProfiles();
|
|
255
|
+
const finalName = profileName ? name : ensureUniqueProfileName(name, profilesFile.profiles);
|
|
256
|
+
const profile = {
|
|
257
|
+
serverUrl: credentials.serverUrl,
|
|
258
|
+
token: credentials.token,
|
|
259
|
+
userId: credentials.userId,
|
|
260
|
+
username: credentials.username,
|
|
261
|
+
email: credentials.email,
|
|
262
|
+
expiresAt: credentials.expiresAt,
|
|
263
|
+
createdAt: credentials.createdAt
|
|
264
|
+
};
|
|
265
|
+
saveProfile(finalName, profile);
|
|
266
|
+
const config = getConfig();
|
|
267
|
+
config.activeProfile = finalName;
|
|
268
|
+
saveConfig(config);
|
|
269
|
+
return finalName;
|
|
270
|
+
}
|
|
271
|
+
function clearCredentials() {
|
|
272
|
+
const activeProfileName = getActiveProfileName();
|
|
273
|
+
if (activeProfileName) {
|
|
274
|
+
deleteProfile(activeProfileName);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function getConfig() {
|
|
278
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
279
|
+
return { defaultServer: DEFAULT_SERVER_URL };
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
const content = fs.readFileSync(CONFIG_FILE, "utf-8");
|
|
283
|
+
return JSON.parse(content);
|
|
284
|
+
} catch {
|
|
285
|
+
return { defaultServer: DEFAULT_SERVER_URL };
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function saveConfig(config) {
|
|
289
|
+
ensureHomeDir();
|
|
290
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
291
|
+
}
|
|
292
|
+
function getLocalConfig() {
|
|
293
|
+
const localConfigPath = path.join(process.cwd(), LOCAL_CONFIG_FILE);
|
|
294
|
+
if (!fs.existsSync(localConfigPath)) {
|
|
295
|
+
return {};
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const content = fs.readFileSync(localConfigPath, "utf-8");
|
|
299
|
+
return JSON.parse(content);
|
|
300
|
+
} catch {
|
|
301
|
+
return {};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function getServerUrl(override) {
|
|
305
|
+
if (override) return override;
|
|
306
|
+
const localConfig = getLocalConfig();
|
|
307
|
+
if (localConfig.serverUrl) return localConfig.serverUrl;
|
|
308
|
+
const credentials = getCredentials();
|
|
309
|
+
if (credentials?.serverUrl) return credentials.serverUrl;
|
|
310
|
+
return getConfig().defaultServer;
|
|
311
|
+
}
|
|
312
|
+
function getNgrokAuthtoken() {
|
|
313
|
+
return getConfig().ngrokAuthtoken;
|
|
314
|
+
}
|
|
315
|
+
function setNgrokAuthtoken(authtoken) {
|
|
316
|
+
const config = getConfig();
|
|
317
|
+
config.ngrokAuthtoken = authtoken;
|
|
318
|
+
saveConfig(config);
|
|
319
|
+
}
|
|
320
|
+
async function startOAuthCallback(serverUrl) {
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
let timeoutId = null;
|
|
323
|
+
const cleanup = () => {
|
|
324
|
+
if (timeoutId) {
|
|
325
|
+
clearTimeout(timeoutId);
|
|
326
|
+
timeoutId = null;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const server = http.createServer((req, res) => {
|
|
330
|
+
const url = new URL(req.url ?? "/", `http://localhost`);
|
|
331
|
+
const searchParams = url.searchParams;
|
|
332
|
+
if (url.pathname === "/callback") {
|
|
333
|
+
const token = searchParams.get("token");
|
|
334
|
+
const userId = searchParams.get("userId");
|
|
335
|
+
const username = searchParams.get("username");
|
|
336
|
+
const email = searchParams.get("email");
|
|
337
|
+
const expiresAt = searchParams.get("expiresAt");
|
|
338
|
+
const error = searchParams.get("error");
|
|
339
|
+
if (error) {
|
|
340
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
341
|
+
res.end(`
|
|
342
|
+
<html>
|
|
343
|
+
<body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
344
|
+
<h1 style="color: #e53e3e;">Authentication Failed</h1>
|
|
345
|
+
<p>${error}</p>
|
|
346
|
+
<p>You can close this window.</p>
|
|
347
|
+
</body>
|
|
348
|
+
</html>
|
|
349
|
+
`);
|
|
350
|
+
cleanup();
|
|
351
|
+
server.close();
|
|
352
|
+
reject(new Error(error));
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (!token || !userId || !username || !email) {
|
|
356
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
357
|
+
res.end(`
|
|
358
|
+
<html>
|
|
359
|
+
<body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
360
|
+
<h1 style="color: #e53e3e;">Authentication Failed</h1>
|
|
361
|
+
<p>Missing required parameters in callback</p>
|
|
362
|
+
<p>You can close this window.</p>
|
|
363
|
+
</body>
|
|
364
|
+
</html>
|
|
365
|
+
`);
|
|
366
|
+
cleanup();
|
|
367
|
+
server.close();
|
|
368
|
+
reject(new Error("Missing required parameters in callback"));
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
372
|
+
res.end(`
|
|
373
|
+
<html>
|
|
374
|
+
<body style="font-family: system-ui; padding: 40px; text-align: center;">
|
|
375
|
+
<h1 style="color: #38a169;">Authentication Successful</h1>
|
|
376
|
+
<p>Logged in as <strong>${email}</strong></p>
|
|
377
|
+
<p>You can close this window and return to the terminal.</p>
|
|
378
|
+
</body>
|
|
379
|
+
</html>
|
|
380
|
+
`);
|
|
381
|
+
cleanup();
|
|
382
|
+
server.close();
|
|
383
|
+
resolve({
|
|
384
|
+
token,
|
|
385
|
+
userId,
|
|
386
|
+
username,
|
|
387
|
+
email,
|
|
388
|
+
expiresAt
|
|
389
|
+
});
|
|
390
|
+
} else {
|
|
391
|
+
res.writeHead(404);
|
|
392
|
+
res.end("Not found");
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
server.listen(0, "127.0.0.1", () => {
|
|
396
|
+
const address = server.address();
|
|
397
|
+
if (!address || typeof address === "string") {
|
|
398
|
+
cleanup();
|
|
399
|
+
reject(new Error("Failed to get server address"));
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const port = address.port;
|
|
403
|
+
const callbackUrl = `http://localhost:${port}/callback`;
|
|
404
|
+
const authUrl = `${serverUrl}/api/cli/auth?redirect=${encodeURIComponent(callbackUrl)}`;
|
|
405
|
+
console.log(`Opening browser for authentication...`);
|
|
406
|
+
console.log(`If browser doesn't open, visit: ${authUrl}`);
|
|
407
|
+
console.log(`Waiting for callback on ${callbackUrl}...`);
|
|
408
|
+
openBrowser(authUrl).catch(() => {
|
|
409
|
+
console.log(`(Could not open browser automatically)`);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
server.on("error", (err) => {
|
|
413
|
+
cleanup();
|
|
414
|
+
reject(err);
|
|
415
|
+
});
|
|
416
|
+
timeoutId = setTimeout(() => {
|
|
417
|
+
server.close();
|
|
418
|
+
reject(new Error("Authentication timed out"));
|
|
419
|
+
}, 5 * 60 * 1e3);
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
async function openBrowser(url) {
|
|
423
|
+
try {
|
|
424
|
+
const open = await import("open");
|
|
425
|
+
await open.default(url);
|
|
426
|
+
} catch {
|
|
427
|
+
const { exec } = await import("child_process");
|
|
428
|
+
const platform = process.platform;
|
|
429
|
+
let command;
|
|
430
|
+
if (platform === "darwin") {
|
|
431
|
+
command = `open "${url}"`;
|
|
432
|
+
} else if (platform === "win32") {
|
|
433
|
+
command = `start "" "${url}"`;
|
|
434
|
+
} else {
|
|
435
|
+
command = `xdg-open "${url}"`;
|
|
436
|
+
}
|
|
437
|
+
return new Promise((resolve, reject) => {
|
|
438
|
+
exec(command, (error) => {
|
|
439
|
+
if (error) reject(error);
|
|
440
|
+
else resolve();
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
async function callCliApi(options, endpoint, body) {
|
|
446
|
+
const url = `${options.serverUrl}/api/cli${endpoint}`;
|
|
447
|
+
const headers = {
|
|
448
|
+
"Content-Type": "application/json"
|
|
449
|
+
};
|
|
450
|
+
if (options.token) {
|
|
451
|
+
headers["Authorization"] = `Bearer ${options.token}`;
|
|
452
|
+
}
|
|
453
|
+
const response = await fetch(url, {
|
|
454
|
+
method: "POST",
|
|
455
|
+
headers,
|
|
456
|
+
body: body ? JSON.stringify(body) : void 0
|
|
457
|
+
});
|
|
458
|
+
if (!response.ok) {
|
|
459
|
+
const text = await response.text();
|
|
460
|
+
let message = `API error: ${response.status}`;
|
|
461
|
+
try {
|
|
462
|
+
const json = JSON.parse(text);
|
|
463
|
+
if (json.error) message = json.error;
|
|
464
|
+
} catch {
|
|
465
|
+
if (text) message = text;
|
|
466
|
+
}
|
|
467
|
+
throw new Error(message);
|
|
468
|
+
}
|
|
469
|
+
return response.json();
|
|
470
|
+
}
|
|
471
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
472
|
+
0 && (module.exports = {
|
|
473
|
+
callCliApi,
|
|
474
|
+
clearAllProfiles,
|
|
475
|
+
clearCredentials,
|
|
476
|
+
deleteProfile,
|
|
477
|
+
ensureUniqueProfileName,
|
|
478
|
+
generateProfileName,
|
|
479
|
+
getActiveProfileName,
|
|
480
|
+
getConfig,
|
|
481
|
+
getCredentials,
|
|
482
|
+
getLocalConfig,
|
|
483
|
+
getNgrokAuthtoken,
|
|
484
|
+
getProfile,
|
|
485
|
+
getProfiles,
|
|
486
|
+
getServerUrl,
|
|
487
|
+
listProfiles,
|
|
488
|
+
saveConfig,
|
|
489
|
+
saveCredentials,
|
|
490
|
+
saveProfile,
|
|
491
|
+
saveProfiles,
|
|
492
|
+
setActiveProfile,
|
|
493
|
+
setNgrokAuthtoken,
|
|
494
|
+
startOAuthCallback
|
|
495
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type MockContext } from '../../context/types';
|
|
2
|
+
/**
|
|
3
|
+
* Load mock context from a JSON file
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadMockContext(filePath: string): MockContext;
|
|
6
|
+
/**
|
|
7
|
+
* Parse a quick mock sender string
|
|
8
|
+
* Format: "Display Name:kind" or "Display Name:kind:model"
|
|
9
|
+
* Examples:
|
|
10
|
+
* "John Smith:contact"
|
|
11
|
+
* "John Smith:contact:customer"
|
|
12
|
+
* "Sarah Jones:member"
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseMockSender(input: string): MockContext['sender'];
|
|
15
|
+
/**
|
|
16
|
+
* Build a complete mock context from sender and optional contexts
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildMockContext(sender: MockContext['sender'], contexts?: MockContext['contexts']): MockContext;
|
|
19
|
+
/**
|
|
20
|
+
* Merge mock context with defaults
|
|
21
|
+
*/
|
|
22
|
+
export declare function mergeMockContext(base: Partial<MockContext>, overrides: Partial<MockContext>): MockContext;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE (Server-Sent Events) stream consumer for Node.js CLI.
|
|
3
|
+
* Parses SSE events from a fetch response stream.
|
|
4
|
+
*/
|
|
5
|
+
export interface SSEEvent {
|
|
6
|
+
data: string;
|
|
7
|
+
event?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parse SSE events from a ReadableStream.
|
|
12
|
+
* Yields parsed JSON data from each SSE event.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseSSEStream<T>(response: Response, debug?: boolean): AsyncGenerator<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetch an SSE endpoint and yield parsed events.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchSSE<T>(url: string, options?: {
|
|
19
|
+
method?: string;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
body?: string;
|
|
22
|
+
}): AsyncGenerator<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Chat event types from the CLI chat endpoint.
|
|
25
|
+
*/
|
|
26
|
+
export interface ChatEvent {
|
|
27
|
+
threadId?: string;
|
|
28
|
+
threadTitle?: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
thought?: string;
|
|
31
|
+
thoughtComplete?: boolean;
|
|
32
|
+
durationMs?: number;
|
|
33
|
+
thoughts?: Array<{
|
|
34
|
+
content: string;
|
|
35
|
+
durationMs: number;
|
|
36
|
+
}>;
|
|
37
|
+
data?: Array<{
|
|
38
|
+
type: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}>;
|
|
41
|
+
context?: Array<{
|
|
42
|
+
model?: string;
|
|
43
|
+
hint?: string;
|
|
44
|
+
id: string;
|
|
45
|
+
label: string;
|
|
46
|
+
data?: Record<string, unknown>;
|
|
47
|
+
}>;
|
|
48
|
+
toolCall?: {
|
|
49
|
+
name: string;
|
|
50
|
+
status: 'started' | 'completed' | 'failed';
|
|
51
|
+
args?: Record<string, unknown>;
|
|
52
|
+
durationMs?: number;
|
|
53
|
+
resultSummary?: string;
|
|
54
|
+
autoApproved?: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** Pending approval request for a tool that requires user confirmation */
|
|
57
|
+
pendingApproval?: {
|
|
58
|
+
toolCallId: string;
|
|
59
|
+
toolName: string;
|
|
60
|
+
displayName: string;
|
|
61
|
+
args: Record<string, unknown>;
|
|
62
|
+
};
|
|
63
|
+
/** Name of the agent currently responding (for multi-stage agent runs) */
|
|
64
|
+
agentName?: string;
|
|
65
|
+
/** Whether this event is from a child agent invocation (for visual hierarchy in CLI) */
|
|
66
|
+
isChildAgent?: boolean;
|
|
67
|
+
/** Full output from an agent stage (for debugging multi-stage pipelines) */
|
|
68
|
+
agentOutput?: string;
|
|
69
|
+
done?: boolean;
|
|
70
|
+
initial?: boolean;
|
|
71
|
+
error?: string;
|
|
72
|
+
sandbox?: boolean;
|
|
73
|
+
/** Updated mock context after tool execution (sandbox mode only) */
|
|
74
|
+
updatedMockContext?: {
|
|
75
|
+
sender: {
|
|
76
|
+
displayName?: string;
|
|
77
|
+
kind: 'contact' | 'member';
|
|
78
|
+
role?: string;
|
|
79
|
+
permissions?: string[];
|
|
80
|
+
crm?: {
|
|
81
|
+
model: string;
|
|
82
|
+
data: Record<string, unknown>;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
contexts?: Array<{
|
|
86
|
+
handle: string;
|
|
87
|
+
model: string;
|
|
88
|
+
data: Record<string, unknown>;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
/** Tool calls from this turn with their results (for accumulating tool history) */
|
|
92
|
+
toolCalls?: Array<{
|
|
93
|
+
toolCallId: string;
|
|
94
|
+
toolName: string;
|
|
95
|
+
args: Record<string, unknown>;
|
|
96
|
+
result: unknown;
|
|
97
|
+
/** Provider-specific options (e.g., Gemini's thought_signature for tool call replay) */
|
|
98
|
+
providerOptions?: Record<string, unknown>;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SkillYAML } from '../skills/types';
|
|
2
|
+
import type { AgentIR, WorkflowIR, CompilationResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Compile agent YAML to IR
|
|
5
|
+
*/
|
|
6
|
+
export declare function compileAgent(yamlContent: string, options?: {
|
|
7
|
+
skillResolver?: (handle: string) => Promise<SkillYAML | null>;
|
|
8
|
+
}): Promise<CompilationResult<AgentIR>>;
|
|
9
|
+
/**
|
|
10
|
+
* Compile workflow YAML to IR
|
|
11
|
+
*/
|
|
12
|
+
export declare function compileWorkflow(yamlContent: string): Promise<CompilationResult<WorkflowIR>>;
|