@alibaba-group/opensandbox-code-interpreter 0.1.1-dev0 → 0.1.2-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.
Files changed (39) hide show
  1. package/dist/cjs/index.cjs +294 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.d.ts +90 -9
  4. package/dist/index.js +266 -16
  5. package/dist/index.js.map +1 -1
  6. package/package.json +6 -3
  7. package/dist/adapters/codesAdapter.d.ts +0 -31
  8. package/dist/adapters/codesAdapter.d.ts.map +0 -1
  9. package/dist/adapters/codesAdapter.js +0 -147
  10. package/dist/adapters/codesAdapter.js.map +0 -1
  11. package/dist/adapters/openapiError.d.ts +0 -5
  12. package/dist/adapters/openapiError.d.ts.map +0 -1
  13. package/dist/adapters/openapiError.js +0 -36
  14. package/dist/adapters/openapiError.js.map +0 -1
  15. package/dist/adapters/sse.d.ts +0 -9
  16. package/dist/adapters/sse.d.ts.map +0 -1
  17. package/dist/adapters/sse.js +0 -84
  18. package/dist/adapters/sse.js.map +0 -1
  19. package/dist/factory/adapterFactory.d.ts +0 -13
  20. package/dist/factory/adapterFactory.d.ts.map +0 -1
  21. package/dist/factory/adapterFactory.js +0 -15
  22. package/dist/factory/adapterFactory.js.map +0 -1
  23. package/dist/factory/defaultAdapterFactory.d.ts +0 -7
  24. package/dist/factory/defaultAdapterFactory.d.ts.map +0 -1
  25. package/dist/factory/defaultAdapterFactory.js +0 -34
  26. package/dist/factory/defaultAdapterFactory.js.map +0 -1
  27. package/dist/index.d.ts.map +0 -1
  28. package/dist/interpreter.d.ts +0 -26
  29. package/dist/interpreter.d.ts.map +0 -1
  30. package/dist/interpreter.js +0 -51
  31. package/dist/interpreter.js.map +0 -1
  32. package/dist/models.d.ts +0 -18
  33. package/dist/models.d.ts.map +0 -1
  34. package/dist/models.js +0 -22
  35. package/dist/models.js.map +0 -1
  36. package/dist/services/codes.d.ts +0 -31
  37. package/dist/services/codes.d.ts.map +0 -1
  38. package/dist/services/codes.js +0 -15
  39. package/dist/services/codes.js.map +0 -1
