@univer-cli/content-execution 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @univer-cli/content-execution
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ Bind a piece of Facade JavaScript to an explicit Univer Unit to generate a program that can be executed by the runtime.
6
+
7
+ This is useful for CLIs or Agents that need user code to operate only on a specified Unit. The package injects stable bindings for the Unit type and prevents user code from redeclaring those bindings before execution.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add @univer-cli/content-execution
13
+ ```
14
+
15
+ Requires Node.js 22.12 or higher.
16
+
17
+ ## Quick Start
18
+
19
+ ```ts
20
+ import { prepareContentExecutionProgram } from "@univer-cli/content-execution";
21
+
22
+ const program = prepareContentExecutionProgram({
23
+ code: 'workbook.getActiveSheet().getRange("A1").setValue("done");',
24
+ unitId: "book-1",
25
+ unitType: "sheet",
26
+ });
27
+
28
+ const result = await runtime.execute({
29
+ code: program,
30
+ mode: "write",
31
+ });
32
+ ```
33
+
34
+ The package returns only the program string. The caller remains responsible for acquiring the Runtime, selecting the execution mode, managing the lease, and persisting changes.
35
+
36
+ ## Available bindings
37
+
38
+ | Unit type | Injected binding |
39
+ | --------- | ---------------------------------- |
40
+ | Sheet | `univerAPI`, `api`, `workbook` |
41
+ | Doc | `univerAPI`, `api`, `document` |
42
+ | Slide | `univerAPI`, `api`, `presentation` |
43
+ | Base | `univerAPI`, `api`, `database` |
44
+ | Board | `univerAPI`, `api`, `board` |
45
+
46
+ Root Facade is obtained through `unitId` instead of relying on the current active unit, so the same code can be stably executed in the headless runtime.
47
+
48
+ ## Validation and errors
49
+
50
+ User code must not redeclare package-injected bindings at the top level. An invalid Unit type, empty Unit ID, parse failure, or binding conflict throws `ContentExecutionError` with a stable error code for adapter-level presentation.
51
+
52
+ The package does not determine whether code is safe or provide a process-level sandbox. When executing untrusted code, the application must provide its own isolation boundary.
53
+
54
+ ## Responsibility boundaries
55
+
56
+ This package does not depend on Commander, acquire collaboration runtimes, parse targets, or submit changesets. For a complete collaboration execution workflow, combine it with `@univer-cli/univer-collaboration-runtime` or the runtime pool.
@@ -0,0 +1,59 @@
1
+ # @univer-cli/content-execution
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ 把一段 Facade JavaScript 绑定到一个明确的 Univer Unit,生成可交给 runtime 执行的 program。
6
+
7
+ 它适合需要让用户代码只操作指定 Unit 的 CLI 或 Agent:package 会根据 Unit 类型注入稳定 binding,并在进入
8
+ runtime 前拒绝用户代码重新声明这些 binding。
9
+
10
+ ## 安装
11
+
12
+ ```bash
13
+ pnpm add @univer-cli/content-execution
14
+ ```
15
+
16
+ 要求 Node.js 22.12 或更高版本。
17
+
18
+ ## 快速开始
19
+
20
+ ```ts
21
+ import { prepareContentExecutionProgram } from "@univer-cli/content-execution";
22
+
23
+ const program = prepareContentExecutionProgram({
24
+ code: 'workbook.getActiveSheet().getRange("A1").setValue("done");',
25
+ unitId: "book-1",
26
+ unitType: "sheet",
27
+ });
28
+
29
+ const result = await runtime.execute({
30
+ code: program,
31
+ mode: "write",
32
+ });
33
+ ```
34
+
35
+ Package 只返回 program 字符串。Runtime 的获取、执行模式、lease 和持久化由调用方负责。
36
+
37
+ ## 可用 binding
38
+
39
+ | Unit 类型 | 注入的 binding |
40
+ | --------- | ---------------------------------- |
41
+ | Sheet | `univerAPI`、`api`、`workbook` |
42
+ | Doc | `univerAPI`、`api`、`document` |
43
+ | Slide | `univerAPI`、`api`、`presentation` |
44
+ | Base | `univerAPI`、`api`、`database` |
45
+ | Board | `univerAPI`、`api`、`board` |
46
+
47
+ Root Facade 通过 `unitId` 获取,而不是依赖当前 active Unit,因此相同代码可在 headless runtime 中稳定执行。
48
+
49
+ ## 校验与错误
50
+
51
+ 用户代码不得在顶层重新声明 package 注入的 binding。非法 Unit type、空 Unit ID、语法分析失败或 binding
52
+ 冲突会抛出 `ContentExecutionError`,并提供稳定 error code 供 adapter 呈现。
53
+
54
+ Package 不判断代码是否安全,也不提供进程级 sandbox。执行不可信代码时,application 必须自行提供隔离边界。
55
+
56
+ ## 职责边界
57
+
58
+ 本 package 不依赖 Commander、不获取 collaboration runtime、不解析 target,也不提交 changeset。需要完整协同
59
+ 执行流程时,与 `@univer-cli/univer-collaboration-runtime` 或 runtime pool 组合。
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';module['exports']=require('./index.mjs');
@@ -0,0 +1,18 @@
1
+ //#region src/errors.d.ts
2
+ type ContentExecutionErrorCode = "CONTENT_EXECUTION_INVALID_INPUT" | "CONTENT_EXECUTION_RESERVED_BINDING" | "CONTENT_EXECUTION_UNIT_TYPE_UNSUPPORTED";
3
+ declare class ContentExecutionError extends Error {
4
+ readonly code: ContentExecutionErrorCode;
5
+ readonly details?: Readonly<Record<string, unknown>> | undefined;
6
+ constructor(code: ContentExecutionErrorCode, message: string, details?: Readonly<Record<string, unknown>> | undefined);
7
+ }
8
+ //#endregion
9
+ //#region src/program.d.ts
10
+ type ContentExecutionUnitType = "sheet" | "doc" | "slide" | "base" | "board";
11
+ interface PrepareContentExecutionProgramInput {
12
+ readonly code: string;
13
+ readonly unitId: string;
14
+ readonly unitType: ContentExecutionUnitType;
15
+ }
16
+ declare function prepareContentExecutionProgram(input: PrepareContentExecutionProgramInput): string;
17
+ //#endregion
18
+ export { ContentExecutionError, type ContentExecutionErrorCode, type ContentExecutionUnitType, type PrepareContentExecutionProgramInput, prepareContentExecutionProgram };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const _0x1afc5c=_0x285f;(function(_0x4e7d8c,_0x4f41e2){const _0x3a172a=_0x285f,_0x30ce9e=_0x4e7d8c();while(!![]){try{const _0x5af814=-parseInt(_0x3a172a(0x16e))/0x1+parseInt(_0x3a172a(0x174))/0x2*(parseInt(_0x3a172a(0x16b))/0x3)+-parseInt(_0x3a172a(0x161))/0x4+parseInt(_0x3a172a(0x17c))/0x5+parseInt(_0x3a172a(0x17d))/0x6+-parseInt(_0x3a172a(0x16c))/0x7+parseInt(_0x3a172a(0x166))/0x8;if(_0x5af814===_0x4f41e2)break;else _0x30ce9e['push'](_0x30ce9e['shift']());}catch(_0x3ccd02){_0x30ce9e['push'](_0x30ce9e['shift']());}}}(_0x3d2d,0xac341));var e=class extends Error{[_0x1afc5c(0x170)];[_0x1afc5c(0x15e)];constructor(_0x15fed9,_0x48b96d,_0x5dd606){const _0x22c5aa=_0x1afc5c;super(_0x48b96d),this[_0x22c5aa(0x170)]=_0x15fed9,this['details']=_0x5dd606,this[_0x22c5aa(0x175)]=_0x22c5aa(0x177);}},t=[_0x1afc5c(0x163),_0x1afc5c(0x17e),'slide',_0x1afc5c(0x168),_0x1afc5c(0x15c)];function n(_0xe18638){const _0x2c61af=_0x1afc5c;if(typeof _0xe18638[_0x2c61af(0x170)]!=_0x2c61af(0x173))throw new e(_0x2c61af(0x167),'Content\x20execution\x20code\x20must\x20be\x20a\x20string');if(typeof _0xe18638['unitId']!=_0x2c61af(0x173)||_0xe18638[_0x2c61af(0x16d)][_0x2c61af(0x15f)]()[_0x2c61af(0x160)]===0x0)throw new e('CONTENT_EXECUTION_INVALID_INPUT','Content\x20execution\x20Unit\x20ID\x20must\x20not\x20be\x20empty',{'unitId':_0xe18638[_0x2c61af(0x16d)]});if(!s(_0xe18638['unitType']))throw new e('CONTENT_EXECUTION_UNIT_TYPE_UNSUPPORTED',_0x2c61af(0x17a)+String(_0xe18638[_0x2c61af(0x172)]),{'supportedUnitTypes':t,'unitType':_0xe18638[_0x2c61af(0x172)]});let _0x35cf92=i(_0xe18638[_0x2c61af(0x172)]);return a(_0xe18638[_0x2c61af(0x170)],_0xe18638[_0x2c61af(0x172)],_0x35cf92),r(_0xe18638['unitType'],_0xe18638[_0x2c61af(0x16d)])+'\x0a'+_0xe18638['code'];}function _0x3d2d(){const _0x1bd1b6=['9216725DwQJlE','unitId','1372876aFHEcQ','const\x20api\x20=\x20univerAPI;\x0aconst\x20board\x20=\x20api.getBoard(','code','join','unitType','string','8tyIHWQ','name','presentation','ContentExecutionError','const\x20api\x20=\x20univerAPI;\x0aconst\x20doc\x20=\x20api.getDocument(','api','Content\x20execution\x20does\x20not\x20support\x20Unit\x20type\x20','univerAPI','1807160SzrsYV','6280272afMIAx','doc','const\x20api\x20=\x20univerAPI;','some','stringify','board','Cannot\x20find\x20workbook\x20','details','trim','length','5198240VzEwSY','slide','sheet','workbook','CONTENT_EXECUTION_RESERVED_BINDING','18964768aULsCB','CONTENT_EXECUTION_INVALID_INPUT','base','const\x20workbook\x20=\x20api.getWorkbook(','const\x20api\x20=\x20univerAPI;\x0aconst\x20presentation\x20=\x20api.getPresentation(','686787rNoHWD'];_0x3d2d=function(){return _0x1bd1b6;};return _0x3d2d();}function r(_0x418205,_0x12be36){const _0x22296b=_0x1afc5c;let _0x210ef7=JSON['stringify'](_0x12be36);return _0x418205==='sheet'?[_0x22296b(0x17f),_0x22296b(0x169)+_0x210ef7+');','if\x20(!workbook)\x20throw\x20new\x20Error('+JSON[_0x22296b(0x15b)](_0x22296b(0x15d)+_0x12be36)+');'][_0x22296b(0x171)]('\x0a'):_0x418205===_0x22296b(0x17e)?_0x22296b(0x178)+_0x210ef7+');':_0x418205===_0x22296b(0x162)?_0x22296b(0x16a)+_0x210ef7+');':_0x418205==='board'?_0x22296b(0x16f)+_0x210ef7+');':_0x22296b(0x17f);}function _0x285f(_0x17eeab,_0x4e66ea){_0x17eeab=_0x17eeab-0x15a;const _0x3d2d1e=_0x3d2d();let _0x285ff6=_0x3d2d1e[_0x17eeab];return _0x285ff6;}function i(_0x3507d8){const _0x893a4a=_0x1afc5c;return _0x3507d8===_0x893a4a(0x163)?[_0x893a4a(0x17b),'api',_0x893a4a(0x164)]:_0x3507d8===_0x893a4a(0x17e)?['univerAPI',_0x893a4a(0x179),_0x893a4a(0x17e)]:_0x3507d8==='slide'?[_0x893a4a(0x17b),_0x893a4a(0x179),_0x893a4a(0x176)]:_0x3507d8===_0x893a4a(0x15c)?[_0x893a4a(0x17b),_0x893a4a(0x179),_0x893a4a(0x15c)]:['univerAPI',_0x893a4a(0x179)];}function a(_0x41f350,_0x3647a5,_0x33591c){const _0x5550ae=_0x1afc5c;if(o(_0x41f350)){for(let _0x3c51a1 of _0x33591c)if(!o('const\x20'+_0x3c51a1+'\x20=\x20undefined;\x0a'+_0x41f350))throw new e(_0x5550ae(0x165),'`'+_0x3c51a1+'`\x20is\x20reserved\x20by\x20the\x20'+_0x3647a5+'\x20content\x20execution\x20prelude',{'binding':_0x3c51a1,'reservedBindings':_0x33591c,'unitType':_0x3647a5});}}function o(_0x36a23f){const _0x5efe97=_0x1afc5c;try{return Function(_0x5efe97(0x17b),'return\x20(async\x20()\x20=>\x20{\x20'+_0x36a23f+'\x0a})();'),!0x0;}catch{return!0x1;}}function s(_0x2785da){const _0x17e430=_0x1afc5c;return t[_0x17e430(0x15a)](_0x4a11fc=>_0x4a11fc===_0x2785da);}export{e as ContentExecutionError,n as prepareContentExecutionProgram};
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@univer-cli/content-execution",
3
+ "type": "module",
4
+ "version": "1.0.0-beta.2",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "README.zh-CN.md"
19
+ ]
20
+ }