lucid-extension-sdk 0.0.209 → 0.0.210

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/commandtypes.d.ts CHANGED
@@ -122,6 +122,7 @@ export declare const enum CommandName {
122
122
  SetPackageSettings = "sps",
123
123
  SetProperty = "sp",
124
124
  SetReferenceKey = "srk",
125
+ SetSelection = "ss",
125
126
  SetShapeData = "ssd",
126
127
  SetText = "st",
127
128
  SetTextStyle = "sts",
@@ -548,6 +549,10 @@ export type CommandArgs = {
548
549
  query: SetReferenceKeyQuery;
549
550
  result: SetReferenceKeyResult;
550
551
  };
552
+ [CommandName.SetSelection]: {
553
+ query: SetSelectionQuery;
554
+ result: SetSelectionResult;
555
+ };
551
556
  [CommandName.SetShapeData]: {
552
557
  query: SetShapeDataQuery;
553
558
  result: SetShapeDataResult;
@@ -1034,11 +1039,17 @@ export type GetLLMContextFromItemsQuery = {
1034
1039
  /** List of item IDs to return LLM-readable context for */
1035
1040
  'i': string[];
1036
1041
  };
1037
- /**
1038
- * A string in a format that LLMs like ChatGPT can easily understand, representing the content
1039
- * of the items specified as well as their immediate context if necessary
1040
- */
1041
- export type GetLLMContextFromItemsResult = string;
1042
+ export type GetLLMContextFromItemsResult = {
1043
+ /**
1044
+ * A string in a format that LLMs like ChatGPT can easily understand, representing the content
1045
+ * of the items specified as well as their immediate context if necessary
1046
+ */
1047
+ 'p': string;
1048
+ /**
1049
+ * A map from IDs specified in the prompt string to actual Lucid item IDs
1050
+ */
1051
+ 'id': Record<string, string>;
1052
+ };
1042
1053
  export type GetReferenceKeyQuery = {
1043
1054
  /** ID of the LucidElement to read a reference key from, or undefined to read from the LucidDocument */
1044
1055
  'id'?: string | undefined;
@@ -1370,6 +1381,11 @@ export type SetReferenceKeyQuery = {
1370
1381
  'v'?: SerializedReferenceKeyType | undefined;
1371
1382
  };
1372
1383
  export type SetReferenceKeyResult = undefined;
1384
+ export type SetSelectionQuery = {
1385
+ /** IDs of the elements to select */
1386
+ 'i': string[];
1387
+ };
1388
+ export type SetSelectionResult = undefined;
1373
1389
  export type SetShapeDataQuery = {
1374
1390
  /** ID of the element to set this shape data on */
1375
1391
  'id'?: string | undefined;
package/commandtypes.js CHANGED
@@ -99,6 +99,7 @@ exports.commandTitles = new Map([
99
99
  ["sps" /* CommandName.SetPackageSettings */, 'SetPackageSettings'],
100
100
  ["sp" /* CommandName.SetProperty */, 'SetProperty'],
101
101
  ["srk" /* CommandName.SetReferenceKey */, 'SetReferenceKey'],
102
+ ["ss" /* CommandName.SetSelection */, 'SetSelection'],
102
103
  ["ssd" /* CommandName.SetShapeData */, 'SetShapeData'],
103
104
  ["sts" /* CommandName.SetTextStyle */, 'SetTextStyle'],
104
105
  ["sm" /* CommandName.ShowModal */, 'ShowModal'],
@@ -111,7 +111,11 @@ export declare class PageProxy extends ElementProxy {
111
111
  /**
112
112
  * @param items
113
113
  * @returns A string representing the content of the items provided, including immediate surrounding context if
114
- * necessary, in a format that is easily understandable by LLMs like ChatGPT.
114
+ * necessary, in a format that is easily understandable by LLMs like ChatGPT. Also a map of IDs, from the shortened
115
+ * IDs provided for the items in the context to the actual Lucid item IDs.
115
116
  */
116
- getLLMContextForItems(items: ItemProxy[]): string;
117
+ getLLMContextForItems(items: ItemProxy[]): {
118
+ prompt: string;
119
+ idToLucidId: Map<string, string>;
120
+ };
117
121
  }
@@ -177,15 +177,20 @@ class PageProxy extends elementproxy_1.ElementProxy {
177
177
  /**
178
178
  * @param items
179
179
  * @returns A string representing the content of the items provided, including immediate surrounding context if
180
- * necessary, in a format that is easily understandable by LLMs like ChatGPT.
180
+ * necessary, in a format that is easily understandable by LLMs like ChatGPT. Also a map of IDs, from the shortened
181
+ * IDs provided for the items in the context to the actual Lucid item IDs.
181
182
  */
182
183
  getLLMContextForItems(items) {
183
184
  //We don't check that the items are on this page here; that is done in the implementation
184
185
  //of the API command. It would be a lot of extra API calls for no benefit.
185
- return this.client.sendCommand("llm" /* CommandName.GetLLMContextFromItems */, {
186
+ const result = this.client.sendCommand("llm" /* CommandName.GetLLMContextFromItems */, {
186
187
  'p': this.id,
187
188
  'i': items.map((item) => item.id),
188
189
  });
190
+ return {
191
+ prompt: result['p'],
192
+ idToLucidId: new Map(Object.entries(result['id'])),
193
+ };
189
194
  }
190
195
  }
191
196
  exports.PageProxy = PageProxy;
package/editorclient.d.ts CHANGED
@@ -317,6 +317,11 @@ export declare class EditorClient {
317
317
  * @returns the given item
318
318
  */
319
319
  getItemProxy(id: string): BlockProxy | LineProxy | GroupProxy;
320
+ /**
321
+ * @param id ID of the item to create a proxy for
322
+ * @returns the given item, or undefined if the item does not exist or an error occurs
323
+ */
324
+ tryGetItemProxy(id: string): BlockProxy | LineProxy | GroupProxy | undefined;
320
325
  /**
321
326
  * @param id ID of the element to create a proxy for
322
327
  * @returns the given element
package/editorclient.js CHANGED
@@ -516,6 +516,20 @@ class EditorClient {
516
516
  throw new Error('Element ' + id + ' is not an Item; type found is ' + type);
517
517
  }
518
518
  }
519
+ /**
520
+ * @param id ID of the item to create a proxy for
521
+ * @returns the given item, or undefined if the item does not exist or an error occurs
522
+ */
523
+ tryGetItemProxy(id) {
524
+ try {
525
+ const item = this.getItemProxy(id);
526
+ if (item.exists()) {
527
+ return item;
528
+ }
529
+ }
530
+ catch (_a) { }
531
+ return undefined;
532
+ }
519
533
  /**
520
534
  * @param id ID of the element to create a proxy for
521
535
  * @returns the given element
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.209",
3
+ "version": "0.0.210",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/ui/viewport.d.ts CHANGED
@@ -21,6 +21,12 @@ export declare class Viewport {
21
21
  * @returns An array of currently-selected items on the currently-visible page
22
22
  */
23
23
  getSelectedItems(deep?: boolean): ItemProxy[];
24
+ /**
25
+ * Unselect all currently-selected items, and select the subset of the given items that exist on
26
+ * the currently-visible page.
27
+ * @param items
28
+ */
29
+ setSelectedItems(items: ItemProxy[]): void;
24
30
  /**
25
31
  * Find available space on the current page for adding new content.
26
32
  * @param width
package/ui/viewport.js CHANGED
@@ -23,6 +23,14 @@ class Viewport {
23
23
  .map((id) => this.client.getElementProxy(id))
24
24
  .filter((proxy) => proxy instanceof itemproxy_1.ItemProxy);
25
25
  }
26
+ /**
27
+ * Unselect all currently-selected items, and select the subset of the given items that exist on
28
+ * the currently-visible page.
29
+ * @param items
30
+ */
31
+ setSelectedItems(items) {
32
+ this.client.sendCommand("ss" /* CommandName.SetSelection */, { 'i': items.map((i) => i.id) });
33
+ }
26
34
  /**
27
35
  * Find available space on the current page for adding new content.
28
36
  * @param width