runline 0.12.0 → 0.13.0

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.
@@ -1,4 +1,46 @@
1
- import { buildLocation, compact, extractDocumentId, hexToRgbF, runBatchUpdate, } from "./shared.js";
1
+ import * as t from "typebox";
2
+ import { buildLocation, compact, DocumentInput, extractDocumentId, HexColor, hexToRgbF, LOCATION_REQUIREMENT, LocationInput, PositivePoints, RangeInput, runBatchUpdate, STRICT_OBJECT, } from "./shared.js";
3
+ const PersonProperties = t.Object({ email: t.String({ minLength: 1 }) }, STRICT_OBJECT);
4
+ const RichLinkProperties = t.Object({
5
+ uri: t.String({ minLength: 1 }),
6
+ mimeType: t.Optional(t.String({ minLength: 1 })),
7
+ title: t.Optional(t.String({ minLength: 1 })),
8
+ }, STRICT_OBJECT);
9
+ const DateElementProperties = t.Object({
10
+ timestamp: t.Optional(t.String({ minLength: 1 })),
11
+ timeZoneId: t.Optional(t.String({ minLength: 1 })),
12
+ locale: t.Optional(t.String({ minLength: 1 })),
13
+ dateFormat: t.Optional(t.Union([
14
+ t.Literal("DATE_FORMAT_UNSPECIFIED"),
15
+ t.Literal("DATE_FORMAT_MONTH_DAY_ABBREVIATED"),
16
+ t.Literal("DATE_FORMAT_MONTH_DAY_FULL"),
17
+ t.Literal("DATE_FORMAT_MONTH_DAY_YEAR_ABBREVIATED"),
18
+ t.Literal("DATE_FORMAT_ISO8601"),
19
+ ])),
20
+ timeFormat: t.Optional(t.Union([
21
+ t.Literal("TIME_FORMAT_UNSPECIFIED"),
22
+ t.Literal("TIME_FORMAT_DISABLED"),
23
+ t.Literal("TIME_FORMAT_HOUR_MINUTE"),
24
+ t.Literal("TIME_FORMAT_HOUR_MINUTE_TIMEZONE"),
25
+ ])),
26
+ }, STRICT_OBJECT);
27
+ const BulletPreset = t.Union([
28
+ t.Literal("BULLET_DISC_CIRCLE_SQUARE"),
29
+ t.Literal("BULLET_DIAMONDX_ARROW3D_SQUARE"),
30
+ t.Literal("BULLET_CHECKBOX"),
31
+ t.Literal("BULLET_ARROW_DIAMOND_DISC"),
32
+ t.Literal("BULLET_STAR_CIRCLE_SQUARE"),
33
+ t.Literal("BULLET_ARROW3D_CIRCLE_SQUARE"),
34
+ t.Literal("BULLET_LEFTTRIANGLE_DIAMOND_DISC"),
35
+ t.Literal("BULLET_DIAMONDX_HOLLOWDIAMOND_SQUARE"),
36
+ t.Literal("BULLET_DIAMOND_CIRCLE_SQUARE"),
37
+ t.Literal("NUMBERED_DECIMAL_ALPHA_ROMAN"),
38
+ t.Literal("NUMBERED_DECIMAL_ALPHA_ROMAN_PARENS"),
39
+ t.Literal("NUMBERED_DECIMAL_NESTED"),
40
+ t.Literal("NUMBERED_UPPERALPHA_ALPHA_ROMAN"),
41
+ t.Literal("NUMBERED_UPPERROMAN_UPPERALPHA_DECIMAL"),
42
+ t.Literal("NUMBERED_ZERODECIMAL_ALPHA_ROMAN"),
43
+ ]);
2
44
  function range(p) {
3
45
  return compact({
4
46
  segmentId: p.segmentId && p.segmentId !== "body" ? p.segmentId : "",
@@ -11,26 +53,7 @@ export function registerTextActions(rl) {
11
53
  rl.registerAction("document.insertText", {
12
54
  access: "write",
13
55
  description: "Insert text at a specific index, or at the end of a segment (body/header/footer/footnote).",
14
- inputSchema: {
15
- document: { type: "string", required: true },
16
- text: { type: "string", required: true },
17
- locationKind: {
18
- type: "string",
19
- required: false,
20
- description: "location (default; requires index) | endOfSegmentLocation",
21
- },
22
- index: {
23
- type: "number",
24
- required: false,
25
- description: "Required for locationKind=location",
26
- },
27
- segmentId: {
28
- type: "string",
29
- required: false,
30
- description: 'Segment ID, or "body" / empty for the main body',
31
- },
32
- tabId: { type: "string", required: false },
33
- },
56
+ inputSchema: t.Object({ ...DocumentInput, text: t.String(), ...LocationInput }, { ...STRICT_OBJECT, anyOf: LOCATION_REQUIREMENT }),
34
57
  async execute(input, ctx) {
35
58
  const p = (input ?? {});
36
59
  const documentId = extractDocumentId(p.document);
@@ -44,18 +67,14 @@ export function registerTextActions(rl) {
44
67
  rl.registerAction("document.replaceAllText", {
45
68
  access: "write",
46
69
  description: "Replace every occurrence of a text string throughout the document.",
47
- inputSchema: {
48
- document: { type: "string", required: true },
49
- findText: { type: "string", required: true },
50
- replaceText: { type: "string", required: true },
51
- matchCase: { type: "boolean", required: false },
52
- searchByRegex: { type: "boolean", required: false },
53
- tabIds: {
54
- type: "array",
55
- required: false,
56
- description: "Optional tab IDs for tabsCriteria.",
57
- },
58
- },
70
+ inputSchema: t.Object({
71
+ ...DocumentInput,
72
+ findText: t.String({ minLength: 1 }),
73
+ replaceText: t.String(),
74
+ matchCase: t.Optional(t.Boolean()),
75
+ searchByRegex: t.Optional(t.Boolean()),
76
+ tabIds: t.Optional(t.Array(t.String({ minLength: 1 }), { minItems: 1 })),
77
+ }, STRICT_OBJECT),
59
78
  async execute(input, ctx) {
60
79
  const p = (input ?? {});
61
80
  const documentId = extractDocumentId(p.document);
@@ -77,13 +96,7 @@ export function registerTextActions(rl) {
77
96
  rl.registerAction("document.deleteContentRange", {
78
97
  access: "write",
79
98
  description: "Delete text between two indices in a segment.",
80
- inputSchema: {
81
- document: { type: "string", required: true },
82
- startIndex: { type: "number", required: true },
83
- endIndex: { type: "number", required: true },
84
- segmentId: { type: "string", required: false },
85
- tabId: { type: "string", required: false },
86
- },
99
+ inputSchema: t.Object({ ...DocumentInput, ...RangeInput }, STRICT_OBJECT),
87
100
  async execute(input, ctx) {
88
101
  const p = (input ?? {});
89
102
  const documentId = extractDocumentId(p.document);
@@ -95,14 +108,7 @@ export function registerTextActions(rl) {
95
108
  rl.registerAction("document.createParagraphBullets", {
96
109
  access: "write",
97
110
  description: "Apply a bullet preset to paragraphs spanning a range. Presets: BULLET_DISC_CIRCLE_SQUARE, BULLET_DIAMONDX_ARROW3D_SQUARE, BULLET_CHECKBOX, NUMBERED_DECIMAL_ALPHA_ROMAN, NUMBERED_DECIMAL_NESTED, etc.",
98
- inputSchema: {
99
- document: { type: "string", required: true },
100
- bulletPreset: { type: "string", required: true },
101
- startIndex: { type: "number", required: true },
102
- endIndex: { type: "number", required: true },
103
- segmentId: { type: "string", required: false },
104
- tabId: { type: "string", required: false },
105
- },
111
+ inputSchema: t.Object({ ...DocumentInput, bulletPreset: BulletPreset, ...RangeInput }, STRICT_OBJECT),
106
112
  async execute(input, ctx) {
107
113
  const p = (input ?? {});
108
114
  const documentId = extractDocumentId(p.document);
@@ -117,13 +123,7 @@ export function registerTextActions(rl) {
117
123
  rl.registerAction("document.deleteParagraphBullets", {
118
124
  access: "write",
119
125
  description: "Remove bullets from paragraphs in a range.",
120
- inputSchema: {
121
- document: { type: "string", required: true },
122
- startIndex: { type: "number", required: true },
123
- endIndex: { type: "number", required: true },
124
- segmentId: { type: "string", required: false },
125
- tabId: { type: "string", required: false },
126
- },
126
+ inputSchema: t.Object({ ...DocumentInput, ...RangeInput }, STRICT_OBJECT),
127
127
  async execute(input, ctx) {
128
128
  const p = (input ?? {});
129
129
  const documentId = extractDocumentId(p.document);
@@ -135,22 +135,11 @@ export function registerTextActions(rl) {
135
135
  rl.registerAction("document.insertPerson", {
136
136
  access: "write",
137
137
  description: "Insert a smart chip person mention at a location or at the end of a segment.",
138
- inputSchema: {
139
- document: { type: "string", required: true },
140
- personProperties: {
141
- type: "object",
142
- required: true,
143
- description: "Docs API PersonProperties object.",
144
- },
145
- locationKind: {
146
- type: "string",
147
- required: false,
148
- description: "location (default; requires index) | endOfSegmentLocation",
149
- },
150
- index: { type: "number", required: false },
151
- segmentId: { type: "string", required: false },
152
- tabId: { type: "string", required: false },
153
- },
138
+ inputSchema: t.Object({
139
+ ...DocumentInput,
140
+ personProperties: PersonProperties,
141
+ ...LocationInput,
142
+ }, { ...STRICT_OBJECT, anyOf: LOCATION_REQUIREMENT }),
154
143
  async execute(input, ctx) {
155
144
  const p = (input ?? {});
156
145
  const documentId = extractDocumentId(p.document);
@@ -166,22 +155,11 @@ export function registerTextActions(rl) {
166
155
  rl.registerAction("document.insertRichLink", {
167
156
  access: "write",
168
157
  description: "Insert a rich link smart chip at a location or at the end of a segment.",
169
- inputSchema: {
170
- document: { type: "string", required: true },
171
- richLinkProperties: {
172
- type: "object",
173
- required: true,
174
- description: "Docs API RichLinkProperties object.",
175
- },
176
- locationKind: {
177
- type: "string",
178
- required: false,
179
- description: "location (default; requires index) | endOfSegmentLocation",
180
- },
181
- index: { type: "number", required: false },
182
- segmentId: { type: "string", required: false },
183
- tabId: { type: "string", required: false },
184
- },
158
+ inputSchema: t.Object({
159
+ ...DocumentInput,
160
+ richLinkProperties: RichLinkProperties,
161
+ ...LocationInput,
162
+ }, { ...STRICT_OBJECT, anyOf: LOCATION_REQUIREMENT }),
185
163
  async execute(input, ctx) {
186
164
  const p = (input ?? {});
187
165
  const documentId = extractDocumentId(p.document);
@@ -197,22 +175,11 @@ export function registerTextActions(rl) {
197
175
  rl.registerAction("document.insertDate", {
198
176
  access: "write",
199
177
  description: "Insert a date smart chip at a location or at the end of a segment.",
200
- inputSchema: {
201
- document: { type: "string", required: true },
202
- dateElementProperties: {
203
- type: "object",
204
- required: false,
205
- description: "Optional Docs API DateElementProperties object.",
206
- },
207
- locationKind: {
208
- type: "string",
209
- required: false,
210
- description: "location (default; requires index) | endOfSegmentLocation",
211
- },
212
- index: { type: "number", required: false },
213
- segmentId: { type: "string", required: false },
214
- tabId: { type: "string", required: false },
215
- },
178
+ inputSchema: t.Object({
179
+ ...DocumentInput,
180
+ dateElementProperties: t.Optional(DateElementProperties),
181
+ ...LocationInput,
182
+ }, { ...STRICT_OBJECT, anyOf: LOCATION_REQUIREMENT }),
216
183
  async execute(input, ctx) {
217
184
  const p = (input ?? {});
218
185
  const documentId = extractDocumentId(p.document);
@@ -229,39 +196,33 @@ export function registerTextActions(rl) {
229
196
  });
230
197
  rl.registerAction("document.updateTextStyle", {
231
198
  access: "write",
232
- description: "Apply text styling (bold, italic, underline, color, fontSize, fontFamily, link) to a range. Pass `fields` listing which TextStyle properties were set.",
233
- inputSchema: {
234
- document: { type: "string", required: true },
235
- startIndex: { type: "number", required: true },
236
- endIndex: { type: "number", required: true },
237
- bold: { type: "boolean", required: false },
238
- italic: { type: "boolean", required: false },
239
- underline: { type: "boolean", required: false },
240
- strikethrough: { type: "boolean", required: false },
241
- fontSizePt: {
242
- type: "number",
243
- required: false,
244
- description: "Font size in points.",
245
- },
246
- fontFamily: { type: "string", required: false },
247
- foregroundColorHex: {
248
- type: "string",
249
- required: false,
250
- description: "Hex color, e.g. #1A73E8",
251
- },
252
- backgroundColorHex: { type: "string", required: false },
253
- link: {
254
- type: "string",
255
- required: false,
256
- description: "URL for the linked range.",
257
- },
258
- segmentId: {
259
- type: "string",
260
- required: false,
261
- description: "Header/footer/footnote id; omit for the body.",
262
- },
263
- tabId: { type: "string", required: false },
264
- },
199
+ description: "Apply text styling (bold, italic, underline, color, font size, font family, or link) to a range.",
200
+ inputSchema: t.Object({
201
+ ...DocumentInput,
202
+ ...RangeInput,
203
+ bold: t.Optional(t.Boolean()),
204
+ italic: t.Optional(t.Boolean()),
205
+ underline: t.Optional(t.Boolean()),
206
+ strikethrough: t.Optional(t.Boolean()),
207
+ fontSizePt: t.Optional(PositivePoints),
208
+ fontFamily: t.Optional(t.String({ minLength: 1 })),
209
+ foregroundColorHex: t.Optional(HexColor),
210
+ backgroundColorHex: t.Optional(HexColor),
211
+ link: t.Optional(t.String({ minLength: 1 })),
212
+ }, {
213
+ ...STRICT_OBJECT,
214
+ anyOf: [
215
+ { required: ["bold"] },
216
+ { required: ["italic"] },
217
+ { required: ["underline"] },
218
+ { required: ["strikethrough"] },
219
+ { required: ["fontSizePt"] },
220
+ { required: ["fontFamily"] },
221
+ { required: ["foregroundColorHex"] },
222
+ { required: ["backgroundColorHex"] },
223
+ { required: ["link"] },
224
+ ],
225
+ }),
265
226
  async execute(input, ctx) {
266
227
  const p = (input ?? {});
267
228
  const documentId = extractDocumentId(p.document);