Skip to content

Commit dbfb8cd

Browse files
committed
Update code
1 parent b705d82 commit dbfb8cd

File tree

138 files changed

+2957
-2692
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+2957
-2692
lines changed

src/box-command.js

Lines changed: 135 additions & 144 deletions
Large diffs are not rendered by default.

src/cli-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const os = require('os');
3+
const os = require('node:os');
44

55
/**
66
* Wrapper for lower-level errors, so we can give reasonable error messages without losing the original message/stack

src/commands/ai/ask.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
const BoxCommand = require('../../box-command');
44
const { Flags } = require('@oclif/core');
5-
const utils = require('../../util');
5+
const utilities = require('../../util');
66

77
class AiAskCommand extends BoxCommand {
88
async run() {
99
const { flags } = await this.parse(AiAskCommand);
10-
let options = {};
11-
options.mode =
12-
flags.items.length > 1 ? 'multiple_item_qa' : 'single_item_qa';
10+
let options = {
11+
mode:
12+
flags.items.length > 1 ? 'multiple_item_qa' : 'single_item_qa',
13+
};
1314

1415
if (flags.prompt) {
1516
options.prompt = flags.prompt;
@@ -49,20 +50,31 @@ AiAskCommand.flags = {
4950
id: '',
5051
type: 'file',
5152
};
52-
const obj = utils.parseStringToObject(input, [
53+
const object = utilities.parseStringToObject(input, [
5354
'id',
5455
'type',
5556
'content',
5657
]);
57-
for (const key in obj) {
58-
if (key === 'id') {
59-
item.id = obj[key];
60-
} else if (key === 'type') {
61-
item.type = obj[key];
62-
} else if (key === 'content') {
63-
item.content = obj[key];
64-
} else {
65-
throw new Error(`Invalid item key ${key}`);
58+
for (const key in object) {
59+
switch (key) {
60+
case 'id': {
61+
item.id = object[key];
62+
63+
break;
64+
}
65+
case 'type': {
66+
item.type = object[key];
67+
68+
break;
69+
}
70+
case 'content': {
71+
item.content = object[key];
72+
73+
break;
74+
}
75+
default: {
76+
throw new Error(`Invalid item key ${key}`);
77+
}
6678
}
6779
}
6880

src/commands/ai/extract-structured.js

Lines changed: 87 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const BoxCommand = require('../../box-command');
44
const { Flags } = require('@oclif/core');
5-
const utils = require('../../util');
5+
const utilities = require('../../util');
66

77
class AiExtractStructuredCommand extends BoxCommand {
88
async run() {
@@ -59,20 +59,28 @@ AiExtractStructuredCommand.flags = {
5959
id: '',
6060
type: 'file',
6161
};
62-
const obj = utils.parseStringToObject(input, [
62+
const object = utilities.parseStringToObject(input, [
6363
'id',
6464
'type',
6565
'content',
6666
]);
67-
for (const key in obj) {
68-
if (key === 'id') {
69-
item.id = obj[key];
70-
} else if (key === 'type') {
71-
item.type = obj[key];
72-
} else if (key === 'content') {
73-
item.content = obj[key];
74-
} else {
75-
throw new Error(`Invalid item key ${key}`);
67+
for (const key in object) {
68+
switch (key) {
69+
case 'id': {
70+
item.id = object[key];
71+
break;
72+
}
73+
case 'type': {
74+
item.type = object[key];
75+
break;
76+
}
77+
case 'content': {
78+
item.content = object[key];
79+
break;
80+
}
81+
default: {
82+
throw new Error(`Invalid item key ${key}`);
83+
}
7684
}
7785
}
7886
if (!item.id) {
@@ -89,20 +97,31 @@ AiExtractStructuredCommand.flags = {
8997
scope: '',
9098
templateKey: '',
9199
};
92-
const obj = utils.parseStringToObject(input, [
100+
const object = utilities.parseStringToObject(input, [
93101
'type',
94102
'scope',
95103
'template_key',
96104
]);
97-
for (const key in obj) {
98-
if (key === 'type') {
99-
metadataTemplate.type = obj[key];
100-
} else if (key === 'scope') {
101-
metadataTemplate.scope = obj[key];
102-
} else if (key === 'template_key') {
103-
metadataTemplate.templateKey = obj[key];
104-
} else {
105-
throw new Error(`Invalid item key ${key}`);
105+
for (const key in object) {
106+
switch (key) {
107+
case 'type': {
108+
metadataTemplate.type = object[key];
109+
110+
break;
111+
}
112+
case 'scope': {
113+
metadataTemplate.scope = object[key];
114+
115+
break;
116+
}
117+
case 'template_key': {
118+
metadataTemplate.templateKey = object[key];
119+
120+
break;
121+
}
122+
default: {
123+
throw new Error(`Invalid item key ${key}`);
124+
}
106125
}
107126
}
108127
return metadataTemplate;
@@ -113,44 +132,64 @@ AiExtractStructuredCommand.flags = {
113132
description: 'The fields to be extracted from the provided items.',
114133
parse(input) {
115134
const fields = {};
116-
const obj = utils.parseStringToObject(input, [
135+
const object = utilities.parseStringToObject(input, [
117136
'key',
118137
'type',
119138
'description',
120139
'prompt',
121140
'displayName',
122141
'options',
123142
]);
124-
for (const key in obj) {
125-
if (key === 'key') {
126-
fields.key = obj[key];
127-
} else if (key === 'type') {
128-
fields.type = obj[key];
129-
} else if (key === 'description') {
130-
fields.description = obj[key];
131-
} else if (key === 'prompt') {
132-
fields.prompt = obj[key];
133-
} else if (key === 'displayName') {
134-
fields.displayName = obj[key];
135-
} else if (key === 'options') {
136-
try {
137-
const parsedOptions = obj[key]
138-
.split(';')
139-
.filter((item) => item)
140-
.map((item) => ({ key: item.trim() }));
141-
if (parsedOptions.length === 0) {
143+
for (const key in object) {
144+
switch (key) {
145+
case 'key': {
146+
fields.key = object[key];
147+
148+
break;
149+
}
150+
case 'type': {
151+
fields.type = object[key];
152+
153+
break;
154+
}
155+
case 'description': {
156+
fields.description = object[key];
157+
158+
break;
159+
}
160+
case 'prompt': {
161+
fields.prompt = object[key];
162+
163+
break;
164+
}
165+
case 'displayName': {
166+
fields.displayName = object[key];
167+
168+
break;
169+
}
170+
case 'options': {
171+
try {
172+
const parsedOptions = object[key]
173+
.split(';')
174+
.filter(Boolean)
175+
.map((item) => ({ key: item.trim() }));
176+
if (parsedOptions.length === 0) {
177+
throw new Error(
178+
'Options field must contain at least one value'
179+
);
180+
}
181+
fields.options = parsedOptions;
182+
} catch (error) {
142183
throw new Error(
143-
'Options field must contain at least one value'
184+
`Error parsing options: ${error.message}`
144185
);
145186
}
146-
fields.options = parsedOptions;
147-
} catch (error) {
148-
throw new Error(
149-
`Error parsing options: ${error.message}`
150-
);
187+
188+
break;
189+
}
190+
default: {
191+
throw new Error(`Invalid item key ${key}`);
151192
}
152-
} else {
153-
throw new Error(`Invalid item key ${key}`);
154193
}
155194
}
156195

src/commands/ai/extract.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const BoxCommand = require('../../box-command');
44
const { Flags } = require('@oclif/core');
5-
const utils = require('../../util');
5+
const utilities = require('../../util');
66

77
class AiExtractCommand extends BoxCommand {
88
async run() {
@@ -52,20 +52,31 @@ AiExtractCommand.flags = {
5252
type: 'file',
5353
};
5454

55-
const obj = utils.parseStringToObject(input, [
55+
const object = utilities.parseStringToObject(input, [
5656
'id',
5757
'type',
5858
'content',
5959
]);
60-
for (const key in obj) {
61-
if (key === 'id') {
62-
item.id = obj[key];
63-
} else if (key === 'type') {
64-
item.type = obj[key];
65-
} else if (key === 'content') {
66-
item.content = obj[key];
67-
} else {
68-
throw new Error(`Invalid item key ${key}`);
60+
for (const key in object) {
61+
switch (key) {
62+
case 'id': {
63+
item.id = object[key];
64+
65+
break;
66+
}
67+
case 'type': {
68+
item.type = object[key];
69+
70+
break;
71+
}
72+
case 'content': {
73+
item.content = object[key];
74+
75+
break;
76+
}
77+
default: {
78+
throw new Error(`Invalid item key ${key}`);
79+
}
6980
}
7081
}
7182
return item;

src/commands/ai/text-gen.js

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const BoxCommand = require('../../box-command');
44
const { Flags } = require('@oclif/core');
5-
const utils = require('../../util');
5+
const utilities = require('../../util');
66

77
class AiTextGenCommand extends BoxCommand {
88
async run() {
@@ -42,22 +42,33 @@ AiTextGenCommand.flags = {
4242
multiple: true,
4343
parse(input) {
4444
const record = {};
45-
const obj = utils.parseStringToObject(input, [
45+
const object = utilities.parseStringToObject(input, [
4646
'prompt',
4747
'answer',
4848
'created-at',
4949
]);
50-
for (const key in obj) {
51-
if (key === 'prompt') {
52-
record.prompt = obj[key];
53-
} else if (key === 'answer') {
54-
record.answer = obj[key];
55-
} else if (key === 'created-at') {
56-
record.created_at = BoxCommand.normalizeDateString(
57-
obj[key]
58-
);
59-
} else {
60-
throw new Error(`Invalid record key ${key}`);
50+
for (const key in object) {
51+
switch (key) {
52+
case 'prompt': {
53+
record.prompt = object[key];
54+
55+
break;
56+
}
57+
case 'answer': {
58+
record.answer = object[key];
59+
60+
break;
61+
}
62+
case 'created-at': {
63+
record.created_at = BoxCommand.normalizeDateString(
64+
object[key]
65+
);
66+
67+
break;
68+
}
69+
default: {
70+
throw new Error(`Invalid record key ${key}`);
71+
}
6172
}
6273
}
6374

@@ -74,20 +85,31 @@ AiTextGenCommand.flags = {
7485
id: '',
7586
type: 'file',
7687
};
77-
const obj = utils.parseStringToObject(input, [
88+
const object = utilities.parseStringToObject(input, [
7889
'id',
7990
'type',
8091
'content',
8192
]);
82-
for (const key in obj) {
83-
if (key === 'id') {
84-
item.id = obj[key];
85-
} else if (key === 'type') {
86-
item.type = obj[key];
87-
} else if (key === 'content') {
88-
item.content = obj[key];
89-
} else {
90-
throw new Error(`Invalid item key ${key}`);
93+
for (const key in object) {
94+
switch (key) {
95+
case 'id': {
96+
item.id = object[key];
97+
98+
break;
99+
}
100+
case 'type': {
101+
item.type = object[key];
102+
103+
break;
104+
}
105+
case 'content': {
106+
item.content = object[key];
107+
108+
break;
109+
}
110+
default: {
111+
throw new Error(`Invalid item key ${key}`);
112+
}
91113
}
92114
}
93115
return item;

0 commit comments

Comments
 (0)