@alibaba-group/opensandbox-code-interpreter 0.1.0 → 0.1.1-dev0
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/adapters/codesAdapter.js +1 -0
- package/dist/adapters/codesAdapter.js.map +1 -0
- package/dist/adapters/openapiError.js +1 -0
- package/dist/adapters/openapiError.js.map +1 -0
- package/dist/adapters/sse.js +1 -0
- package/dist/adapters/sse.js.map +1 -0
- package/dist/factory/adapterFactory.js +1 -0
- package/dist/factory/adapterFactory.js.map +1 -0
- package/dist/factory/defaultAdapterFactory.js +1 -0
- package/dist/factory/defaultAdapterFactory.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/interpreter.js +1 -0
- package/dist/interpreter.js.map +1 -0
- package/dist/models.js +1 -0
- package/dist/models.js.map +1 -0
- package/dist/services/codes.js +1 -0
- package/dist/services/codes.js.map +1 -0
- package/package.json +4 -3
- package/src/adapters/codesAdapter.ts +188 -0
- package/src/adapters/openapiError.ts +44 -0
- package/src/adapters/sse.ts +90 -0
- package/src/factory/adapterFactory.ts +28 -0
- package/src/factory/defaultAdapterFactory.ts +39 -0
- package/src/index.ts +34 -0
- package/src/interpreter.ts +64 -0
- package/src/models.ts +35 -0
- package/src/services/codes.ts +49 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codesAdapter.js","sourceRoot":"","sources":["../../src/adapters/codesAdapter.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAIpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC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ACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultAdapterFactory.js","sourceRoot":"","sources":["../../src/factory/defaultAdapterFactory.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,MAAM,OAAO,qBAAqB;IAChC,WAAW,CAAC,IAA6B;QACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC;YAC/B,OAAO,EAAE,IAAI,CAAC,YAAY;YAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO;YAC9C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK;SAC3C,CAAC,CAAC;QAEH,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE;YAC9B,OAAO,EAAE,IAAI,CAAC,YAAY;YAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO;YAC9C,gFAAgF;YAChF,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ;SAC9C,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B;IACzC,OAAO,IAAI,qBAAqB,EAAE,CAAC;AACrC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,3 +14,4 @@
|
|
|
14
14
|
export { CodeInterpreter } from "./interpreter.js";
|
|
15
15
|
export { DefaultAdapterFactory, createDefaultAdapterFactory } from "./factory/defaultAdapterFactory.js";
|
|
16
16
|
export { SupportedLanguage as SupportedLanguages } from "./models.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAGxG,OAAO,EAAE,iBAAiB,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/interpreter.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interpreter.js","sourceRoot":"","sources":["../src/interpreter.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAQjF;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAEf;IACA;IAFX,YACW,OAAgB,EAChB,KAAY;QADZ,YAAO,GAAP,OAAO,CAAS;QAChB,UAAK,GAAL,KAAK,CAAO;IACpB,CAAC;IAEJ,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAgB,EAAE,OAAqC,EAAE;QAC3E,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;QACtE,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,2BAA2B,EAAE,CAAC;QAC5E,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;QAEpE,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;IAC9B,CAAC;CACF"}
|
package/dist/models.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,IAAI;IACR,UAAU,EAAE,YAAY;IACxB,UAAU,EAAE,YAAY;IACxB,IAAI,EAAE,MAAM;CACJ,CAAC"}
|
package/dist/services/codes.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/services/codes.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alibaba-group/opensandbox-code-interpreter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-dev0",
|
|
4
4
|
"description": "OpenSandbox Code Interpreter TypeScript/JavaScript SDK",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/alibaba/OpenSandbox",
|
|
25
25
|
"files": [
|
|
26
|
-
"dist"
|
|
26
|
+
"dist",
|
|
27
|
+
"src"
|
|
27
28
|
],
|
|
28
29
|
"engines": {
|
|
29
30
|
"node": ">=20"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@alibaba-group/opensandbox": "^0.1.
|
|
33
|
+
"@alibaba-group/opensandbox": "^0.1.1-dev0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@eslint/js": "^9.39.2",
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import type { ExecdClient, ExecdPaths } from "@alibaba-group/opensandbox/internal";
|
|
16
|
+
import type { ServerStreamEvent } from "@alibaba-group/opensandbox";
|
|
17
|
+
import type { Execution, ExecutionHandlers } from "@alibaba-group/opensandbox";
|
|
18
|
+
import {
|
|
19
|
+
ExecutionEventDispatcher,
|
|
20
|
+
InvalidArgumentException,
|
|
21
|
+
} from "@alibaba-group/opensandbox";
|
|
22
|
+
|
|
23
|
+
import type { Codes } from "../services/codes.js";
|
|
24
|
+
import type { CodeContext, SupportedLanguage } from "../models.js";
|
|
25
|
+
import { throwOnOpenApiFetchError } from "./openapiError.js";
|
|
26
|
+
import { parseJsonEventStream } from "./sse.js";
|
|
27
|
+
|
|
28
|
+
type ApiCreateContextRequest =
|
|
29
|
+
ExecdPaths["/code/context"]["post"]["requestBody"]["content"]["application/json"];
|
|
30
|
+
type ApiCreateContextOk =
|
|
31
|
+
ExecdPaths["/code/context"]["post"]["responses"][200]["content"]["application/json"];
|
|
32
|
+
type ApiGetContextOk =
|
|
33
|
+
ExecdPaths["/code/contexts/{context_id}"]["get"]["responses"][200]["content"]["application/json"];
|
|
34
|
+
type ApiListContextsOk =
|
|
35
|
+
ExecdPaths["/code/contexts"]["get"]["responses"][200]["content"]["application/json"];
|
|
36
|
+
type ApiRunCodeRequest =
|
|
37
|
+
ExecdPaths["/code"]["post"]["requestBody"]["content"]["application/json"];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Single-layer codes adapter for the Code Interpreter SDK.
|
|
41
|
+
*
|
|
42
|
+
* - Handles HTTP/SSE streaming via the underlying execd adapter
|
|
43
|
+
* - Builds the structured {@link Execution} result for `run(...)`
|
|
44
|
+
*/
|
|
45
|
+
function joinUrl(baseUrl: string, pathname: string): string {
|
|
46
|
+
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
47
|
+
const path = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
48
|
+
return `${base}${path}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class CodesAdapter implements Codes {
|
|
52
|
+
private readonly fetch: typeof fetch;
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
private readonly client: ExecdClient,
|
|
56
|
+
private readonly opts: { baseUrl: string; fetch?: typeof fetch; headers?: Record<string, string> },
|
|
57
|
+
) {
|
|
58
|
+
this.fetch = opts.fetch ?? fetch;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async createContext(language: SupportedLanguage): Promise<CodeContext> {
|
|
62
|
+
const body: ApiCreateContextRequest = { language };
|
|
63
|
+
const { data, error, response } = await this.client.POST("/code/context", {
|
|
64
|
+
body,
|
|
65
|
+
});
|
|
66
|
+
throwOnOpenApiFetchError({ error, response }, "Create code context failed");
|
|
67
|
+
const ok = data as ApiCreateContextOk | undefined;
|
|
68
|
+
if (!ok || typeof ok !== "object") {
|
|
69
|
+
throw new Error("Create code context failed: unexpected response shape");
|
|
70
|
+
}
|
|
71
|
+
if (typeof ok.language !== "string" || !ok.language) {
|
|
72
|
+
throw new Error("Create code context failed: missing language");
|
|
73
|
+
}
|
|
74
|
+
return { id: ok.id, language: ok.language };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async getContext(contextId: string): Promise<CodeContext> {
|
|
78
|
+
if (!contextId?.trim()) {
|
|
79
|
+
throw new InvalidArgumentException({ message: "contextId cannot be empty" });
|
|
80
|
+
}
|
|
81
|
+
const { data, error, response } = await this.client.GET("/code/contexts/{context_id}", {
|
|
82
|
+
params: { path: { context_id: contextId } },
|
|
83
|
+
});
|
|
84
|
+
throwOnOpenApiFetchError({ error, response }, "Get code context failed");
|
|
85
|
+
const ok = data as ApiGetContextOk | undefined;
|
|
86
|
+
if (!ok || typeof ok !== "object") {
|
|
87
|
+
throw new Error("Get code context failed: unexpected response shape");
|
|
88
|
+
}
|
|
89
|
+
if (typeof (ok as any).language !== "string" || !(ok as any).language) {
|
|
90
|
+
throw new Error("Get code context failed: missing language");
|
|
91
|
+
}
|
|
92
|
+
return { id: (ok as any).id, language: (ok as any).language };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async listContexts(language?: SupportedLanguage): Promise<CodeContext[]> {
|
|
96
|
+
const { data, error, response } = await this.client.GET("/code/contexts", {
|
|
97
|
+
params: language ? { query: { language } } : undefined,
|
|
98
|
+
} as any);
|
|
99
|
+
throwOnOpenApiFetchError({ error, response }, "List code contexts failed");
|
|
100
|
+
const ok = data as ApiListContextsOk | undefined;
|
|
101
|
+
if (!Array.isArray(ok)) {
|
|
102
|
+
throw new Error("List code contexts failed: unexpected response shape");
|
|
103
|
+
}
|
|
104
|
+
return ok
|
|
105
|
+
.filter((c) => c && typeof c === "object")
|
|
106
|
+
.map((c: any) => ({ id: c.id, language: c.language as any }));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async deleteContext(contextId: string): Promise<void> {
|
|
110
|
+
if (!contextId?.trim()) {
|
|
111
|
+
throw new InvalidArgumentException({ message: "contextId cannot be empty" });
|
|
112
|
+
}
|
|
113
|
+
const { error, response } = await this.client.DELETE("/code/contexts/{context_id}", {
|
|
114
|
+
params: { path: { context_id: contextId } },
|
|
115
|
+
});
|
|
116
|
+
throwOnOpenApiFetchError({ error, response }, "Delete code context failed");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async deleteContexts(language: SupportedLanguage): Promise<void> {
|
|
120
|
+
const { error, response } = await this.client.DELETE("/code/contexts", {
|
|
121
|
+
params: { query: { language } },
|
|
122
|
+
});
|
|
123
|
+
throwOnOpenApiFetchError({ error, response }, "Delete code contexts failed");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async interrupt(contextId: string): Promise<void> {
|
|
127
|
+
const { error, response } = await this.client.DELETE("/code", {
|
|
128
|
+
params: { query: { id: contextId } },
|
|
129
|
+
});
|
|
130
|
+
throwOnOpenApiFetchError({ error, response }, "Interrupt code failed");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async *runStream(req: ApiRunCodeRequest, signal?: AbortSignal): AsyncIterable<ServerStreamEvent> {
|
|
134
|
+
const url = joinUrl(this.opts.baseUrl, "/code");
|
|
135
|
+
const body = JSON.stringify(req);
|
|
136
|
+
const res = await this.fetch(url, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: {
|
|
139
|
+
"accept": "text/event-stream",
|
|
140
|
+
"content-type": "application/json",
|
|
141
|
+
...(this.opts.headers ?? {}),
|
|
142
|
+
},
|
|
143
|
+
body,
|
|
144
|
+
signal,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
for await (const ev of parseJsonEventStream<ServerStreamEvent>(res, { fallbackErrorMessage: "Run code failed" })) {
|
|
148
|
+
yield ev;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async run(
|
|
153
|
+
code: string,
|
|
154
|
+
opts: { context?: CodeContext; language?: SupportedLanguage; handlers?: ExecutionHandlers; signal?: AbortSignal } = {},
|
|
155
|
+
): Promise<Execution> {
|
|
156
|
+
if (!code.trim()) {
|
|
157
|
+
throw new InvalidArgumentException({ message: "Code cannot be empty" });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (opts.context && opts.language) {
|
|
161
|
+
throw new InvalidArgumentException({ message: "Provide either opts.context or opts.language, not both" });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const context: CodeContext =
|
|
165
|
+
opts.context ??
|
|
166
|
+
(opts.language
|
|
167
|
+
? { language: opts.language }
|
|
168
|
+
: { language: "python" });
|
|
169
|
+
|
|
170
|
+
// Make the OpenAPI contract explicit so backend schema changes surface quickly.
|
|
171
|
+
const req: ApiRunCodeRequest = {
|
|
172
|
+
code,
|
|
173
|
+
context: { id: context.id, language: context.language },
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const execution: Execution = {
|
|
177
|
+
logs: { stdout: [], stderr: [] },
|
|
178
|
+
result: [],
|
|
179
|
+
};
|
|
180
|
+
const dispatcher = new ExecutionEventDispatcher(execution, opts.handlers);
|
|
181
|
+
|
|
182
|
+
for await (const ev of this.runStream(req, opts.signal)) {
|
|
183
|
+
await dispatcher.dispatch(ev as any);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return execution;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { SandboxApiException, SandboxError } from "@alibaba-group/opensandbox";
|
|
16
|
+
|
|
17
|
+
export function throwOnOpenApiFetchError(
|
|
18
|
+
result: { error?: unknown; response: Response },
|
|
19
|
+
fallbackMessage: string,
|
|
20
|
+
): void {
|
|
21
|
+
if (!result.error) return;
|
|
22
|
+
|
|
23
|
+
const requestId = result.response.headers.get("x-request-id") ?? undefined;
|
|
24
|
+
const status = (result.response as any).status ?? 0;
|
|
25
|
+
|
|
26
|
+
const err = result.error as any;
|
|
27
|
+
const message =
|
|
28
|
+
err?.message ??
|
|
29
|
+
err?.error?.message ??
|
|
30
|
+
fallbackMessage;
|
|
31
|
+
|
|
32
|
+
const code = err?.code ?? err?.error?.code;
|
|
33
|
+
const msg = err?.message ?? err?.error?.message ?? message;
|
|
34
|
+
|
|
35
|
+
throw new SandboxApiException({
|
|
36
|
+
message: msg,
|
|
37
|
+
statusCode: status,
|
|
38
|
+
requestId,
|
|
39
|
+
error: code
|
|
40
|
+
? new SandboxError(String(code), String(msg ?? ""))
|
|
41
|
+
: new SandboxError(SandboxError.UNEXPECTED_RESPONSE, String(msg ?? "")),
|
|
42
|
+
rawBody: result.error,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { SandboxApiException, SandboxError } from "@alibaba-group/opensandbox";
|
|
16
|
+
|
|
17
|
+
function tryParseJson(line: string): unknown | undefined {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(line);
|
|
20
|
+
} catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Parses an SSE-like stream that may be either:
|
|
27
|
+
* - standard SSE frames (`data: {...}\n\n`)
|
|
28
|
+
* - newline-delimited JSON (one JSON object per line)
|
|
29
|
+
*/
|
|
30
|
+
export async function* parseJsonEventStream<T>(
|
|
31
|
+
res: Response,
|
|
32
|
+
opts?: { fallbackErrorMessage?: string },
|
|
33
|
+
): AsyncIterable<T> {
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
const text = await res.text().catch(() => "");
|
|
36
|
+
const parsed = tryParseJson(text);
|
|
37
|
+
const err = parsed && typeof parsed === "object" ? (parsed as any) : undefined;
|
|
38
|
+
const requestId = res.headers.get("x-request-id") ?? undefined;
|
|
39
|
+
const message = err?.message ?? opts?.fallbackErrorMessage ?? `Stream request failed (status=${res.status})`;
|
|
40
|
+
const code = err?.code ? String(err.code) : SandboxError.UNEXPECTED_RESPONSE;
|
|
41
|
+
throw new SandboxApiException({
|
|
42
|
+
message,
|
|
43
|
+
statusCode: res.status,
|
|
44
|
+
requestId,
|
|
45
|
+
error: new SandboxError(code, err?.message ? String(err.message) : message),
|
|
46
|
+
rawBody: parsed ?? text,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!res.body) return;
|
|
51
|
+
|
|
52
|
+
const reader = res.body.getReader();
|
|
53
|
+
const decoder = new TextDecoder("utf-8");
|
|
54
|
+
let buf = "";
|
|
55
|
+
|
|
56
|
+
while (true) {
|
|
57
|
+
const { value, done } = await reader.read();
|
|
58
|
+
if (done) break;
|
|
59
|
+
|
|
60
|
+
buf += decoder.decode(value, { stream: true });
|
|
61
|
+
let idx: number;
|
|
62
|
+
|
|
63
|
+
while ((idx = buf.indexOf("\n")) >= 0) {
|
|
64
|
+
const rawLine = buf.slice(0, idx);
|
|
65
|
+
buf = buf.slice(idx + 1);
|
|
66
|
+
|
|
67
|
+
const line = rawLine.trim();
|
|
68
|
+
if (!line) continue;
|
|
69
|
+
|
|
70
|
+
// Support standard SSE "data:" prefix
|
|
71
|
+
if (line.startsWith(":")) continue;
|
|
72
|
+
if (line.startsWith("event:") || line.startsWith("id:") || line.startsWith("retry:")) continue;
|
|
73
|
+
|
|
74
|
+
const jsonLine = line.startsWith("data:") ? line.slice("data:".length).trim() : line;
|
|
75
|
+
if (!jsonLine) continue;
|
|
76
|
+
|
|
77
|
+
const parsed = tryParseJson(jsonLine);
|
|
78
|
+
if (!parsed) continue;
|
|
79
|
+
yield parsed as T;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// flush last line if exists
|
|
84
|
+
const last = buf.trim();
|
|
85
|
+
if (last) {
|
|
86
|
+
const jsonLine = last.startsWith("data:") ? last.slice("data:".length).trim() : last;
|
|
87
|
+
const parsed = tryParseJson(jsonLine);
|
|
88
|
+
if (parsed) yield parsed as T;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import type { Sandbox } from "@alibaba-group/opensandbox";
|
|
16
|
+
import type { Codes } from "../services/codes.js";
|
|
17
|
+
|
|
18
|
+
export interface CreateCodesStackOptions {
|
|
19
|
+
sandbox: Sandbox;
|
|
20
|
+
execdBaseUrl: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Factory abstraction for Code Interpreter SDK to decouple from concrete adapters/clients.
|
|
25
|
+
*/
|
|
26
|
+
export interface AdapterFactory {
|
|
27
|
+
createCodes(opts: CreateCodesStackOptions): Codes;
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { createExecdClient } from "@alibaba-group/opensandbox/internal";
|
|
16
|
+
import type { AdapterFactory, CreateCodesStackOptions } from "./adapterFactory.js";
|
|
17
|
+
import { CodesAdapter } from "../adapters/codesAdapter.js";
|
|
18
|
+
import type { Codes } from "../services/codes.js";
|
|
19
|
+
|
|
20
|
+
export class DefaultAdapterFactory implements AdapterFactory {
|
|
21
|
+
createCodes(opts: CreateCodesStackOptions): Codes {
|
|
22
|
+
const client = createExecdClient({
|
|
23
|
+
baseUrl: opts.execdBaseUrl,
|
|
24
|
+
headers: opts.sandbox.connectionConfig.headers,
|
|
25
|
+
fetch: opts.sandbox.connectionConfig.fetch,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return new CodesAdapter(client, {
|
|
29
|
+
baseUrl: opts.execdBaseUrl,
|
|
30
|
+
headers: opts.sandbox.connectionConfig.headers,
|
|
31
|
+
// Streaming calls (SSE) use a dedicated fetch, aligned with Kotlin/Python SDKs.
|
|
32
|
+
fetch: opts.sandbox.connectionConfig.sseFetch,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createDefaultAdapterFactory(): AdapterFactory {
|
|
38
|
+
return new DefaultAdapterFactory();
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
export { CodeInterpreter } from "./interpreter.js";
|
|
16
|
+
export type { CodeInterpreterCreateOptions } from "./interpreter.js";
|
|
17
|
+
|
|
18
|
+
export type { AdapterFactory } from "./factory/adapterFactory.js";
|
|
19
|
+
export { DefaultAdapterFactory, createDefaultAdapterFactory } from "./factory/defaultAdapterFactory.js";
|
|
20
|
+
|
|
21
|
+
export type { CodeContext, SupportedLanguage } from "./models.js";
|
|
22
|
+
export { SupportedLanguage as SupportedLanguages } from "./models.js";
|
|
23
|
+
|
|
24
|
+
export type { Codes } from "./services/codes.js";
|
|
25
|
+
|
|
26
|
+
export type {
|
|
27
|
+
Execution,
|
|
28
|
+
ExecutionComplete,
|
|
29
|
+
ExecutionError,
|
|
30
|
+
ExecutionHandlers,
|
|
31
|
+
ExecutionInit,
|
|
32
|
+
ExecutionResult,
|
|
33
|
+
OutputMessage,
|
|
34
|
+
} from "@alibaba-group/opensandbox";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { DEFAULT_EXECD_PORT } from "@alibaba-group/opensandbox";
|
|
16
|
+
import type { Sandbox } from "@alibaba-group/opensandbox";
|
|
17
|
+
|
|
18
|
+
import { createDefaultAdapterFactory } from "./factory/defaultAdapterFactory.js";
|
|
19
|
+
import type { AdapterFactory } from "./factory/adapterFactory.js";
|
|
20
|
+
import type { Codes } from "./services/codes.js";
|
|
21
|
+
|
|
22
|
+
export interface CodeInterpreterCreateOptions {
|
|
23
|
+
adapterFactory?: AdapterFactory;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Code interpreter facade (JS/TS).
|
|
28
|
+
*
|
|
29
|
+
* This class wraps an existing {@link Sandbox} and provides a high-level API for code execution.
|
|
30
|
+
*
|
|
31
|
+
* - Use {@link codes} to create contexts and run code.
|
|
32
|
+
* - {@link files}, {@link commands}, and {@link metrics} are exposed for convenience and are
|
|
33
|
+
* the same instances as on the underlying {@link Sandbox}.
|
|
34
|
+
*/
|
|
35
|
+
export class CodeInterpreter {
|
|
36
|
+
private constructor(
|
|
37
|
+
readonly sandbox: Sandbox,
|
|
38
|
+
readonly codes: Codes,
|
|
39
|
+
) {}
|
|
40
|
+
|
|
41
|
+
static async create(sandbox: Sandbox, opts: CodeInterpreterCreateOptions = {}): Promise<CodeInterpreter> {
|
|
42
|
+
const execdBaseUrl = await sandbox.getEndpointUrl(DEFAULT_EXECD_PORT);
|
|
43
|
+
const adapterFactory = opts.adapterFactory ?? createDefaultAdapterFactory();
|
|
44
|
+
const codes = adapterFactory.createCodes({ sandbox, execdBaseUrl });
|
|
45
|
+
|
|
46
|
+
return new CodeInterpreter(sandbox, codes);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get id() {
|
|
50
|
+
return this.sandbox.id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get files() {
|
|
54
|
+
return this.sandbox.files;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get commands() {
|
|
58
|
+
return this.sandbox.commands;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get metrics() {
|
|
62
|
+
return this.sandbox.metrics;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
export const SupportedLanguage = {
|
|
16
|
+
PYTHON: "python",
|
|
17
|
+
JAVA: "java",
|
|
18
|
+
GO: "go",
|
|
19
|
+
TYPESCRIPT: "typescript",
|
|
20
|
+
JAVASCRIPT: "javascript",
|
|
21
|
+
BASH: "bash",
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
export type SupportedLanguage =
|
|
25
|
+
(typeof SupportedLanguage)[keyof typeof SupportedLanguage];
|
|
26
|
+
|
|
27
|
+
export interface CodeContext {
|
|
28
|
+
id?: string;
|
|
29
|
+
language: SupportedLanguage | (string & {});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface RunCodeRequest {
|
|
33
|
+
code: string;
|
|
34
|
+
context: CodeContext;
|
|
35
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2026 Alibaba Group Holding Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import type { ServerStreamEvent } from "@alibaba-group/opensandbox";
|
|
16
|
+
import type { Execution, ExecutionHandlers } from "@alibaba-group/opensandbox";
|
|
17
|
+
import type { CodeContext, RunCodeRequest, SupportedLanguage } from "../models.js";
|
|
18
|
+
|
|
19
|
+
export interface Codes {
|
|
20
|
+
createContext(language: SupportedLanguage): Promise<CodeContext>;
|
|
21
|
+
/**
|
|
22
|
+
* Get an existing context by id.
|
|
23
|
+
*/
|
|
24
|
+
getContext(contextId: string): Promise<CodeContext>;
|
|
25
|
+
/**
|
|
26
|
+
* List active contexts. If language is provided, filters by language/runtime.
|
|
27
|
+
*/
|
|
28
|
+
listContexts(language?: SupportedLanguage): Promise<CodeContext[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete a context by id.
|
|
31
|
+
*/
|
|
32
|
+
deleteContext(contextId: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Delete all contexts under the specified language/runtime.
|
|
35
|
+
*/
|
|
36
|
+
deleteContexts(language: SupportedLanguage): Promise<void>;
|
|
37
|
+
|
|
38
|
+
run(
|
|
39
|
+
code: string,
|
|
40
|
+
opts?: { context?: CodeContext; language?: SupportedLanguage; handlers?: ExecutionHandlers; signal?: AbortSignal },
|
|
41
|
+
): Promise<Execution>;
|
|
42
|
+
|
|
43
|
+
runStream(
|
|
44
|
+
req: RunCodeRequest,
|
|
45
|
+
signal?: AbortSignal,
|
|
46
|
+
): AsyncIterable<ServerStreamEvent>;
|
|
47
|
+
|
|
48
|
+
interrupt(contextId: string): Promise<void>;
|
|
49
|
+
}
|