@dajiaoai/algeo-sdk 2.14.1 → 2.14.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 CHANGED
@@ -314,9 +314,12 @@ type AlgeoCreateOptions =
314
314
  | `auth` | `{ appId: string }` | - | 编辑模式鉴权参数,其中 `appId` 会参与默认路由生成 |
315
315
  | `shareId` | `string` | `''` | 编辑模式初始分享 ID,会映射到 `/embed/edit/:appId/:id` |
316
316
  | `initialContent` | `FileContentAny` | - | 初始化后自动注入的文件内容;SDK 会自动转换为最新格式 |
317
+ | `initialMode` | `'2d' \| '3d'` | `'2d'` | 空白画板模式,仅在没有初始内容或分享文件时生效 |
317
318
  | `ui` | `Partial<AlgeoEditorUiConfig>` | - | 编辑器 UI 开关配置 |
318
319
  | `fonts` | `AlgeoFontConfig` | - | 字体资源、字体选择器列表及默认字体配置 |
319
320
 
321
+ 初始化优先级:`initialContent` > `shareId` > 指定 `initialMode` 的空画板。提供 `initialContent` 时不会请求分享文件;加载已有内容时保留内容中的画板模式。
322
+
320
323
  **AlgeoEditorUiConfig:**
321
324
 
322
325
  | 属性 | 类型 | 默认值 | 说明 |
@@ -506,24 +509,26 @@ SDK 内部已通过 `ResizeObserver` 在容器从隐藏(`display:none`,尺
506
509
 
507
510
  ---
508
511
 
509
- ##### `presentation.repl(command: string): Promise<ReplResult>`
512
+ ##### `editor.repl(command: string): Promise<ReplResult>`
510
513
 
511
- 执行 REPL 指令,返回面向 AI 的文档/文本内容。需先通过 `loadShareById` 或 `loadFile` 加载内容后,部分指令才有数据可查。
514
+ 执行 REPL 指令,返回 `{ output: string }`。修改支持撤销、重做,调用后自动同步画板和历史状态。
512
515
 
513
- | 参数 | 类型 | 说明 |
514
- | --------- | -------- | --------- |
515
- | `command` | `string` | REPL 指令 |
516
+ ```ts
517
+ const { output } = await editor.repl('def A := Point(0,0)');
518
+ await editor.history.undo();
519
+ ```
516
520
 
517
- **常用指令:**
521
+ 调用不触发 `contentChange` / `slideChange`,读取最新内容请用 `editor.document.getContent()`。执行失败时,已完成的修改不会自动回滚。
518
522
 
519
- | 指令 | 说明 |
520
- | ------------- | ----------------------------- |
521
- | `help` | 查看 REPL 帮助 |
522
- | `list` | 列出当前画板中的对象 |
523
- | `list_slides` | 列出所有画板 |
524
- | `eval` | 执行表达式(具体用法见 help) |
523
+ ##### `presentation.repl(command: string): Promise<ReplResult>`
524
+
525
+ 执行 REPL 指令,返回 `{ output: string }`。查询已有内容前,可通过 `loadShareById` 或 `loadFile` 加载画板。
526
+
527
+ ```ts
528
+ const { output } = await presentation.repl('list');
529
+ ```
525
530
 
526
- **返回值:** `{ output: string }` — 指令输出的文本内容
531
+ 两种模式均可通过 `repl('help')` 查看命令帮助,或参考 [REPL 指令实验室](examples/20-repl.html)。
527
532
 
528
533
  ---
529
534
 
@@ -3865,12 +3865,6 @@ var AlgeoError = class extends Error {
3865
3865
  this.name = "AlgeoError";
3866
3866
  }
3867
3867
  };
