backend-manager 3.2.38 → 3.2.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.2.38",
3
+ "version": "3.2.40",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -86,20 +86,40 @@ OpenAI.prototype.request = function (options) {
86
86
  return;
87
87
  }
88
88
 
89
- _log('callOpenAI():', ...arguments);
89
+ assistant.log('callOpenAI():', ...arguments);
90
90
  }
91
91
 
92
92
  function _load(input) {
93
93
  // console.log('*** input!!!', input.content.slice(0, 50), input.path);
94
94
  // console.log('*** input.content', input.content.slice(0, 50));
95
95
  // console.log('*** input.path', input.path);
96
- return powertools.template(
97
- input.path ? jetpack.read(input.path) : input.content,
98
- input.settings,
99
- )
100
- .trim();
96
+ // _log('Loading', input);
97
+
98
+ let content = '';
99
+
100
+ // Load content
101
+ if (input.path) {
102
+ if (!jetpack.exists(input.path)) {
103
+ return new Error(`Path ${input.path} not found`);
104
+ }
105
+
106
+ if (jetpack.isDirectory(input.path)) {
107
+ return new Error(`Path ${input.path} is a directory`);
108
+ }
109
+
110
+ try {
111
+ content = jetpack.read(input.path);
112
+ } catch (e) {
113
+ return new Error(`Error reading file ${input.path}: ${e}`);
114
+ }
115
+ } else {
116
+ content = input.content;
117
+ }
118
+
119
+ return powertools.template(content, input.settings).trim();
101
120
  }
102
121
 
122
+ // Log
103
123
  _log('Starting', self.key);
104
124
  _log('Starting', options);
105
125
 
@@ -111,10 +131,20 @@ OpenAI.prototype.request = function (options) {
111
131
  ? { type: 'json_object' }
112
132
  : undefined;
113
133
 
134
+ // Log
114
135
  _log('Prompt', prompt);
115
136
  _log('Message', message);
116
137
  _log('User', user);
117
138
 
139
+ // Check for errors
140
+ if (prompt instanceof Error) {
141
+ return reject(assistant.errorify(`Error loading prompt: ${prompt}`, {code: 400}));
142
+ }
143
+
144
+ if (message instanceof Error) {
145
+ return reject(assistant.errorify(`Error loading message: ${message}`, {code: 400}));
146
+ }
147
+
118
148
  function _request(mode, options) {
119
149
  return new Promise(async function(resolve, reject) {
120
150
  let resultPath = '';