@blaxel/core 0.2.49-preview.110 → 0.2.49-preview.112
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/client/sdk.gen.js +143 -3
- package/dist/cjs/common/settings.js +2 -2
- package/dist/cjs/sandbox/index.js +1 -0
- package/dist/cjs/sandbox/interpreter.js +400 -0
- package/dist/cjs/tools/mcpTool.js +0 -4
- package/dist/cjs/types/client/sdk.gen.d.ts +41 -1
- package/dist/cjs/types/client/types.gen.d.ts +599 -16
- package/dist/cjs/types/sandbox/index.d.ts +1 -0
- package/dist/cjs/types/sandbox/interpreter.d.ts +71 -0
- package/dist/cjs-browser/.tsbuildinfo +1 -1
- package/dist/cjs-browser/client/sdk.gen.js +143 -3
- package/dist/cjs-browser/common/settings.js +2 -2
- package/dist/cjs-browser/sandbox/index.js +1 -0
- package/dist/cjs-browser/sandbox/interpreter.js +400 -0
- package/dist/cjs-browser/tools/mcpTool.js +0 -4
- package/dist/cjs-browser/types/client/sdk.gen.d.ts +41 -1
- package/dist/cjs-browser/types/client/types.gen.d.ts +599 -16
- package/dist/cjs-browser/types/sandbox/index.d.ts +1 -0
- package/dist/cjs-browser/types/sandbox/interpreter.d.ts +71 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/client/sdk.gen.js +132 -0
- package/dist/esm/common/settings.js +2 -2
- package/dist/esm/sandbox/index.js +1 -0
- package/dist/esm/sandbox/interpreter.js +396 -0
- package/dist/esm/tools/mcpTool.js +0 -4
- package/dist/esm-browser/.tsbuildinfo +1 -1
- package/dist/esm-browser/client/sdk.gen.js +132 -0
- package/dist/esm-browser/common/settings.js +2 -2
- package/dist/esm-browser/sandbox/index.js +1 -0
- package/dist/esm-browser/sandbox/interpreter.js +396 -0
- package/dist/esm-browser/tools/mcpTool.js +0 -4
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.checkWorkspaceAvailability = exports.leaveWorkspace = exports.acceptWorkspaceInvitation = exports.declineWorkspaceInvitation = void 0;
|
|
4
|
+
exports.listModelRevisions = exports.updateModel = exports.getModel = exports.deleteModel = exports.createModel = exports.listModels = exports.listMcpHubDefinitions = exports.listLocations = exports.listJobRevisions = exports.getJobExecution = exports.deleteJobExecution = exports.createJobExecution = exports.listJobExecutions = exports.updateJob = exports.getJob = exports.deleteJob = exports.createJob = exports.listJobs = exports.getIntegrationConnectionModel = exports.listIntegrationConnectionModels = exports.getIntegrationConnectionModelEndpointConfigurations = exports.updateIntegrationConnection = exports.getIntegrationConnection = exports.deleteIntegrationConnection = exports.createIntegrationConnection = exports.listIntegrationConnections = exports.getIntegration = exports.deleteImageTag = exports.getImage = exports.deleteImage = exports.listImages = exports.listFunctionRevisions = exports.updateFunction = exports.getFunction = exports.deleteFunction = exports.createFunction = exports.listFunctions = exports.verifyCustomDomain = exports.updateCustomDomain = exports.getCustomDomain = exports.deleteCustomDomain = exports.createCustomDomain = exports.listCustomDomains = exports.getConfiguration = exports.listAgentRevisions = exports.updateAgent = exports.getAgent = exports.deleteAgent = exports.createAgent = exports.listAgents = void 0;
|
|
5
|
+
exports.listVolumes = exports.deleteVolumeTemplateVersion = exports.updateVolumeTemplate = exports.getVolumeTemplate = exports.deleteVolumeTemplate = exports.createVolumeTemplate = exports.listVolumeTemplates = exports.updateWorkspaceUserRole = exports.removeWorkspaceUser = exports.inviteWorkspaceUser = exports.listWorkspaceUsers = exports.getTemplate = exports.listTemplates = exports.deleteApiKeyForServiceAccount = exports.createApiKeyForServiceAccount = exports.listApiKeysForServiceAccount = exports.updateWorkspaceServiceAccount = exports.deleteWorkspaceServiceAccount = exports.createWorkspaceServiceAccount = exports.getWorkspaceServiceAccounts = exports.stopSandbox = exports.startSandbox = exports.deleteSandboxPreviewToken = exports.createSandboxPreviewToken = exports.listSandboxPreviewTokens = exports.updateSandboxPreview = exports.getSandboxPreview = exports.deleteSandboxPreview = exports.createSandboxPreview = exports.listSandboxPreviews = exports.updateSandbox = exports.getSandbox = exports.deleteSandbox = exports.createSandbox = exports.listSandboxes = exports.listSandboxHubDefinitions = exports.listPublicIps = exports.listAllPendingInvitations = exports.updatePrivateClusterHealth = exports.getPrivateClusterHealth = exports.updatePrivateCluster = exports.getPrivateCluster = exports.deletePrivateCluster = exports.createPrivateCluster = exports.listPrivateClusters = exports.updatePolicy = exports.getPolicy = exports.deletePolicy = exports.createPolicy = exports.listPolicies = void 0;
|
|
6
|
+
exports.checkWorkspaceAvailability = exports.leaveWorkspace = exports.acceptWorkspaceInvitation = exports.declineWorkspaceInvitation = exports.updateWorkspace = exports.getWorkspace = exports.deleteWorkspace = exports.createWorkspace = exports.listWorkspaces = exports.getVolume = exports.deleteVolume = exports.createVolume = void 0;
|
|
7
7
|
const client_gen_1 = require("./client.gen");
|
|
8
8
|
/**
|
|
9
9
|
* List all agents
|
|
@@ -334,6 +334,74 @@ const listFunctionRevisions = (options) => {
|
|
|
334
334
|
});
|
|
335
335
|
};
|
|
336
336
|
exports.listFunctionRevisions = listFunctionRevisions;
|
|
337
|
+
/**
|
|
338
|
+
* List images
|
|
339
|
+
* Returns a list of all images in the workspace grouped by repository with tags.
|
|
340
|
+
*/
|
|
341
|
+
const listImages = (options) => {
|
|
342
|
+
return (options?.client ?? client_gen_1.client).get({
|
|
343
|
+
security: [
|
|
344
|
+
{
|
|
345
|
+
scheme: 'bearer',
|
|
346
|
+
type: 'http'
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
url: '/images',
|
|
350
|
+
...options
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
exports.listImages = listImages;
|
|
354
|
+
/**
|
|
355
|
+
* Delete image by name
|
|
356
|
+
* Deletes an image by name.
|
|
357
|
+
*/
|
|
358
|
+
const deleteImage = (options) => {
|
|
359
|
+
return (options.client ?? client_gen_1.client).delete({
|
|
360
|
+
security: [
|
|
361
|
+
{
|
|
362
|
+
scheme: 'bearer',
|
|
363
|
+
type: 'http'
|
|
364
|
+
}
|
|
365
|
+
],
|
|
366
|
+
url: '/images/{resourceType}/{imageName}',
|
|
367
|
+
...options
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
exports.deleteImage = deleteImage;
|
|
371
|
+
/**
|
|
372
|
+
* Get image by name
|
|
373
|
+
* Returns an image by name.
|
|
374
|
+
*/
|
|
375
|
+
const getImage = (options) => {
|
|
376
|
+
return (options.client ?? client_gen_1.client).get({
|
|
377
|
+
security: [
|
|
378
|
+
{
|
|
379
|
+
scheme: 'bearer',
|
|
380
|
+
type: 'http'
|
|
381
|
+
}
|
|
382
|
+
],
|
|
383
|
+
url: '/images/{resourceType}/{imageName}',
|
|
384
|
+
...options
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
exports.getImage = getImage;
|
|
388
|
+
/**
|
|
389
|
+
* Delete image tag
|
|
390
|
+
* Deletes a specific tag from an image.
|
|
391
|
+
*/
|
|
392
|
+
const deleteImageTag = (options) => {
|
|
393
|
+
return (options.client ?? client_gen_1.client).delete({
|
|
394
|
+
security: [
|
|
395
|
+
{
|
|
396
|
+
scheme: 'bearer',
|
|
397
|
+
type: 'http'
|
|
398
|
+
}
|
|
399
|
+
],
|
|
400
|
+
url: '/images/{resourceType}/{imageName}/tags/{tagName}',
|
|
401
|
+
...options
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
exports.deleteImageTag = deleteImageTag;
|
|
337
405
|
/**
|
|
338
406
|
* List integrations connections
|
|
339
407
|
* Returns integration information by name.
|
|
@@ -588,6 +656,78 @@ const updateJob = (options) => {
|
|
|
588
656
|
});
|
|
589
657
|
};
|
|
590
658
|
exports.updateJob = updateJob;
|
|
659
|
+
/**
|
|
660
|
+
* List job executions
|
|
661
|
+
* Returns a list of all executions for a job by name.
|
|
662
|
+
*/
|
|
663
|
+
const listJobExecutions = (options) => {
|
|
664
|
+
return (options.client ?? client_gen_1.client).get({
|
|
665
|
+
security: [
|
|
666
|
+
{
|
|
667
|
+
scheme: 'bearer',
|
|
668
|
+
type: 'http'
|
|
669
|
+
}
|
|
670
|
+
],
|
|
671
|
+
url: '/jobs/{jobId}/executions',
|
|
672
|
+
...options
|
|
673
|
+
});
|
|
674
|
+
};
|
|
675
|
+
exports.listJobExecutions = listJobExecutions;
|
|
676
|
+
/**
|
|
677
|
+
* Create job execution
|
|
678
|
+
* Creates a new execution for a job by name.
|
|
679
|
+
*/
|
|
680
|
+
const createJobExecution = (options) => {
|
|
681
|
+
return (options.client ?? client_gen_1.client).post({
|
|
682
|
+
security: [
|
|
683
|
+
{
|
|
684
|
+
scheme: 'bearer',
|
|
685
|
+
type: 'http'
|
|
686
|
+
}
|
|
687
|
+
],
|
|
688
|
+
url: '/jobs/{jobId}/executions',
|
|
689
|
+
...options,
|
|
690
|
+
headers: {
|
|
691
|
+
'Content-Type': 'application/json',
|
|
692
|
+
...options?.headers
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
};
|
|
696
|
+
exports.createJobExecution = createJobExecution;
|
|
697
|
+
/**
|
|
698
|
+
* Delete job execution
|
|
699
|
+
* Stop an execution for a job by name.
|
|
700
|
+
*/
|
|
701
|
+
const deleteJobExecution = (options) => {
|
|
702
|
+
return (options.client ?? client_gen_1.client).delete({
|
|
703
|
+
security: [
|
|
704
|
+
{
|
|
705
|
+
scheme: 'bearer',
|
|
706
|
+
type: 'http'
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
url: '/jobs/{jobId}/executions/{executionId}',
|
|
710
|
+
...options
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
exports.deleteJobExecution = deleteJobExecution;
|
|
714
|
+
/**
|
|
715
|
+
* Get job execution
|
|
716
|
+
* Returns an execution for a job by name.
|
|
717
|
+
*/
|
|
718
|
+
const getJobExecution = (options) => {
|
|
719
|
+
return (options.client ?? client_gen_1.client).get({
|
|
720
|
+
security: [
|
|
721
|
+
{
|
|
722
|
+
scheme: 'bearer',
|
|
723
|
+
type: 'http'
|
|
724
|
+
}
|
|
725
|
+
],
|
|
726
|
+
url: '/jobs/{jobId}/executions/{executionId}',
|
|
727
|
+
...options
|
|
728
|
+
});
|
|
729
|
+
};
|
|
730
|
+
exports.getJobExecution = getJobExecution;
|
|
591
731
|
/**
|
|
592
732
|
* List job revisions
|
|
593
733
|
* Returns revisions for a job by name.
|
|
@@ -10,7 +10,7 @@ function getPackageVersion() {
|
|
|
10
10
|
if (typeof require !== "undefined") {
|
|
11
11
|
// Try to require package.json (Node.js only, gracefully fails in browser)
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
13
|
-
const packageJson = {"version":"0.2.49-preview.
|
|
13
|
+
const packageJson = {"version":"0.2.49-preview.112","commit":"d50dddc5a1963abd22bad3b294e9f6096c3e8287"};
|
|
14
14
|
return packageJson.version || "unknown";
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
@@ -62,7 +62,7 @@ function getCommitHash() {
|
|
|
62
62
|
if (typeof require !== "undefined") {
|
|
63
63
|
// Try to require package.json and look for commit field (set during build)
|
|
64
64
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
65
|
-
const packageJson = {"version":"0.2.49-preview.
|
|
65
|
+
const packageJson = {"version":"0.2.49-preview.112","commit":"d50dddc5a1963abd22bad3b294e9f6096c3e8287"};
|
|
66
66
|
// Check for commit in various possible locations
|
|
67
67
|
const commit = packageJson.commit || packageJson.buildInfo?.commit;
|
|
68
68
|
if (commit) {
|
|
@@ -36,4 +36,5 @@ __exportStar(require("./filesystem/index.js"), exports);
|
|
|
36
36
|
__exportStar(require("./codegen/index.js"), exports);
|
|
37
37
|
__exportStar(require("./sandbox.js"), exports);
|
|
38
38
|
__exportStar(require("./types.js"), exports);
|
|
39
|
+
__exportStar(require("./interpreter.js"), exports);
|
|
39
40
|
// Re-export everything from client except ClientOptions to avoid conflict
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeInterpreter = void 0;
|
|
4
|
+
const logger_js_1 = require("../common/logger.js");
|
|
5
|
+
const settings_js_1 = require("../common/settings.js");
|
|
6
|
+
const sandbox_js_1 = require("./sandbox.js");
|
|
7
|
+
class CodeInterpreter extends sandbox_js_1.SandboxInstance {
|
|
8
|
+
static DEFAULT_IMAGE = "blaxel/jupyter-server";
|
|
9
|
+
static DEFAULT_PORTS = [
|
|
10
|
+
{ name: "jupyter", target: 8888, protocol: "HTTP" },
|
|
11
|
+
];
|
|
12
|
+
static DEFAULT_LIFECYCLE = {
|
|
13
|
+
expirationPolicies: [{ type: "ttl-idle", value: "30m", action: "delete" }],
|
|
14
|
+
};
|
|
15
|
+
_sandboxConfig;
|
|
16
|
+
constructor(sandbox) {
|
|
17
|
+
super(sandbox);
|
|
18
|
+
this._sandboxConfig = sandbox;
|
|
19
|
+
}
|
|
20
|
+
static async get(sandboxName) {
|
|
21
|
+
const base = await sandbox_js_1.SandboxInstance.get(sandboxName);
|
|
22
|
+
// Create a minimal config - the base instance already has the sandbox data
|
|
23
|
+
// We'll rely on the process property for URL/headers access
|
|
24
|
+
const config = {
|
|
25
|
+
metadata: base.metadata,
|
|
26
|
+
spec: base.spec,
|
|
27
|
+
status: base.status,
|
|
28
|
+
events: base.events,
|
|
29
|
+
};
|
|
30
|
+
return new CodeInterpreter(config);
|
|
31
|
+
}
|
|
32
|
+
static async create(sandbox, { safe = true } = {}) {
|
|
33
|
+
const payload = {
|
|
34
|
+
image: CodeInterpreter.DEFAULT_IMAGE,
|
|
35
|
+
ports: CodeInterpreter.DEFAULT_PORTS,
|
|
36
|
+
lifecycle: CodeInterpreter.DEFAULT_LIFECYCLE,
|
|
37
|
+
};
|
|
38
|
+
const allowedCopyKeys = new Set(["name", "envs", "memory", "region", "headers"]);
|
|
39
|
+
if (sandbox && typeof sandbox === "object") {
|
|
40
|
+
if (Array.isArray(sandbox)) {
|
|
41
|
+
// Skip arrays
|
|
42
|
+
}
|
|
43
|
+
else if ("metadata" in sandbox || "spec" in sandbox) {
|
|
44
|
+
// It's a Sandbox object
|
|
45
|
+
const sandboxObj = sandbox;
|
|
46
|
+
if (sandboxObj.metadata?.name) {
|
|
47
|
+
payload["name"] = sandboxObj.metadata.name;
|
|
48
|
+
}
|
|
49
|
+
if (sandboxObj.spec?.runtime) {
|
|
50
|
+
if (sandboxObj.spec.runtime.envs) {
|
|
51
|
+
payload["envs"] = sandboxObj.spec.runtime.envs;
|
|
52
|
+
}
|
|
53
|
+
if (sandboxObj.spec.runtime.memory) {
|
|
54
|
+
payload["memory"] = sandboxObj.spec.runtime.memory;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (sandboxObj.spec?.region) {
|
|
58
|
+
payload["region"] = sandboxObj.spec.region;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if ("name" in sandbox || "image" in sandbox || "memory" in sandbox) {
|
|
62
|
+
// It's a SandboxCreateConfiguration or dict-like object
|
|
63
|
+
const sandboxDict = sandbox;
|
|
64
|
+
for (const k of allowedCopyKeys) {
|
|
65
|
+
const value = sandboxDict[k];
|
|
66
|
+
if (value !== null && value !== undefined) {
|
|
67
|
+
payload[k] = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const baseInstance = await sandbox_js_1.SandboxInstance.create(payload, { safe });
|
|
73
|
+
// Create config from the instance - preserve any forceUrl/headers if provided in input
|
|
74
|
+
const config = {
|
|
75
|
+
metadata: baseInstance.metadata,
|
|
76
|
+
spec: baseInstance.spec,
|
|
77
|
+
status: baseInstance.status,
|
|
78
|
+
events: baseInstance.events,
|
|
79
|
+
};
|
|
80
|
+
// Preserve forceUrl and headers from input if it was a dict-like object
|
|
81
|
+
if (sandbox && typeof sandbox === "object" && !Array.isArray(sandbox)) {
|
|
82
|
+
if ("forceUrl" in sandbox && typeof sandbox.forceUrl === "string") {
|
|
83
|
+
config.forceUrl = sandbox.forceUrl;
|
|
84
|
+
}
|
|
85
|
+
if ("headers" in sandbox && typeof sandbox.headers === "object") {
|
|
86
|
+
config.headers = sandbox.headers;
|
|
87
|
+
}
|
|
88
|
+
if ("params" in sandbox && typeof sandbox.params === "object") {
|
|
89
|
+
config.params = sandbox.params;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return new CodeInterpreter(config);
|
|
93
|
+
}
|
|
94
|
+
get _jupyterUrl() {
|
|
95
|
+
return this.process.url;
|
|
96
|
+
}
|
|
97
|
+
static OutputMessage = class {
|
|
98
|
+
text;
|
|
99
|
+
timestamp;
|
|
100
|
+
isStderr;
|
|
101
|
+
constructor(text, timestamp, isStderr) {
|
|
102
|
+
this.text = text;
|
|
103
|
+
this.timestamp = timestamp;
|
|
104
|
+
this.isStderr = isStderr;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
static Result = class {
|
|
108
|
+
constructor(kwargs = {}) {
|
|
109
|
+
for (const [k, v] of Object.entries(kwargs)) {
|
|
110
|
+
this[k] = v;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
static ExecutionError = class {
|
|
115
|
+
name;
|
|
116
|
+
value;
|
|
117
|
+
traceback;
|
|
118
|
+
constructor(name, value, traceback) {
|
|
119
|
+
this.name = name;
|
|
120
|
+
this.value = value;
|
|
121
|
+
this.traceback = traceback;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
static Logs = class {
|
|
125
|
+
stdout = [];
|
|
126
|
+
stderr = [];
|
|
127
|
+
};
|
|
128
|
+
static Execution = class {
|
|
129
|
+
results = [];
|
|
130
|
+
logs = new CodeInterpreter.Logs();
|
|
131
|
+
error = null;
|
|
132
|
+
executionCount = null;
|
|
133
|
+
};
|
|
134
|
+
static Context = class {
|
|
135
|
+
id;
|
|
136
|
+
constructor(id) {
|
|
137
|
+
this.id = id;
|
|
138
|
+
}
|
|
139
|
+
static fromJson(data) {
|
|
140
|
+
return new CodeInterpreter.Context(String(data.id || data.context_id || ""));
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
_parseOutput(execution, output, onStdout, onStderr, onResult, onError) {
|
|
144
|
+
let data;
|
|
145
|
+
try {
|
|
146
|
+
data = JSON.parse(output);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// Fallback: treat as stdout text-only message
|
|
150
|
+
execution.logs.stdout.push(output);
|
|
151
|
+
if (onStdout) {
|
|
152
|
+
return onStdout(new CodeInterpreter.OutputMessage(output, null, false));
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
let dataType = "";
|
|
157
|
+
if (typeof data.type === "string") {
|
|
158
|
+
dataType = data.type;
|
|
159
|
+
}
|
|
160
|
+
else if (data.type !== null &&
|
|
161
|
+
data.type !== undefined &&
|
|
162
|
+
typeof data.type !== "object") {
|
|
163
|
+
const typeValue = data.type;
|
|
164
|
+
dataType = String(typeValue);
|
|
165
|
+
}
|
|
166
|
+
const restData = { ...data };
|
|
167
|
+
delete restData.type;
|
|
168
|
+
if (dataType === "result") {
|
|
169
|
+
const result = new CodeInterpreter.Result(restData);
|
|
170
|
+
execution.results.push(result);
|
|
171
|
+
if (onResult) {
|
|
172
|
+
return onResult(result);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if (dataType === "stdout") {
|
|
176
|
+
let text = "";
|
|
177
|
+
if (typeof data.text === "string") {
|
|
178
|
+
text = data.text;
|
|
179
|
+
}
|
|
180
|
+
else if (data.text !== null &&
|
|
181
|
+
data.text !== undefined &&
|
|
182
|
+
typeof data.text !== "object") {
|
|
183
|
+
const textValue = data.text;
|
|
184
|
+
text = String(textValue);
|
|
185
|
+
}
|
|
186
|
+
execution.logs.stdout.push(text);
|
|
187
|
+
if (onStdout) {
|
|
188
|
+
return onStdout(new CodeInterpreter.OutputMessage(text, typeof data.timestamp === "number" ? data.timestamp : null, false));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (dataType === "stderr") {
|
|
192
|
+
let text = "";
|
|
193
|
+
if (typeof data.text === "string") {
|
|
194
|
+
text = data.text;
|
|
195
|
+
}
|
|
196
|
+
else if (data.text !== null &&
|
|
197
|
+
data.text !== undefined &&
|
|
198
|
+
typeof data.text !== "object") {
|
|
199
|
+
const textValue = data.text;
|
|
200
|
+
text = String(textValue);
|
|
201
|
+
}
|
|
202
|
+
execution.logs.stderr.push(text);
|
|
203
|
+
if (onStderr) {
|
|
204
|
+
return onStderr(new CodeInterpreter.OutputMessage(text, typeof data.timestamp === "number" ? data.timestamp : null, true));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (dataType === "error") {
|
|
208
|
+
let errorName = "";
|
|
209
|
+
if (typeof data.name === "string") {
|
|
210
|
+
errorName = data.name;
|
|
211
|
+
}
|
|
212
|
+
else if (data.name !== null &&
|
|
213
|
+
data.name !== undefined &&
|
|
214
|
+
typeof data.name !== "object") {
|
|
215
|
+
const nameValue = data.name;
|
|
216
|
+
errorName = String(nameValue);
|
|
217
|
+
}
|
|
218
|
+
execution.error = new CodeInterpreter.ExecutionError(errorName, data.value, data.traceback);
|
|
219
|
+
if (onError) {
|
|
220
|
+
return onError(execution.error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else if (dataType === "number_of_executions") {
|
|
224
|
+
execution.executionCount =
|
|
225
|
+
typeof data.execution_count === "number" ? data.execution_count : null;
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
async runCode(code, options = {}) {
|
|
230
|
+
const { language = null, context = null, onStdout, onStderr, onResult, onError, envs = null, timeout = null, } = options;
|
|
231
|
+
const DEFAULT_TIMEOUT = 60.0;
|
|
232
|
+
if (language && context) {
|
|
233
|
+
throw new Error("You can provide context or language, but not both at the same time.");
|
|
234
|
+
}
|
|
235
|
+
const readTimeout = timeout === 0 ? null : timeout ?? DEFAULT_TIMEOUT;
|
|
236
|
+
const contextId = context?.id ?? null;
|
|
237
|
+
const body = {
|
|
238
|
+
code,
|
|
239
|
+
context_id: contextId,
|
|
240
|
+
language,
|
|
241
|
+
env_vars: envs,
|
|
242
|
+
};
|
|
243
|
+
const execution = new CodeInterpreter.Execution();
|
|
244
|
+
const headers = this._sandboxConfig.forceUrl
|
|
245
|
+
? this._sandboxConfig.headers
|
|
246
|
+
: settings_js_1.settings.headers;
|
|
247
|
+
const controller = new AbortController();
|
|
248
|
+
let timeoutId = null;
|
|
249
|
+
// Set up timeout
|
|
250
|
+
if (readTimeout !== null) {
|
|
251
|
+
timeoutId = setTimeout(() => {
|
|
252
|
+
controller.abort();
|
|
253
|
+
}, readTimeout * 1000);
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
const response = await fetch(`${this._jupyterUrl}/port/8888/execute`, {
|
|
257
|
+
method: "POST",
|
|
258
|
+
headers: {
|
|
259
|
+
...headers,
|
|
260
|
+
"Content-Type": "application/json",
|
|
261
|
+
},
|
|
262
|
+
body: JSON.stringify(body),
|
|
263
|
+
signal: controller.signal,
|
|
264
|
+
});
|
|
265
|
+
if (response.status >= 400) {
|
|
266
|
+
let bodyText = "<unavailable>";
|
|
267
|
+
try {
|
|
268
|
+
bodyText = await response.text();
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// Ignore errors
|
|
272
|
+
}
|
|
273
|
+
const method = "POST";
|
|
274
|
+
const url = `${this._jupyterUrl}/port/8888/execute`;
|
|
275
|
+
const reason = response.statusText;
|
|
276
|
+
const details = "Execution failed\n" +
|
|
277
|
+
`- method: ${method}\n- url: ${url}\n- status: ${response.status} ${reason}\n` +
|
|
278
|
+
`- response-headers: ${JSON.stringify(Object.fromEntries(response.headers.entries()))}\n- body:\n${bodyText}`;
|
|
279
|
+
logger_js_1.logger.debug(details);
|
|
280
|
+
throw new Error(details);
|
|
281
|
+
}
|
|
282
|
+
if (!response.body) {
|
|
283
|
+
throw new Error("No response body");
|
|
284
|
+
}
|
|
285
|
+
const reader = response.body.getReader();
|
|
286
|
+
const decoder = new TextDecoder();
|
|
287
|
+
let buffer = "";
|
|
288
|
+
try {
|
|
289
|
+
while (true) {
|
|
290
|
+
const result = await reader.read();
|
|
291
|
+
if (result.done)
|
|
292
|
+
break;
|
|
293
|
+
const value = result.value;
|
|
294
|
+
if (value instanceof Uint8Array) {
|
|
295
|
+
buffer += decoder.decode(value, { stream: true });
|
|
296
|
+
const lines = buffer.split(/\r?\n/);
|
|
297
|
+
buffer = lines.pop() || "";
|
|
298
|
+
for (const line of lines) {
|
|
299
|
+
if (!line)
|
|
300
|
+
continue;
|
|
301
|
+
try {
|
|
302
|
+
this._parseOutput(execution, line, onStdout, onStderr, onResult, onError);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
// Fallback: treat as stdout text-only message
|
|
306
|
+
execution.logs.stdout.push(line);
|
|
307
|
+
if (onStdout) {
|
|
308
|
+
onStdout(new CodeInterpreter.OutputMessage(line, null, false));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
reader.releaseLock();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (error &&
|
|
321
|
+
typeof error === "object" &&
|
|
322
|
+
"name" in error &&
|
|
323
|
+
error.name === "AbortError") {
|
|
324
|
+
throw new Error("Request timeout");
|
|
325
|
+
}
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
finally {
|
|
329
|
+
if (timeoutId) {
|
|
330
|
+
clearTimeout(timeoutId);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return execution;
|
|
334
|
+
}
|
|
335
|
+
async createCodeContext(options = {}) {
|
|
336
|
+
const { cwd = null, language = null, requestTimeout = null } = options;
|
|
337
|
+
const data = {};
|
|
338
|
+
if (language) {
|
|
339
|
+
data.language = language;
|
|
340
|
+
}
|
|
341
|
+
if (cwd) {
|
|
342
|
+
data.cwd = cwd;
|
|
343
|
+
}
|
|
344
|
+
const headers = this._sandboxConfig.forceUrl
|
|
345
|
+
? this._sandboxConfig.headers
|
|
346
|
+
: settings_js_1.settings.headers;
|
|
347
|
+
const controller = new AbortController();
|
|
348
|
+
let timeoutId = null;
|
|
349
|
+
if (requestTimeout !== null) {
|
|
350
|
+
timeoutId = setTimeout(() => {
|
|
351
|
+
controller.abort();
|
|
352
|
+
}, requestTimeout * 1000);
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
const response = await fetch(`${this._jupyterUrl}/port/8888/contexts`, {
|
|
356
|
+
method: "POST",
|
|
357
|
+
headers: {
|
|
358
|
+
...headers,
|
|
359
|
+
"Content-Type": "application/json",
|
|
360
|
+
},
|
|
361
|
+
body: JSON.stringify(data),
|
|
362
|
+
signal: controller.signal,
|
|
363
|
+
});
|
|
364
|
+
if (response.status >= 400) {
|
|
365
|
+
let bodyText = "<unavailable>";
|
|
366
|
+
try {
|
|
367
|
+
bodyText = await response.text();
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
// Ignore errors
|
|
371
|
+
}
|
|
372
|
+
const method = "POST";
|
|
373
|
+
const url = `${this._jupyterUrl}/port/8888/contexts`;
|
|
374
|
+
const reason = response.statusText;
|
|
375
|
+
const details = "Create context failed\n" +
|
|
376
|
+
`- method: ${method}\n- url: ${url}\n- status: ${response.status} ${reason}\n` +
|
|
377
|
+
`- response-headers: ${JSON.stringify(Object.fromEntries(response.headers.entries()))}\n- body:\n${bodyText}`;
|
|
378
|
+
logger_js_1.logger.debug(details);
|
|
379
|
+
throw new Error(details);
|
|
380
|
+
}
|
|
381
|
+
const responseData = (await response.json());
|
|
382
|
+
return CodeInterpreter.Context.fromJson(responseData);
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
if (error &&
|
|
386
|
+
typeof error === "object" &&
|
|
387
|
+
"name" in error &&
|
|
388
|
+
error.name === "AbortError") {
|
|
389
|
+
throw new Error("Request timeout");
|
|
390
|
+
}
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
if (timeoutId) {
|
|
395
|
+
clearTimeout(timeoutId);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
exports.CodeInterpreter = CodeInterpreter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
|
|
2
|
-
import type { ListAgentsData, CreateAgentData, DeleteAgentData, GetAgentData, UpdateAgentData, ListAgentRevisionsData, GetConfigurationData, ListCustomDomainsData, CreateCustomDomainData, DeleteCustomDomainData, GetCustomDomainData, UpdateCustomDomainData, VerifyCustomDomainData, ListFunctionsData, CreateFunctionData, DeleteFunctionData, GetFunctionData, UpdateFunctionData, ListFunctionRevisionsData, GetIntegrationData, ListIntegrationConnectionsData, CreateIntegrationConnectionData, DeleteIntegrationConnectionData, GetIntegrationConnectionData, UpdateIntegrationConnectionData, GetIntegrationConnectionModelEndpointConfigurationsData, ListIntegrationConnectionModelsData, GetIntegrationConnectionModelData, ListJobsData, CreateJobData, DeleteJobData, GetJobData, UpdateJobData, ListJobRevisionsData, ListLocationsData, ListMcpHubDefinitionsData, ListModelsData, CreateModelData, DeleteModelData, GetModelData, UpdateModelData, ListModelRevisionsData, ListPoliciesData, CreatePolicyData, DeletePolicyData, GetPolicyData, UpdatePolicyData, ListPrivateClustersData, CreatePrivateClusterData, DeletePrivateClusterData, GetPrivateClusterData, UpdatePrivateClusterData, GetPrivateClusterHealthData, UpdatePrivateClusterHealthData, ListAllPendingInvitationsData, ListPublicIpsData, ListSandboxHubDefinitionsData, ListSandboxesData, CreateSandboxData, DeleteSandboxData, GetSandboxData, UpdateSandboxData, ListSandboxPreviewsData, CreateSandboxPreviewData, DeleteSandboxPreviewData, GetSandboxPreviewData, UpdateSandboxPreviewData, ListSandboxPreviewTokensData, CreateSandboxPreviewTokenData, DeleteSandboxPreviewTokenData, StartSandboxData, StopSandboxData, GetWorkspaceServiceAccountsData, CreateWorkspaceServiceAccountData, DeleteWorkspaceServiceAccountData, UpdateWorkspaceServiceAccountData, ListApiKeysForServiceAccountData, CreateApiKeyForServiceAccountData, DeleteApiKeyForServiceAccountData, ListTemplatesData, GetTemplateData, ListWorkspaceUsersData, InviteWorkspaceUserData, RemoveWorkspaceUserData, UpdateWorkspaceUserRoleData, ListVolumeTemplatesData, CreateVolumeTemplateData, DeleteVolumeTemplateData, GetVolumeTemplateData, UpdateVolumeTemplateData, DeleteVolumeTemplateVersionData, ListVolumesData, CreateVolumeData, DeleteVolumeData, GetVolumeData, ListWorkspacesData, CreateWorkspaceData, DeleteWorkspaceData, GetWorkspaceData, UpdateWorkspaceData, DeclineWorkspaceInvitationData, AcceptWorkspaceInvitationData, LeaveWorkspaceData, CheckWorkspaceAvailabilityData } from './types.gen.js';
|
|
2
|
+
import type { ListAgentsData, CreateAgentData, DeleteAgentData, GetAgentData, UpdateAgentData, ListAgentRevisionsData, GetConfigurationData, ListCustomDomainsData, CreateCustomDomainData, DeleteCustomDomainData, GetCustomDomainData, UpdateCustomDomainData, VerifyCustomDomainData, ListFunctionsData, CreateFunctionData, DeleteFunctionData, GetFunctionData, UpdateFunctionData, ListFunctionRevisionsData, ListImagesData, DeleteImageData, GetImageData, DeleteImageTagData, GetIntegrationData, ListIntegrationConnectionsData, CreateIntegrationConnectionData, DeleteIntegrationConnectionData, GetIntegrationConnectionData, UpdateIntegrationConnectionData, GetIntegrationConnectionModelEndpointConfigurationsData, ListIntegrationConnectionModelsData, GetIntegrationConnectionModelData, ListJobsData, CreateJobData, DeleteJobData, GetJobData, UpdateJobData, ListJobExecutionsData, CreateJobExecutionData, DeleteJobExecutionData, GetJobExecutionData, ListJobRevisionsData, ListLocationsData, ListMcpHubDefinitionsData, ListModelsData, CreateModelData, DeleteModelData, GetModelData, UpdateModelData, ListModelRevisionsData, ListPoliciesData, CreatePolicyData, DeletePolicyData, GetPolicyData, UpdatePolicyData, ListPrivateClustersData, CreatePrivateClusterData, DeletePrivateClusterData, GetPrivateClusterData, UpdatePrivateClusterData, GetPrivateClusterHealthData, UpdatePrivateClusterHealthData, ListAllPendingInvitationsData, ListPublicIpsData, ListSandboxHubDefinitionsData, ListSandboxesData, CreateSandboxData, DeleteSandboxData, GetSandboxData, UpdateSandboxData, ListSandboxPreviewsData, CreateSandboxPreviewData, DeleteSandboxPreviewData, GetSandboxPreviewData, UpdateSandboxPreviewData, ListSandboxPreviewTokensData, CreateSandboxPreviewTokenData, DeleteSandboxPreviewTokenData, StartSandboxData, StopSandboxData, GetWorkspaceServiceAccountsData, CreateWorkspaceServiceAccountData, DeleteWorkspaceServiceAccountData, UpdateWorkspaceServiceAccountData, ListApiKeysForServiceAccountData, CreateApiKeyForServiceAccountData, DeleteApiKeyForServiceAccountData, ListTemplatesData, GetTemplateData, ListWorkspaceUsersData, InviteWorkspaceUserData, RemoveWorkspaceUserData, UpdateWorkspaceUserRoleData, ListVolumeTemplatesData, CreateVolumeTemplateData, DeleteVolumeTemplateData, GetVolumeTemplateData, UpdateVolumeTemplateData, DeleteVolumeTemplateVersionData, ListVolumesData, CreateVolumeData, DeleteVolumeData, GetVolumeData, ListWorkspacesData, CreateWorkspaceData, DeleteWorkspaceData, GetWorkspaceData, UpdateWorkspaceData, DeclineWorkspaceInvitationData, AcceptWorkspaceInvitationData, LeaveWorkspaceData, CheckWorkspaceAvailabilityData } from './types.gen.js';
|
|
3
3
|
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
|
|
4
4
|
/**
|
|
5
5
|
* You can provide a client instance returned by `createClient()` instead of
|
|
@@ -90,6 +90,26 @@ export declare const updateFunction: <ThrowOnError extends boolean = false>(opti
|
|
|
90
90
|
* Returns revisions for a function by name.
|
|
91
91
|
*/
|
|
92
92
|
export declare const listFunctionRevisions: <ThrowOnError extends boolean = false>(options: Options<ListFunctionRevisionsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").RevisionMetadata[], unknown, ThrowOnError>;
|
|
93
|
+
/**
|
|
94
|
+
* List images
|
|
95
|
+
* Returns a list of all images in the workspace grouped by repository with tags.
|
|
96
|
+
*/
|
|
97
|
+
export declare const listImages: <ThrowOnError extends boolean = false>(options?: Options<ListImagesData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").Image[], unknown, ThrowOnError>;
|
|
98
|
+
/**
|
|
99
|
+
* Delete image by name
|
|
100
|
+
* Deletes an image by name.
|
|
101
|
+
*/
|
|
102
|
+
export declare const deleteImage: <ThrowOnError extends boolean = false>(options: Options<DeleteImageData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").Image, unknown, ThrowOnError>;
|
|
103
|
+
/**
|
|
104
|
+
* Get image by name
|
|
105
|
+
* Returns an image by name.
|
|
106
|
+
*/
|
|
107
|
+
export declare const getImage: <ThrowOnError extends boolean = false>(options: Options<GetImageData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").Image, unknown, ThrowOnError>;
|
|
108
|
+
/**
|
|
109
|
+
* Delete image tag
|
|
110
|
+
* Deletes a specific tag from an image.
|
|
111
|
+
*/
|
|
112
|
+
export declare const deleteImageTag: <ThrowOnError extends boolean = false>(options: Options<DeleteImageTagData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").Image, unknown, ThrowOnError>;
|
|
93
113
|
/**
|
|
94
114
|
* List integrations connections
|
|
95
115
|
* Returns integration information by name.
|
|
@@ -160,6 +180,26 @@ export declare const getJob: <ThrowOnError extends boolean = false>(options: Opt
|
|
|
160
180
|
* Update a job by name.
|
|
161
181
|
*/
|
|
162
182
|
export declare const updateJob: <ThrowOnError extends boolean = false>(options: Options<UpdateJobData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").Job, unknown, ThrowOnError>;
|
|
183
|
+
/**
|
|
184
|
+
* List job executions
|
|
185
|
+
* Returns a list of all executions for a job by name.
|
|
186
|
+
*/
|
|
187
|
+
export declare const listJobExecutions: <ThrowOnError extends boolean = false>(options: Options<ListJobExecutionsData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").JobExecution[], unknown, ThrowOnError>;
|
|
188
|
+
/**
|
|
189
|
+
* Create job execution
|
|
190
|
+
* Creates a new execution for a job by name.
|
|
191
|
+
*/
|
|
192
|
+
export declare const createJobExecution: <ThrowOnError extends boolean = false>(options: Options<CreateJobExecutionData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").JobExecution, unknown, ThrowOnError>;
|
|
193
|
+
/**
|
|
194
|
+
* Delete job execution
|
|
195
|
+
* Stop an execution for a job by name.
|
|
196
|
+
*/
|
|
197
|
+
export declare const deleteJobExecution: <ThrowOnError extends boolean = false>(options: Options<DeleteJobExecutionData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").JobExecution, unknown, ThrowOnError>;
|
|
198
|
+
/**
|
|
199
|
+
* Get job execution
|
|
200
|
+
* Returns an execution for a job by name.
|
|
201
|
+
*/
|
|
202
|
+
export declare const getJobExecution: <ThrowOnError extends boolean = false>(options: Options<GetJobExecutionData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen.js").JobExecution, unknown, ThrowOnError>;
|
|
163
203
|
/**
|
|
164
204
|
* List job revisions
|
|
165
205
|
* Returns revisions for a job by name.
|