@@ -1,84 +0,0 @@
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
- import { SandboxApiException, SandboxError } from "@alibaba-group/opensandbox";
15
- function tryParseJson(line) {
16
- try {
17
- return JSON.parse(line);
18
- }
19
- catch {
20
- return undefined;
21
- }
22
- }
23
- /**
24
- * Parses an SSE-like stream that may be either:
25
- * - standard SSE frames (`data: {...}\n\n`)
26
- * - newline-delimited JSON (one JSON object per line)
27
- */
28
- export async function* parseJsonEventStream(res, opts) {
29
- if (!res.ok) {
30
- const text = await res.text().catch(() => "");
31
- const parsed = tryParseJson(text);
32
- const err = parsed && typeof parsed === "object" ? parsed : undefined;
33
- const requestId = res.headers.get("x-request-id") ?? undefined;
34
- const message = err?.message ?? opts?.fallbackErrorMessage ?? `Stream request failed (status=${res.status})`;
35
- const code = err?.code ? String(err.code) : SandboxError.UNEXPECTED_RESPONSE;
36
- throw new SandboxApiException({
37
- message,
38
- statusCode: res.status,
39
- requestId,
40
- error: new SandboxError(code, err?.message ? String(err.message) : message),
41
- rawBody: parsed ?? text,
42
- });
43
- }
44
- if (!res.body)
45
- return;
46
- const reader = res.body.getReader();
47
- const decoder = new TextDecoder("utf-8");
48
- let buf = "";
49
- while (true) {
50
- const { value, done } = await reader.read();
51
- if (done)
52
- break;
53
- buf += decoder.decode(value, { stream: true });
54
- let idx;
55
- while ((idx = buf.indexOf("\n")) >= 0) {
56
- const rawLine = buf.slice(0, idx);
57
- buf = buf.slice(idx + 1);
58
- const line = rawLine.trim();
59
- if (!line)
60
- continue;
61
- // Support standard SSE "data:" prefix
62
- if (line.startsWith(":"))
63
- continue;
64
- if (line.startsWith("event:") || line.startsWith("id:") || line.startsWith("retry:"))
65
- continue;
66
- const jsonLine = line.startsWith("data:") ? line.slice("data:".length).trim() : line;
67
- if (!jsonLine)
68
- continue;
69
- const parsed = tryParseJson(jsonLine);
70
- if (!parsed)
71
- continue;
72
- yield parsed;
73
- }
74
- }
75
- // flush last line if exists
76
- const last = buf.trim();
77
- if (last) {
78
- const jsonLine = last.startsWith("data:") ? last.slice("data:".length).trim() : last;
79
- const parsed = tryParseJson(jsonLine);
80
- if (parsed)
81
- yield parsed;
82
- }
83
- }
84
- //# sourceMappingURL=sse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/adapters/sse.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,mBAAmB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/E,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,oBAAoB,CACzC,GAAa,EACb,IAAwC;IAExC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAA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AI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACrF,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,MAAM;YAAE,MAAM,MAAW,CAAC;IAChC,CAAC;AACH,CAAC"}
@@ -1,13 +0,0 @@
1
- import type { Sandbox } from "@alibaba-group/opensandbox";
2
- import type { Codes } from "../services/codes.js";
3
- export interface CreateCodesStackOptions {
4
- sandbox: Sandbox;
5
- execdBaseUrl: string;
6
- }
7
- /**
8
- * Factory abstraction for Code Interpreter SDK to decouple from concrete adapters/clients.
9
- */
10
- export interface AdapterFactory {
11
- createCodes(opts: CreateCodesStackOptions): Codes;
12
- }
13
- //# sourceMappingURL=adapterFactory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapterFactory.d.ts","sourceRoot":"","sources":["../../src/factory/adapterFactory.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,IAAI,EAAE,uBAAuB,GAAG,KAAK,CAAC;CACnD"}
@@ -1,15 +0,0 @@
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
- export {};
15
- //# sourceMappingURL=adapterFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapterFactory.js","sourceRoot":"","sources":["../../src/factory/adapterFactory.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"}
@@ -1,7 +0,0 @@
1
- import type { AdapterFactory, CreateCodesStackOptions } from "./adapterFactory.js";
2
- import type { Codes } from "../services/codes.js";
3
- export declare class DefaultAdapterFactory implements AdapterFactory {
4
- createCodes(opts: CreateCodesStackOptions): Codes;
5
- }
6
- export declare function createDefaultAdapterFactory(): AdapterFactory;
7
- //# sourceMappingURL=defaultAdapterFactory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultAdapterFactory.d.ts","sourceRoot":"","sources":["../../src/factory/defaultAdapterFactory.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEnF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,WAAW,CAAC,IAAI,EAAE,uBAAuB,GAAG,KAAK;CAclD;AAED,wBAAgB,2BAA2B,IAAI,cAAc,CAE5D"}
@@ -1,34 +0,0 @@
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
- import { createExecdClient } from "@alibaba-group/opensandbox/internal";
15
- import { CodesAdapter } from "../adapters/codesAdapter.js";
16
- export class DefaultAdapterFactory {
17
- createCodes(opts) {
18
- const client = createExecdClient({
19
- baseUrl: opts.execdBaseUrl,
20
- headers: opts.sandbox.connectionConfig.headers,
21
- fetch: opts.sandbox.connectionConfig.fetch,
22
- });
23
- return new CodesAdapter(client, {
24
- baseUrl: opts.execdBaseUrl,
25
- headers: opts.sandbox.connectionConfig.headers,
26
- // Streaming calls (SSE) use a dedicated fetch, aligned with Kotlin/Python SDKs.
27
- fetch: opts.sandbox.connectionConfig.sseFetch,
28
- });
29
- }
30
- }
31
- export function createDefaultAdapterFactory() {
32
- return new DefaultAdapterFactory();
33
- }
34
- //# sourceMappingURL=defaultAdapterFactory.js.map
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,YAAY,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAErE,YAAY,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAExG,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,iBAAiB,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtE,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,4BAA4B,CAAC"}
@@ -1,26 +0,0 @@
1
- import type { Sandbox } from "@alibaba-group/opensandbox";
2
- import type { AdapterFactory } from "./factory/adapterFactory.js";
3
- import type { Codes } from "./services/codes.js";
4
- export interface CodeInterpreterCreateOptions {
5
- adapterFactory?: AdapterFactory;
6
- }
7
- /**
8
- * Code interpreter facade (JS/TS).
9
- *
10
- * This class wraps an existing {@link Sandbox} and provides a high-level API for code execution.
11
- *
12
- * - Use {@link codes} to create contexts and run code.
13
- * - {@link files}, {@link commands}, and {@link metrics} are exposed for convenience and are
14
- * the same instances as on the underlying {@link Sandbox}.
15
- */
16
- export declare class CodeInterpreter {
17
- readonly sandbox: Sandbox;
18
- readonly codes: Codes;
19
- private constructor();
20
- static create(sandbox: Sandbox, opts?: CodeInterpreterCreateOptions): Promise<CodeInterpreter>;
21
- get id(): string;
22
- get files(): import("@alibaba-group/opensandbox").SandboxFiles;
23
- get commands(): import("@alibaba-group/opensandbox").ExecdCommands;
24
- get metrics(): import("@alibaba-group/opensandbox").ExecdMetrics;
25
- }
26
- //# sourceMappingURL=interpreter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interpreter.d.ts","sourceRoot":"","sources":["../src/interpreter.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAG1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,WAAW,4BAA4B;IAC3C,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAExB,QAAQ,CAAC,OAAO,EAAE,OAAO;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK;IAFvB,OAAO;WAKM,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAE,4BAAiC,GAAG,OAAO,CAAC,eAAe,CAAC;IAQxG,IAAI,EAAE,WAEL;IAED,IAAI,KAAK,sDAER;IAED,IAAI,QAAQ,uDAEX;IAED,IAAI,OAAO,sDAEV;CACF"}
@@ -1,51 +0,0 @@
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
- import { DEFAULT_EXECD_PORT } from "@alibaba-group/opensandbox";
15
- import { createDefaultAdapterFactory } from "./factory/defaultAdapterFactory.js";
16
- /**
17
- * Code interpreter facade (JS/TS).
18
- *
19
- * This class wraps an existing {@link Sandbox} and provides a high-level API for code execution.
20
- *
21
- * - Use {@link codes} to create contexts and run code.
22
- * - {@link files}, {@link commands}, and {@link metrics} are exposed for convenience and are
23
- * the same instances as on the underlying {@link Sandbox}.
24
- */
25
- export class CodeInterpreter {
26
- sandbox;
27
- codes;
28
- constructor(sandbox, codes) {
29
- this.sandbox = sandbox;
30
- this.codes = codes;
31
- }
32
- static async create(sandbox, opts = {}) {
33
- const execdBaseUrl = await sandbox.getEndpointUrl(DEFAULT_EXECD_PORT);
34
- const adapterFactory = opts.adapterFactory ?? createDefaultAdapterFactory();
35
- const codes = adapterFactory.createCodes({ sandbox, execdBaseUrl });
36
- return new CodeInterpreter(sandbox, codes);
37
- }
38
- get id() {
39
- return this.sandbox.id;
40
- }
41
- get files() {
42
- return this.sandbox.files;
43
- }
44
- get commands() {
45
- return this.sandbox.commands;
46
- }
47
- get metrics() {
48
- return this.sandbox.metrics;
49
- }
50
- }
51
- //# sourceMappingURL=interpreter.js.map
@@ -1 +0,0 @@
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.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export declare const SupportedLanguage: {
2
- readonly PYTHON: "python";
3
- readonly JAVA: "java";
4
- readonly GO: "go";
5
- readonly TYPESCRIPT: "typescript";
6
- readonly JAVASCRIPT: "javascript";
7
- readonly BASH: "bash";
8
- };
9
- export type SupportedLanguage = (typeof SupportedLanguage)[keyof typeof SupportedLanguage];
10
- export interface CodeContext {
11
- id?: string;
12
- language: SupportedLanguage | (string & {});
13
- }
14
- export interface RunCodeRequest {
15
- code: string;
16
- context: CodeContext;
17
- }
18
- //# sourceMappingURL=models.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,iBAAiB;;;;;;;CAOpB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,iBAAiB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;CACtB"}
package/dist/models.js DELETED
@@ -1,22 +0,0 @@
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
- export const SupportedLanguage = {
15
- PYTHON: "python",
16
- JAVA: "java",
17
- GO: "go",
18
- TYPESCRIPT: "typescript",
19
- JAVASCRIPT: "javascript",
20
- BASH: "bash",
21
- };
22
- //# sourceMappingURL=models.js.map
@@ -1 +0,0 @@
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"}
@@ -1,31 +0,0 @@
1
- import type { ServerStreamEvent } from "@alibaba-group/opensandbox";
2
- import type { Execution, ExecutionHandlers } from "@alibaba-group/opensandbox";
3
- import type { CodeContext, RunCodeRequest, SupportedLanguage } from "../models.js";
4
- export interface Codes {
5
- createContext(language: SupportedLanguage): Promise<CodeContext>;
6
- /**
7
- * Get an existing context by id.
8
- */
9
- getContext(contextId: string): Promise<CodeContext>;
10
- /**
11
- * List active contexts. If language is provided, filters by language/runtime.
12
- */
13
- listContexts(language?: SupportedLanguage): Promise<CodeContext[]>;
14
- /**
15
- * Delete a context by id.
16
- */
17
- deleteContext(contextId: string): Promise<void>;
18
- /**
19
- * Delete all contexts under the specified language/runtime.
20
- */
21
- deleteContexts(language: SupportedLanguage): Promise<void>;
22
- run(code: string, opts?: {
23
- context?: CodeContext;
24
- language?: SupportedLanguage;
25
- handlers?: ExecutionHandlers;
26
- signal?: AbortSignal;
27
- }): Promise<Execution>;
28
- runStream(req: RunCodeRequest, signal?: AbortSignal): AsyncIterable<ServerStreamEvent>;
29
- interrupt(contextId: string): Promise<void>;
30
- }
31
- //# sourceMappingURL=codes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/services/codes.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEnF,MAAM,WAAW,KAAK;IACpB,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACjE;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACpD;;OAEG;IACH,YAAY,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACnE;;OAEG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3D,GAAG,CACD,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,WAAW,CAAC;QAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;QAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACjH,OAAO,CAAC,SAAS,CAAC,CAAC;IAEtB,SAAS,CACP,GAAG,EAAE,cAAc,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAEpC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C"}
@@ -1,15 +0,0 @@
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
- export {};
15
- //# sourceMappingURL=codes.js.map
@@ -1 +0,0 @@
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"}