3868
- objectType({
3869
- text: stringType().optional(),
3870
- images: arrayType(stringType().trim().min(1)).optional(),
3871
- openPanel: booleanType().optional(),
3872
- focus: booleanType().optional()
3873
- }).passthrough();
3874
3868
  var openAiChatMessageV1Schema = objectType({
3875
3869
  role: stringType(),
3876
3870
  content: unionType([
@@ -3884,23 +3878,9 @@ var openAiChatMessageV1Schema = objectType({
3884
3878
  name: stringType().optional()
3885
3879
  }).passthrough();
3886
3880
  objectType({
3887
- model: stringType().trim().min(1),
3888
- input: unionType([
3889
- stringType(),
3890
- arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
3891
- ]).optional(),
3892
- previous_response_id: stringType().trim().min(1).optional(),
3893
- instructions: stringType().optional(),
3894
- temperature: numberType().min(0).max(2).optional(),
3895
- max_output_tokens: numberType().int().positive().optional(),
3896
- metadata: recordType(unknownType()).optional()
3897
- }).passthrough().superRefine((value, ctx) => {
3898
- if (!("input" in value) && !("previous_response_id" in value)) {
3899
- ctx.addIssue({
3900
- code: ZodIssueCode.custom,
3901
- message: "input or previous_response_id is required."
3902
- });
3903
- }
3881
+ model_id: stringType(),
3882
+ messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3883
+ extra_openai_params: recordType(unknownType()).optional()
3904
3884
  });
3905
3885
  objectType({
3906
3886
  id: stringType(),
@@ -4031,7 +4011,7 @@ function convertToLatest(content) {
4031
4011
  }
4032
4012
 
4033
4013
  /** SDK 版本号,构建时由 rollup 注入 */
4034
- const VERSION = '2.14.1';
4014
+ const VERSION = '2.14.2';
4035
4015
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4036
4016
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4037
4017
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4152,10 +4132,10 @@ function buildEmbedSrc(options) {
4152
4132
  const path = getEmbedPath(mode);
4153
4133
  const appId = options.auth?.appId?.trim() ?? '';
4154
4134
  const initialId = options.initialId?.trim();
4155
- if (!initialId) {
4156
- return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
4157
- }
4158
- return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
4135
+ const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4136
+ return mode === 'editor' && options.cameraMode
4137
+ ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4138
+ : src;
4159
4139
  }
4160
4140
 
4161
4141
  class EmbeddedTarget {
@@ -4627,6 +4607,30 @@ class EmbeddedEditor extends EmbeddedTarget {
4627
4607
  },
4628
4608
  };
4629
4609
  }
4610
+ /** Execute a REPL command and synchronize editor state before resolving. */
4611
+ async repl(command) {
4612
+ try {
4613
+ const result = await this.post('repl', { command });
4614
+ this.applyReplState(result.state);
4615
+ return { output: result.output };
4616
+ }
4617
+ catch (error) {
4618
+ // REPL execution can fail after applying some operations.
4619
+ if (error instanceof AlgeoError) {
4620
+ const details = error.details;
4621
+ if (details?.state)
4622
+ this.applyReplState(details.state);
4623
+ }
4624
+ throw error;
4625
+ }
4626
+ }
4627
+ applyReplState(state) {
4628
+ this.currentContent = undefined;
4629
+ this.slideCount = state.slideCount;
4630
+ this.currentSlideIndex = state.currentSlideIndex;
4631
+ this.historyCount = state.historyCount;
4632
+ this.historyCurrentIndex = state.historyCurrentIndex;
4633
+ }
4630
4634
  async initialize(options = {}, baseUrl) {
4631
4635
  if (!options.auth?.appId?.trim()) {
4632
4636
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
@@ -4639,7 +4643,8 @@ class EmbeddedEditor extends EmbeddedTarget {
4639
4643
  await this.init({
4640
4644
  baseUrl,
4641
4645
  auth: options.auth,
4642
- initialId: options.shareId,
4646
+ initialId: options.initialContent ? undefined : options.shareId,
4647
+ cameraMode: options.initialContent ? undefined : options.initialMode,
4643
4648
  });
4644
4649
  if (options.fonts) {
4645
4650
  await this.post('setFontConfig', { config: options.fonts });
@@ -3863,12 +3863,6 @@ var AlgeoError = class extends Error {
3863
3863
  this.name = "AlgeoError";
3864
3864
  }
3865
3865
  };
3866
- objectType({
3867
- text: stringType().optional(),
3868
- images: arrayType(stringType().trim().min(1)).optional(),
3869
- openPanel: booleanType().optional(),
3870
- focus: booleanType().optional()
3871
- }).passthrough();
3872
3866
  var openAiChatMessageV1Schema = objectType({
3873
3867
  role: stringType(),
3874
3868
  content: unionType([
@@ -3882,23 +3876,9 @@ var openAiChatMessageV1Schema = objectType({
3882
3876
  name: stringType().optional()
3883
3877
  }).passthrough();
3884
3878
  objectType({
3885
- model: stringType().trim().min(1),
3886
- input: unionType([
3887
- stringType(),
3888
- arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
3889
- ]).optional(),
3890
- previous_response_id: stringType().trim().min(1).optional(),
3891
- instructions: stringType().optional(),
3892
- temperature: numberType().min(0).max(2).optional(),
3893
- max_output_tokens: numberType().int().positive().optional(),
3894
- metadata: recordType(unknownType()).optional()
3895
- }).passthrough().superRefine((value, ctx) => {
3896
- if (!("input" in value) && !("previous_response_id" in value)) {
3897
- ctx.addIssue({
3898
- code: ZodIssueCode.custom,
3899
- message: "input or previous_response_id is required."
3900
- });
3901
- }
3879
+ model_id: stringType(),
3880
+ messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3881
+ extra_openai_params: recordType(unknownType()).optional()
3902
3882
  });
3903
3883
  objectType({
3904
3884
  id: stringType(),
@@ -4029,7 +4009,7 @@ function convertToLatest(content) {
4029
4009
  }
4030
4010
 
4031
4011
  /** SDK 版本号,构建时由 rollup 注入 */
4032
- const VERSION = '2.14.1';
4012
+ const VERSION = '2.14.2';
4033
4013
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4034
4014
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4035
4015
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4150,10 +4130,10 @@ function buildEmbedSrc(options) {
4150
4130
  const path = getEmbedPath(mode);
4151
4131
  const appId = options.auth?.appId?.trim() ?? '';
4152
4132
  const initialId = options.initialId?.trim();
4153
- if (!initialId) {
4154
- return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
4155
- }
4156
- return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
4133
+ const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4134
+ return mode === 'editor' && options.cameraMode
4135
+ ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4136
+ : src;
4157
4137
  }
4158
4138
 
4159
4139
  class EmbeddedTarget {
@@ -4625,6 +4605,30 @@ class EmbeddedEditor extends EmbeddedTarget {
4625
4605
  },
4626
4606
  };
4627
4607
  }
4608
+ /** Execute a REPL command and synchronize editor state before resolving. */
4609
+ async repl(command) {
4610
+ try {
4611
+ const result = await this.post('repl', { command });
4612
+ this.applyReplState(result.state);
4613
+ return { output: result.output };
4614
+ }
4615
+ catch (error) {
4616
+ // REPL execution can fail after applying some operations.
4617
+ if (error instanceof AlgeoError) {
4618
+ const details = error.details;
4619
+ if (details?.state)
4620
+ this.applyReplState(details.state);
4621
+ }
4622
+ throw error;
4623
+ }
4624
+ }
4625
+ applyReplState(state) {
4626
+ this.currentContent = undefined;
4627
+ this.slideCount = state.slideCount;
4628
+ this.currentSlideIndex = state.currentSlideIndex;
4629
+ this.historyCount = state.historyCount;
4630
+ this.historyCurrentIndex = state.historyCurrentIndex;
4631
+ }
4628
4632
  async initialize(options = {}, baseUrl) {
4629
4633
  if (!options.auth?.appId?.trim()) {
4630
4634
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
@@ -4637,7 +4641,8 @@ class EmbeddedEditor extends EmbeddedTarget {
4637
4641
  await this.init({
4638
4642
  baseUrl,
4639
4643
  auth: options.auth,
4640
- initialId: options.shareId,
4644
+ initialId: options.initialContent ? undefined : options.shareId,
4645
+ cameraMode: options.initialContent ? undefined : options.initialMode,
4641
4646
  });
4642
4647
  if (options.fonts) {
4643
4648
  await this.post('setFontConfig', { config: options.fonts });
@@ -3869,12 +3869,6 @@
3869
3869
  this.name = "AlgeoError";
3870
3870
  }
3871
3871
  };
3872
- objectType({
3873
- text: stringType().optional(),
3874
- images: arrayType(stringType().trim().min(1)).optional(),
3875
- openPanel: booleanType().optional(),
3876
- focus: booleanType().optional()
3877
- }).passthrough();
3878
3872
  var openAiChatMessageV1Schema = objectType({
3879
3873
  role: stringType(),
3880
3874
  content: unionType([
@@ -3888,23 +3882,9 @@
3888
3882
  name: stringType().optional()
3889
3883
  }).passthrough();
3890
3884
  objectType({
3891
- model: stringType().trim().min(1),
3892
- input: unionType([
3893
- stringType(),
3894
- arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())]))
3895
- ]).optional(),
3896
- previous_response_id: stringType().trim().min(1).optional(),
3897
- instructions: stringType().optional(),
3898
- temperature: numberType().min(0).max(2).optional(),
3899
- max_output_tokens: numberType().int().positive().optional(),
3900
- metadata: recordType(unknownType()).optional()
3901
- }).passthrough().superRefine((value, ctx) => {
3902
- if (!("input" in value) && !("previous_response_id" in value)) {
3903
- ctx.addIssue({
3904
- code: ZodIssueCode.custom,
3905
- message: "input or previous_response_id is required."
3906
- });
3907
- }
3885
+ model_id: stringType(),
3886
+ messages: arrayType(unionType([openAiChatMessageV1Schema, recordType(unknownType())])),
3887
+ extra_openai_params: recordType(unknownType()).optional()
3908
3888
  });
3909
3889
  objectType({
3910
3890
  id: stringType(),
@@ -4035,7 +4015,7 @@
4035
4015
  }
4036
4016
 
4037
4017
  /** SDK 版本号,构建时由 rollup 注入 */
4038
- const VERSION = '2.14.1';
4018
+ const VERSION = '2.14.2';
4039
4019
  const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
4040
4020
  const DEFAULT_PRESENTATION_PATH = '/embed/present';
4041
4021
  const DEFAULT_EDITOR_PATH = '/embed/edit';
@@ -4156,10 +4136,10 @@
4156
4136
  const path = getEmbedPath(mode);
4157
4137
  const appId = options.auth?.appId?.trim() ?? '';
4158
4138
  const initialId = options.initialId?.trim();
4159
- if (!initialId) {
4160
- return `${baseUrl}${path}/${encodeURIComponent(appId)}`;
4161
- }
4162
- return `${baseUrl}${path}/${encodeURIComponent(appId)}/${encodeURIComponent(initialId)}`;
4139
+ const src = `${baseUrl}${path}/${encodeURIComponent(appId)}${initialId ? `/${encodeURIComponent(initialId)}` : ''}`;
4140
+ return mode === 'editor' && options.cameraMode
4141
+ ? `${src}?cameraMode=${encodeURIComponent(options.cameraMode)}`
4142
+ : src;
4163
4143
  }
4164
4144
 
4165
4145
  class EmbeddedTarget {
@@ -4631,6 +4611,30 @@
4631
4611
  },
4632
4612
  };
4633
4613
  }
4614
+ /** Execute a REPL command and synchronize editor state before resolving. */
4615
+ async repl(command) {
4616
+ try {
4617
+ const result = await this.post('repl', { command });
4618
+ this.applyReplState(result.state);
4619
+ return { output: result.output };
4620
+ }
4621
+ catch (error) {
4622
+ // REPL execution can fail after applying some operations.
4623
+ if (error instanceof AlgeoError) {
4624
+ const details = error.details;
4625
+ if (details?.state)
4626
+ this.applyReplState(details.state);
4627
+ }
4628
+ throw error;
4629
+ }
4630
+ }
4631
+ applyReplState(state) {
4632
+ this.currentContent = undefined;
4633
+ this.slideCount = state.slideCount;
4634
+ this.currentSlideIndex = state.currentSlideIndex;
4635
+ this.historyCount = state.historyCount;
4636
+ this.historyCurrentIndex = state.historyCurrentIndex;
4637
+ }
4634
4638
  async initialize(options = {}, baseUrl) {
4635
4639
  if (!options.auth?.appId?.trim()) {
4636
4640
  throw new AlgeoError('编辑模式需要提供 auth.appId。', EMBED_ERROR_CODES.MISSING_APP_ID);
@@ -4643,7 +4647,8 @@
4643
4647
  await this.init({
4644
4648
  baseUrl,
4645
4649
  auth: options.auth,
4646
- initialId: options.shareId,
4650
+ initialId: options.initialContent ? undefined : options.shareId,
4651
+ cameraMode: options.initialContent ? undefined : options.initialMode,
4647
4652
  });
4648
4653
  if (options.fonts) {
4649
4654
  await this.post('setFontConfig', { config: options.fonts });
@@ -1,5 +1,5 @@
1
1
  import { EmbeddedTarget } from './embedded-target';
2
- import { type AiApi, type AiCancelEvent, type AlgeoEditorCreateOptions, type ContentChangeEvent, type DocumentApi, type EmbedRequestMessage, type EmbeddedEditorEventListenerMap, type EmbeddedEditorEventMap, type EmbeddedEditorEventName, type HistoryApi, type ModeApi, type SaveEvent, type SlidesApi } from './shared';
2
+ import { type AiApi, type AiCancelEvent, type ReplResult, type AlgeoEditorCreateOptions, type ContentChangeEvent, type DocumentApi, type EmbedRequestMessage, type EmbeddedEditorEventListenerMap, type EmbeddedEditorEventMap, type EmbeddedEditorEventName, type HistoryApi, type ModeApi, type SaveEvent, type SlidesApi } from './shared';
3
3
  export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedEditorEventListenerMap> {
4
4
  private resourceLibrary?;
5
5
  private readonly resourceLibraryRequests;
@@ -16,6 +16,9 @@ export declare class EmbeddedEditor extends EmbeddedTarget<EmbeddedEditorEventMa
16
16
  private uiConfig;
17
17
  private activeAiRun?;
18
18
  constructor(container: HTMLElement);
19
+ /** Execute a REPL command and synchronize editor state before resolving. */
20
+ repl(command: string): Promise<ReplResult>;
21
+ private applyReplState;
19
22
  initialize(options?: AlgeoEditorCreateOptions, baseUrl?: string): Promise<void>;
20
23
  protected handleEventMessage(event: ContentChangeEvent | SaveEvent | {
21
24
  type: 'slideChange';
package/dist/shared.d.ts CHANGED
@@ -76,6 +76,8 @@ export interface AlgeoEditorCreateOptions {
76
76
  auth?: AlgeoEditorAuthOptions;
77
77
  shareId?: string;
78
78
  initialContent?: FileContentAny;
79
+ /** 空白画板模式,默认 2d。初始化优先级:initialContent > shareId > 空白画板。 */
80
+ initialMode?: '2d' | '3d';
79
81
  ui?: AlgeoEditorUiConfig;
80
82
  /** 字体资源、字体选择器列表及默认字体配置。 */
81
83
  fonts?: AlgeoFontConfig;
@@ -478,6 +480,7 @@ export declare function normalizeMode(mode?: AlgeoEmbedMode): AlgeoEmbedMode;
478
480
  export declare function getEmbedPath(mode: AlgeoEmbedMode): string;
479
481
  export interface EmbedInitOptions extends AlgeoSdkOptions {
480
482
  auth?: AlgeoEditorAuthOptions;
483
+ cameraMode?: '2d' | '3d';
481
484
  }
482
485
  export declare function buildEmbedSrc(options: EmbedInitOptions): string;
483
486
  export type KnownEventName = 'ready' | 'contentChange' | 'slideChange' | 'save' | 'aiRequest' | 'aiCancel';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "2.14.1",
3
+ "version": "2.14.2",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",