skedyul 0.1.53 → 0.1.55
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/.build-stamp +1 -1
- package/dist/core/client.d.ts +19 -1
- package/dist/core/client.js +49 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/server.js +14 -1
- package/package.json +1 -1
package/dist/.build-stamp
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
1768803539794
|
package/dist/core/client.d.ts
CHANGED
|
@@ -6,9 +6,26 @@ type ClientConfig = {
|
|
|
6
6
|
apiToken: string;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Run a function with request-scoped configuration.
|
|
10
|
+
* The configuration is isolated to this async context and won't affect other requests.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const result = await runWithConfig(
|
|
15
|
+
* { baseUrl: 'https://api.skedyul.com', apiToken: 'sk_xxx' },
|
|
16
|
+
* async () => {
|
|
17
|
+
* // All SDK calls in here use the scoped config
|
|
18
|
+
* return await instance.list('model', ctx);
|
|
19
|
+
* }
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function runWithConfig<T>(config: ClientConfig, fn: () => T): T;
|
|
24
|
+
/**
|
|
25
|
+
* Configure the Skedyul client globally.
|
|
10
26
|
*
|
|
11
27
|
* Can be called to override environment variables, or to set config at runtime.
|
|
28
|
+
* Note: For multi-tenant scenarios, prefer using runWithConfig() for request-scoped config.
|
|
12
29
|
*
|
|
13
30
|
* @example
|
|
14
31
|
* ```ts
|
|
@@ -23,6 +40,7 @@ type ClientConfig = {
|
|
|
23
40
|
export declare function configure(options: Partial<ClientConfig>): void;
|
|
24
41
|
/**
|
|
25
42
|
* Get the current client configuration.
|
|
43
|
+
* Returns the effective config (request-scoped if available, otherwise global).
|
|
26
44
|
*/
|
|
27
45
|
export declare function getConfig(): Readonly<ClientConfig>;
|
|
28
46
|
type ListArgs = {
|
package/dist/core/client.js
CHANGED
|
@@ -1,16 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.instance = exports.communicationChannel = exports.workplace = void 0;
|
|
4
|
+
exports.runWithConfig = runWithConfig;
|
|
4
5
|
exports.configure = configure;
|
|
5
6
|
exports.getConfig = getConfig;
|
|
6
|
-
|
|
7
|
+
const async_hooks_1 = require("async_hooks");
|
|
8
|
+
/**
|
|
9
|
+
* AsyncLocalStorage for request-scoped configuration.
|
|
10
|
+
* This allows each request to have its own config without affecting other concurrent requests.
|
|
11
|
+
*/
|
|
12
|
+
const requestConfigStorage = new async_hooks_1.AsyncLocalStorage();
|
|
13
|
+
/**
|
|
14
|
+
* Global configuration fallback (set at module load or via configure()).
|
|
15
|
+
*/
|
|
16
|
+
let globalConfig = {
|
|
7
17
|
baseUrl: process.env.SKEDYUL_API_URL ?? process.env.SKEDYUL_NODE_URL ?? '',
|
|
8
18
|
apiToken: process.env.SKEDYUL_API_TOKEN ?? '',
|
|
9
19
|
};
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
21
|
+
* Run a function with request-scoped configuration.
|
|
22
|
+
* The configuration is isolated to this async context and won't affect other requests.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const result = await runWithConfig(
|
|
27
|
+
* { baseUrl: 'https://api.skedyul.com', apiToken: 'sk_xxx' },
|
|
28
|
+
* async () => {
|
|
29
|
+
* // All SDK calls in here use the scoped config
|
|
30
|
+
* return await instance.list('model', ctx);
|
|
31
|
+
* }
|
|
32
|
+
* );
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function runWithConfig(config, fn) {
|
|
36
|
+
return requestConfigStorage.run(config, fn);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the effective configuration for the current context.
|
|
40
|
+
* Request-scoped config takes precedence over global config.
|
|
41
|
+
*/
|
|
42
|
+
function getEffectiveConfig() {
|
|
43
|
+
// Check for request-scoped config first
|
|
44
|
+
const requestConfig = requestConfigStorage.getStore();
|
|
45
|
+
if (requestConfig?.baseUrl && requestConfig?.apiToken) {
|
|
46
|
+
return requestConfig;
|
|
47
|
+
}
|
|
48
|
+
// Fall back to global config
|
|
49
|
+
return globalConfig;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Configure the Skedyul client globally.
|
|
12
53
|
*
|
|
13
54
|
* Can be called to override environment variables, or to set config at runtime.
|
|
55
|
+
* Note: For multi-tenant scenarios, prefer using runWithConfig() for request-scoped config.
|
|
14
56
|
*
|
|
15
57
|
* @example
|
|
16
58
|
* ```ts
|
|
@@ -23,22 +65,23 @@ let config = {
|
|
|
23
65
|
* ```
|
|
24
66
|
*/
|
|
25
67
|
function configure(options) {
|
|
26
|
-
|
|
27
|
-
...
|
|
68
|
+
globalConfig = {
|
|
69
|
+
...globalConfig,
|
|
28
70
|
...options,
|
|
29
71
|
};
|
|
30
72
|
}
|
|
31
73
|
/**
|
|
32
74
|
* Get the current client configuration.
|
|
75
|
+
* Returns the effective config (request-scoped if available, otherwise global).
|
|
33
76
|
*/
|
|
34
77
|
function getConfig() {
|
|
35
|
-
return
|
|
78
|
+
return getEffectiveConfig();
|
|
36
79
|
}
|
|
37
80
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
38
81
|
// Core API Client
|
|
39
82
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
40
83
|
async function callCore(method, params) {
|
|
41
|
-
const { baseUrl, apiToken } =
|
|
84
|
+
const { baseUrl, apiToken } = getEffectiveConfig();
|
|
42
85
|
if (!baseUrl) {
|
|
43
86
|
throw new Error('Skedyul client not configured: missing baseUrl. Set SKEDYUL_API_URL environment variable or call configure().');
|
|
44
87
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './types';
|
|
|
3
3
|
export * from './schemas';
|
|
4
4
|
export { server } from './server';
|
|
5
5
|
export { z };
|
|
6
|
-
export { workplace, communicationChannel, instance, configure, getConfig, } from './core/client';
|
|
6
|
+
export { workplace, communicationChannel, instance, configure, getConfig, runWithConfig, } from './core/client';
|
|
7
7
|
export type { InstanceContext, InstanceData, InstanceMeta, InstancePagination, InstanceListResult, InstanceListArgs, } from './core/client';
|
|
8
8
|
declare const _default: {
|
|
9
9
|
z: typeof z;
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.CONFIG_FILE_NAMES = exports.getAllEnvKeys = exports.getRequiredInstallEnvKeys = exports.validateConfig = exports.loadConfig = exports.defineConfig = exports.getConfig = exports.configure = exports.instance = exports.communicationChannel = exports.workplace = exports.z = exports.server = void 0;
|
|
17
|
+
exports.CONFIG_FILE_NAMES = exports.getAllEnvKeys = exports.getRequiredInstallEnvKeys = exports.validateConfig = exports.loadConfig = exports.defineConfig = exports.runWithConfig = exports.getConfig = exports.configure = exports.instance = exports.communicationChannel = exports.workplace = exports.z = exports.server = void 0;
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
19
|
Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "communicationChannel", { enumerable: true, get:
|
|
|
27
27
|
Object.defineProperty(exports, "instance", { enumerable: true, get: function () { return client_1.instance; } });
|
|
28
28
|
Object.defineProperty(exports, "configure", { enumerable: true, get: function () { return client_1.configure; } });
|
|
29
29
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return client_1.getConfig; } });
|
|
30
|
+
Object.defineProperty(exports, "runWithConfig", { enumerable: true, get: function () { return client_1.runWithConfig; } });
|
|
30
31
|
// Default export for ESM compatibility when importing from CJS
|
|
31
32
|
exports.default = { z: zod_1.z };
|
|
32
33
|
var config_1 = require("./config");
|
package/dist/server.js
CHANGED
|
@@ -43,6 +43,7 @@ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
43
43
|
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
44
44
|
const z = __importStar(require("zod"));
|
|
45
45
|
const service_1 = require("./core/service");
|
|
46
|
+
const client_1 = require("./core/client");
|
|
46
47
|
function normalizeBilling(billing) {
|
|
47
48
|
if (!billing || typeof billing.credits !== 'number') {
|
|
48
49
|
return { credits: 0 };
|
|
@@ -350,8 +351,20 @@ function createCallToolHandler(registry, state, onMaxRequests) {
|
|
|
350
351
|
fieldValues: executionContext.fieldValues,
|
|
351
352
|
mode: executionContext.mode,
|
|
352
353
|
}, null, 2));
|
|
354
|
+
// Build request-scoped config from env passed in MCP call
|
|
355
|
+
const requestConfig = {
|
|
356
|
+
baseUrl: requestEnv.SKEDYUL_API_URL ?? process.env.SKEDYUL_API_URL ?? '',
|
|
357
|
+
apiToken: requestEnv.SKEDYUL_API_TOKEN ?? process.env.SKEDYUL_API_TOKEN ?? '',
|
|
358
|
+
};
|
|
359
|
+
console.log(' Request config:', JSON.stringify({
|
|
360
|
+
baseUrl: requestConfig.baseUrl ? '(set)' : '(empty)',
|
|
361
|
+
apiToken: requestConfig.apiToken ? '(set)' : '(empty)',
|
|
362
|
+
}, null, 2));
|
|
353
363
|
// Call handler with two arguments: (input, context)
|
|
354
|
-
|
|
364
|
+
// Wrap in runWithConfig for request-scoped SDK configuration
|
|
365
|
+
const functionResult = await (0, client_1.runWithConfig)(requestConfig, async () => {
|
|
366
|
+
return await fn(inputs, executionContext);
|
|
367
|
+
});
|
|
355
368
|
const billing = normalizeBilling(functionResult.billing);
|
|
356
369
|
return {
|
|
357
370
|
output: functionResult.output,
|