skedyul 1.4.11 → 1.5.2

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.
@@ -1,10 +1,4 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
2
 
9
3
  // src/index.ts
10
4
  import { z as z15 } from "zod/v4";
@@ -2025,13 +2019,13 @@ function mergeRuntimeEnv() {
2025
2019
 
2026
2020
  // src/server/utils/http.ts
2027
2021
  function readRawRequestBody(req) {
2028
- return new Promise((resolve4, reject) => {
2022
+ return new Promise((resolve3, reject) => {
2029
2023
  let body = "";
2030
2024
  req.on("data", (chunk) => {
2031
2025
  body += chunk.toString();
2032
2026
  });
2033
2027
  req.on("end", () => {
2034
- resolve4(body);
2028
+ resolve3(body);
2035
2029
  });
2036
2030
  req.on("error", reject);
2037
2031
  });
@@ -3844,7 +3838,7 @@ function printStartupLog(config, tools, port) {
3844
3838
 
3845
3839
  // src/server/route-handlers/adapters.ts
3846
3840
  function fromLambdaEvent(event2) {
3847
- const path6 = event2.path || event2.rawPath || "/";
3841
+ const path5 = event2.path || event2.rawPath || "/";
3848
3842
  const method = event2.httpMethod || event2.requestContext?.http?.method || "POST";
3849
3843
  const forwardedProto = event2.headers?.["x-forwarded-proto"] ?? event2.headers?.["X-Forwarded-Proto"];
3850
3844
  const protocol = forwardedProto ?? "https";
@@ -3852,9 +3846,9 @@ function fromLambdaEvent(event2) {
3852
3846
  const queryString = event2.queryStringParameters ? "?" + new URLSearchParams(
3853
3847
  event2.queryStringParameters
3854
3848
  ).toString() : "";
3855
- const url = `${protocol}://${host}${path6}${queryString}`;
3849
+ const url = `${protocol}://${host}${path5}${queryString}`;
3856
3850
  return {
3857
- path: path6,
3851
+ path: path5,
3858
3852
  method,
3859
3853
  headers: event2.headers,
3860
3854
  query: event2.queryStringParameters ?? {},
@@ -4404,7 +4398,7 @@ async function handleOAuthCallback(parsedBody, hooks) {
4404
4398
  }
4405
4399
 
4406
4400
  // src/server/handlers/webhook-handler.ts
4407
- function parseWebhookRequest(parsedBody, method, url, path6, headers, query, rawBody, appIdHeader, appVersionIdHeader) {
4401
+ function parseWebhookRequest(parsedBody, method, url, path5, headers, query, rawBody, appIdHeader, appVersionIdHeader) {
4408
4402
  const isEnvelope = typeof parsedBody === "object" && parsedBody !== null && "env" in parsedBody && "request" in parsedBody && "context" in parsedBody;
4409
4403
  if (isEnvelope) {
4410
4404
  const envelope = parsedBody;
@@ -4458,7 +4452,7 @@ function parseWebhookRequest(parsedBody, method, url, path6, headers, query, raw
4458
4452
  const webhookRequest = {
4459
4453
  method,
4460
4454
  url,
4461
- path: path6,
4455
+ path: path5,
4462
4456
  headers,
4463
4457
  query,
4464
4458
  body: parsedBody,
@@ -4907,9 +4901,9 @@ async function handleMcpBatchRoute(req, ctx) {
4907
4901
  }
4908
4902
  const perCallTimeoutMs = deadline ? Math.min(deadline, 25e3) : 25e3;
4909
4903
  const executeWithTimeout = async (call2, timeoutMs) => {
4910
- return new Promise(async (resolve4) => {
4904
+ return new Promise(async (resolve3) => {
4911
4905
  const timeoutHandle = setTimeout(() => {
4912
- resolve4({
4906
+ resolve3({
4913
4907
  id: call2.id,
4914
4908
  success: false,
4915
4909
  error: "Timeout",
@@ -4922,7 +4916,7 @@ async function handleMcpBatchRoute(req, ctx) {
4922
4916
  const found = findToolInRegistry(ctx.registry, toolName);
4923
4917
  if (!found) {
4924
4918
  clearTimeout(timeoutHandle);
4925
- resolve4({
4919
+ resolve3({
4926
4920
  id: call2.id,
4927
4921
  success: false,
4928
4922
  error: `Tool "${toolName}" not found`
@@ -4940,13 +4934,13 @@ async function handleMcpBatchRoute(req, ctx) {
4940
4934
  clearTimeout(timeoutHandle);
4941
4935
  const isFailure2 = "success" in toolResult && toolResult.success === false || "error" in toolResult && toolResult.error != null;
4942
4936
  if (isFailure2) {
4943
- resolve4({
4937
+ resolve3({
4944
4938
  id: call2.id,
4945
4939
  success: false,
4946
4940
  error: "error" in toolResult && toolResult.error ? typeof toolResult.error === "string" ? toolResult.error : JSON.stringify(toolResult.error) : "Tool execution failed"
4947
4941
  });
4948
4942
  } else {
4949
- resolve4({
4943
+ resolve3({
4950
4944
  id: call2.id,
4951
4945
  success: true,
4952
4946
  result: "output" in toolResult ? toolResult.output : toolResult
@@ -4954,7 +4948,7 @@ async function handleMcpBatchRoute(req, ctx) {
4954
4948
  }
4955
4949
  } catch (err) {
4956
4950
  clearTimeout(timeoutHandle);
4957
- resolve4({
4951
+ resolve3({
4958
4952
  id: call2.id,
4959
4953
  success: false,
4960
4954
  error: err instanceof Error ? err.message : String(err)
@@ -5140,21 +5134,21 @@ function createDedicatedServerInstance(config, tools, callTool, state, mcpServer
5140
5134
  return {
5141
5135
  async listen(listenPort) {
5142
5136
  const finalPort = listenPort ?? port;
5143
- return new Promise((resolve4, reject) => {
5137
+ return new Promise((resolve3, reject) => {
5144
5138
  httpServer.listen(finalPort, () => {
5145
5139
  printStartupLog(config, tools, finalPort);
5146
- resolve4();
5140
+ resolve3();
5147
5141
  });
5148
5142
  httpServer.once("error", reject);
5149
5143
  });
5150
5144
  },
5151
5145
  async close() {
5152
- return new Promise((resolve4, reject) => {
5146
+ return new Promise((resolve3, reject) => {
5153
5147
  const closable = httpServer;
5154
5148
  closable.closeAllConnections?.();
5155
5149
  httpServer.close((err) => {
5156
5150
  if (err) reject(err);
5157
- else resolve4();
5151
+ else resolve3();
5158
5152
  });
5159
5153
  });
5160
5154
  },
@@ -5509,109 +5503,14 @@ function defineNavigation(navigation) {
5509
5503
  return navigation;
5510
5504
  }
5511
5505
 
5512
- // src/config/loader.ts
5506
+ // src/config/schema-loader.ts
5513
5507
  import * as fs3 from "fs";
5514
5508
  import * as path3 from "path";
5515
5509
  import * as os from "os";
5516
- var CONFIG_FILE_NAMES = [
5517
- "skedyul.config.ts",
5518
- "skedyul.config.js",
5519
- "skedyul.config.mjs",
5520
- "skedyul.config.cjs"
5521
- ];
5522
- async function transpileTypeScript(filePath) {
5523
- const content = fs3.readFileSync(filePath, "utf-8");
5524
- const configDir = path3.dirname(path3.resolve(filePath));
5525
- let transpiled = content.replace(/import\s+type\s+\{[^}]+\}\s+from\s+['"][^'"]+['"]\s*;?\n?/g, "").replace(/import\s+\{\s*defineConfig\s*\}\s+from\s+['"]skedyul['"]\s*;?\n?/g, "").replace(/:\s*SkedyulConfig/g, "").replace(/export\s+default\s+/, "module.exports = ").replace(/defineConfig\s*\(\s*\{/, "{").replace(/\}\s*\)\s*;?\s*$/, "}");
5526
- transpiled = transpiled.replace(
5527
- /import\s+(\w+)\s+from\s+['"](\.[^'"]+)['"]\s*(?:with\s*\{[^}]*\})?/g,
5528
- (_match, varName, relativePath) => {
5529
- const absolutePath = path3.resolve(configDir, relativePath);
5530
- return `const ${varName} = require('${absolutePath.replace(/\\/g, "/")}')`;
5531
- }
5532
- );
5533
- transpiled = transpiled.replace(
5534
- /import\s+\{\s*([^}]+)\s*\}\s+from\s+['"](\.[^'"]+)['"]\s*;?\n?/g,
5535
- (_match, namedImports, relativePath) => {
5536
- const absolutePath = path3.resolve(configDir, relativePath);
5537
- return `const { ${namedImports.trim()} } = require('${absolutePath.replace(/\\/g, "/")}')
5538
- `;
5539
- }
5540
- );
5541
- transpiled = transpiled.replace(/import\s*\(\s*['"][^'"]+['"]\s*\)/g, "null");
5542
- return transpiled;
5543
- }
5544
- async function loadConfig(configPath) {
5545
- const absolutePath = path3.resolve(configPath);
5546
- if (!fs3.existsSync(absolutePath)) {
5547
- throw new Error(`Config file not found: ${absolutePath}`);
5548
- }
5549
- const isTypeScript = absolutePath.endsWith(".ts");
5550
- try {
5551
- if (isTypeScript) {
5552
- try {
5553
- const transpiled = await transpileTypeScript(absolutePath);
5554
- const tempFile = path3.join(os.tmpdir(), `skedyul-config-${Date.now()}.cjs`);
5555
- fs3.writeFileSync(tempFile, transpiled);
5556
- try {
5557
- const module2 = __require(tempFile);
5558
- const config2 = module2.default || module2;
5559
- if (!config2 || typeof config2 !== "object") {
5560
- throw new Error("Config file must export a configuration object");
5561
- }
5562
- if (!config2.name || typeof config2.name !== "string") {
5563
- throw new Error('Config must have a "name" property');
5564
- }
5565
- return config2;
5566
- } finally {
5567
- try {
5568
- fs3.unlinkSync(tempFile);
5569
- } catch {
5570
- }
5571
- }
5572
- } catch (transpileError) {
5573
- throw new Error(
5574
- `Cannot load TypeScript config metadata from ${absolutePath}: ${transpileError instanceof Error ? transpileError.message : String(transpileError)}`
5575
- );
5576
- }
5577
- }
5578
- const module = await import(
5579
- /* webpackIgnore: true */
5580
- absolutePath
5581
- );
5582
- const config = module.default || module;
5583
- if (!config || typeof config !== "object") {
5584
- throw new Error("Config file must export a configuration object");
5585
- }
5586
- if (!config.name || typeof config.name !== "string") {
5587
- throw new Error('Config must have a "name" property');
5588
- }
5589
- return config;
5590
- } catch (error) {
5591
- throw new Error(
5592
- `Failed to load config from ${configPath}: ${error instanceof Error ? error.message : String(error)}`
5593
- );
5594
- }
5595
- }
5596
- function validateConfig(config) {
5597
- const errors = [];
5598
- if (!config.name) {
5599
- errors.push("Missing required field: name");
5600
- }
5601
- if (config.computeLayer && !["serverless", "dedicated"].includes(config.computeLayer)) {
5602
- errors.push(`Invalid computeLayer: ${config.computeLayer}. Must be 'serverless' or 'dedicated'`);
5603
- }
5604
- return { valid: errors.length === 0, errors };
5605
- }
5606
5510
 
5607
- // src/config/schema-loader.ts
5511
+ // src/config/resolver.ts
5608
5512
  import * as fs4 from "fs";
5609
5513
  import * as path4 from "path";
5610
- import * as os2 from "os";
5611
-
5612
- // src/config/resolver.ts
5613
- import * as fs5 from "fs";
5614
- import * as path5 from "path";
5615
5514
 
5616
5515
  // src/config/utils.ts
5617
5516
  function getAllEnvKeys(config) {
@@ -5714,7 +5613,7 @@ function getApiToken() {
5714
5613
  const config = getConfig();
5715
5614
  return config.apiToken || process.env.SKEDYUL_API_TOKEN || "";
5716
5615
  }
5717
- async function callRateLimitApi(path6, body) {
5616
+ async function callRateLimitApi(path5, body) {
5718
5617
  const baseUrl = getApiBaseUrl();
5719
5618
  const token2 = getApiToken();
5720
5619
  if (!baseUrl || !token2) {
@@ -5722,7 +5621,7 @@ async function callRateLimitApi(path6, body) {
5722
5621
  "SKEDYUL_API_URL and SKEDYUL_API_TOKEN are required for platform queue coordination"
5723
5622
  );
5724
5623
  }
5725
- const response = await fetch(`${baseUrl}/api/internal/ratelimit/${path6}`, {
5624
+ const response = await fetch(`${baseUrl}/api/internal/ratelimit/${path5}`, {
5726
5625
  method: "POST",
5727
5626
  headers: {
5728
5627
  Authorization: `Bearer ${token2}`,
@@ -5732,11 +5631,11 @@ async function callRateLimitApi(path6, body) {
5732
5631
  });
5733
5632
  const payload = await response.json().catch(() => null);
5734
5633
  if (!response.ok || payload?.success === false) {
5735
- const message = payload?.errors?.[0]?.message ?? `Queue coordination API ${path6} failed with status ${response.status}`;
5634
+ const message = payload?.errors?.[0]?.message ?? `Queue coordination API ${path5} failed with status ${response.status}`;
5736
5635
  throw new RateLimitBackendError(message, response.status);
5737
5636
  }
5738
5637
  if (!payload?.data) {
5739
- throw new RateLimitBackendError(`Queue coordination API ${path6} returned empty data`);
5638
+ throw new RateLimitBackendError(`Queue coordination API ${path5} returned empty data`);
5740
5639
  }
5741
5640
  return payload.data;
5742
5641
  }
@@ -5863,9 +5762,9 @@ var MemoryRateLimitBackend = class {
5863
5762
  if (canAcquire(state, limits)) {
5864
5763
  return this.grant(state, queueKey, limits);
5865
5764
  }
5866
- return new Promise((resolve4, reject) => {
5765
+ return new Promise((resolve3, reject) => {
5867
5766
  const waiter = {
5868
- resolve: resolve4,
5767
+ resolve: resolve3,
5869
5768
  reject,
5870
5769
  timer: null,
5871
5770
  limits
@@ -5894,7 +5793,7 @@ var MemoryRateLimitBackend = class {
5894
5793
  if (waiter.timer) {
5895
5794
  clearTimeout(waiter.timer);
5896
5795
  }
5897
- resolve4(this.grant(state, queueKey, limits));
5796
+ resolve3(this.grant(state, queueKey, limits));
5898
5797
  return;
5899
5798
  }
5900
5799
  setTimeout(retry, Math.max(getMinTime(limits), 10));
@@ -6015,7 +5914,7 @@ function defaultShouldRetry(error, _attempt) {
6015
5914
  return false;
6016
5915
  }
6017
5916
  function sleep(ms) {
6018
- return new Promise((resolve4) => setTimeout(resolve4, ms));
5917
+ return new Promise((resolve3) => setTimeout(resolve3, ms));
6019
5918
  }
6020
5919
 
6021
5920
  // src/ratelimit/queued-fetch.ts
@@ -6295,16 +6194,16 @@ function evaluateTemplate(template, context) {
6295
6194
  const templateRegex = /\{\{\s*([^}]+)\s*\}\}/g;
6296
6195
  const singleMatch = template.match(/^\{\{\s*([^}]+)\s*\}\}$/);
6297
6196
  if (singleMatch) {
6298
- const path6 = singleMatch[1].trim();
6299
- return resolvePath(context, path6);
6197
+ const path5 = singleMatch[1].trim();
6198
+ return resolvePath(context, path5);
6300
6199
  }
6301
- return template.replace(templateRegex, (_, path6) => {
6302
- const value = resolvePath(context, path6.trim());
6200
+ return template.replace(templateRegex, (_, path5) => {
6201
+ const value = resolvePath(context, path5.trim());
6303
6202
  return value === void 0 || value === null ? "" : String(value);
6304
6203
  });
6305
6204
  }
6306
- function resolvePath(obj, path6) {
6307
- const parts = path6.split(".");
6205
+ function resolvePath(obj, path5) {
6206
+ const parts = path5.split(".");
6308
6207
  let current = obj;
6309
6208
  for (const part of parts) {
6310
6209
  if (current === null || current === void 0) {
@@ -6325,14 +6224,14 @@ function evaluateCondition(condition, context) {
6325
6224
  const expression = match[1].trim();
6326
6225
  const eqMatch = expression.match(/^(.+?)\s*==\s*['"](.+)['"]$/);
6327
6226
  if (eqMatch) {
6328
- const [, path6, expectedValue] = eqMatch;
6329
- const actualValue = resolvePath(context, path6.trim());
6227
+ const [, path5, expectedValue] = eqMatch;
6228
+ const actualValue = resolvePath(context, path5.trim());
6330
6229
  return actualValue === expectedValue;
6331
6230
  }
6332
6231
  const neqMatch = expression.match(/^(.+?)\s*!=\s*['"](.+)['"]$/);
6333
6232
  if (neqMatch) {
6334
- const [, path6, expectedValue] = neqMatch;
6335
- const actualValue = resolvePath(context, path6.trim());
6233
+ const [, path5, expectedValue] = neqMatch;
6234
+ const actualValue = resolvePath(context, path5.trim());
6336
6235
  return actualValue !== expectedValue;
6337
6236
  }
6338
6237
  const value = resolvePath(context, expression);
@@ -7574,7 +7473,6 @@ export {
7574
7473
  AuthenticationError,
7575
7474
  BaseEventPayloadSchema,
7576
7475
  BreadcrumbItemSchema,
7577
- CONFIG_FILE_NAMES,
7578
7476
  CRMCardinalitySchema,
7579
7477
  CRMContextSchema2 as CRMContextSchema,
7580
7478
  CRMDataSchema,
@@ -7840,7 +7738,6 @@ export {
7840
7738
  isTimeInPolicy,
7841
7739
  isTimeInWindowSlot2 as isTimeInWindowSlot,
7842
7740
  isWorkflowDependency,
7843
- loadConfig,
7844
7741
  matchesTrigger,
7845
7742
  parseCRMSchema,
7846
7743
  queuedFetch,
@@ -7858,7 +7755,6 @@ export {
7858
7755
  server,
7859
7756
  token,
7860
7757
  validateCRMSchema,
7861
- validateConfig,
7862
7758
  validateSkillYAML,
7863
7759
  validateWorkflowYAML,
7864
7760
  webhook,
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ declare const _default: {
14
14
  z: typeof z;
15
15
  };
16
16
  export default _default;
17
- export { defineConfig, defineModel, defineChannel, definePage, defineWorkflow, defineAgent, defineEnv, defineNavigation, loadConfig, validateConfig, CONFIG_FILE_NAMES, getAllEnvKeys, getRequiredInstallEnvKeys, } from './config';
17
+ export { defineConfig, defineModel, defineChannel, definePage, defineWorkflow, defineAgent, defineEnv, defineNavigation, getAllEnvKeys, getRequiredInstallEnvKeys, } from './config';
18
18
  export { queuedFetch, requeue, resolveQueue, createQueueHandle, queuedFetchResponse, registerQueueConfig, runWithRateLimitExecutionContext, getRateLimitExecutionContext, defaultShouldRetry, QueueContextError, QueueNotFoundError, QueuedFetchExhaustedError, RequeueOutsideContextError, RateLimitBackendError, RateLimitExceededError, } from './ratelimit';
19
19
  export type { QueueInput, QueueSelector, Lease, QueueLimits, ResolvedQueue, RateLimitExecutionContext, RateLimitBackend, QueueScope, QueueConfig, SerializableQueueConfig, QueueRegistry, } from './ratelimit';
20
20
  export { defineSchema, validateCRMSchema, parseCRMSchema, safeParseCRMSchema, } from './schemas';