@miso.ai/client-sdk-dev-tool 1.14.0-beta.2 → 1.14.0-beta.4
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/dist/cjs/debug.js +69 -10
- package/package.json +4 -4
- package/src/debug.js +58 -9
package/dist/cjs/debug.js
CHANGED
|
@@ -8,6 +8,12 @@ var _logs = require("./logs.js");
|
|
|
8
8
|
const _excluded = ["groupName", "apiName", "url", "bulk"];
|
|
9
9
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
10
10
|
const ID = 'std:debug';
|
|
11
|
+
|
|
12
|
+
// the item subworkflow contexts emit per item (one workflow per thread of
|
|
13
|
+
// the list, per message of the conversation), which floods the console.
|
|
14
|
+
// Muted paths stay out of the console only: they are still preserved for
|
|
15
|
+
// the log dump. Configurable via the `mute` option (`mute: []` shows all)
|
|
16
|
+
const DEFAULT_MUTE = Object.freeze(['workflow/thread-items', 'workflow/message-items']);
|
|
11
17
|
class DebugPlugin {
|
|
12
18
|
constructor(options = {}) {
|
|
13
19
|
this._options = options;
|
|
@@ -56,6 +62,10 @@ class DebugPlugin {
|
|
|
56
62
|
}));
|
|
57
63
|
return;
|
|
58
64
|
}
|
|
65
|
+
if (path.length === 1 && (name === 'workflow' || name === 'postworkflow')) {
|
|
66
|
+
this._handleClientWorkflowEvent(name, data);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
59
69
|
break;
|
|
60
70
|
case 'plugins':
|
|
61
71
|
if (path.length === 1) {
|
|
@@ -114,8 +124,18 @@ class DebugPlugin {
|
|
|
114
124
|
}
|
|
115
125
|
this._log('plugins', eventName, `${plugin.id || '(anonymous)'}`, [plugin, ...data]);
|
|
116
126
|
}
|
|
127
|
+
|
|
128
|
+
// a workflow's creation events on the client follow its context: the
|
|
129
|
+
// workflows of a muted context (the item subworkflows) are muted as well
|
|
130
|
+
_handleClientWorkflowEvent(name, workflow) {
|
|
131
|
+
const context = workflow && workflow._context;
|
|
132
|
+
const silent = !!context && this._isMuted(_joinPath(_pluginComponentPath(context.meta.path)));
|
|
133
|
+
this._logw('client', name, workflow, {
|
|
134
|
+
silent
|
|
135
|
+
});
|
|
136
|
+
}
|
|
117
137
|
_handlePluginSpecificEvent(pluginId, path, name, data) {
|
|
118
|
-
this._logw([pluginId, path
|
|
138
|
+
this._logw(_pluginComponentPath([pluginId, ...path]), name, data);
|
|
119
139
|
}
|
|
120
140
|
_getPath(component) {
|
|
121
141
|
const path = [];
|
|
@@ -124,24 +144,49 @@ class DebugPlugin {
|
|
|
124
144
|
}
|
|
125
145
|
return path.reverse();
|
|
126
146
|
}
|
|
127
|
-
_logw(path, name, data) {
|
|
147
|
+
_logw(path, name, data, options) {
|
|
128
148
|
if (data === undefined) {
|
|
129
|
-
|
|
149
|
+
data = [];
|
|
130
150
|
} else if (Array.isArray(data)) {
|
|
131
|
-
|
|
151
|
+
data = data.map(_wrapObj);
|
|
132
152
|
} else {
|
|
133
|
-
|
|
153
|
+
data = [_wrapObj(data)];
|
|
134
154
|
}
|
|
155
|
+
this._logp(path, name, data, options);
|
|
135
156
|
}
|
|
136
157
|
_log(path, name, ...data) {
|
|
137
|
-
this.
|
|
158
|
+
this._logp(path, name, data);
|
|
159
|
+
}
|
|
160
|
+
_logp(path, name, data, {
|
|
161
|
+
silent = false
|
|
162
|
+
} = {}) {
|
|
163
|
+
path = _joinPath(path);
|
|
164
|
+
this._write([_path(path), _name(name), ...data], {
|
|
165
|
+
silent: silent || this._isMuted(path),
|
|
166
|
+
error: name === 'error'
|
|
167
|
+
});
|
|
138
168
|
}
|
|
139
169
|
_logr(...data) {
|
|
170
|
+
this._write(data);
|
|
171
|
+
}
|
|
172
|
+
_write(data, {
|
|
173
|
+
silent = false,
|
|
174
|
+
error = false
|
|
175
|
+
} = {}) {
|
|
140
176
|
const options = this._options.console || {};
|
|
141
177
|
if (this._options.preserveLog) {
|
|
142
178
|
this._logs._logs.push(data);
|
|
143
179
|
}
|
|
144
|
-
|
|
180
|
+
if (silent) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
console.log(_tag(options), _style(options, error), ...data);
|
|
184
|
+
}
|
|
185
|
+
_isMuted(path) {
|
|
186
|
+
const {
|
|
187
|
+
mute = DEFAULT_MUTE
|
|
188
|
+
} = this._options;
|
|
189
|
+
return mute.includes(path);
|
|
145
190
|
}
|
|
146
191
|
}
|
|
147
192
|
exports.default = DebugPlugin;
|
|
@@ -150,16 +195,30 @@ function _tag({
|
|
|
150
195
|
} = {}) {
|
|
151
196
|
return `%c${text}`;
|
|
152
197
|
}
|
|
198
|
+
|
|
199
|
+
// an error event stands out with a red tag
|
|
153
200
|
function _style({
|
|
154
201
|
color = '#fff',
|
|
155
|
-
background = '#334cbb'
|
|
156
|
-
|
|
202
|
+
background = '#334cbb',
|
|
203
|
+
errorBackground = '#c0392b'
|
|
204
|
+
} = {}, error = false) {
|
|
205
|
+
background = error ? errorBackground : background;
|
|
157
206
|
return `color: ${color}; background-color: ${background}; padding: 2px 2px 1px 4px;`;
|
|
158
207
|
}
|
|
159
208
|
|
|
160
209
|
// format path
|
|
161
210
|
function _path(path) {
|
|
162
|
-
return `<${
|
|
211
|
+
return `<${path}>`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// the log path of a component under a plugin, off its meta path — which
|
|
215
|
+
// starts at the plugin ([pluginId, ...rest]): the plugins root reaches the
|
|
216
|
+
// plugins as subtrees, not as parents
|
|
217
|
+
function _pluginComponentPath(path) {
|
|
218
|
+
return [path[0], path.slice(1).join('.')];
|
|
219
|
+
}
|
|
220
|
+
function _joinPath(path) {
|
|
221
|
+
return typeof path === 'string' ? path : path.filter(v => v).join('/');
|
|
163
222
|
}
|
|
164
223
|
|
|
165
224
|
// format event name
|
package/package.json
CHANGED
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@miso.ai/commons": "1.14.0-beta.
|
|
34
|
-
"@miso.ai/doggoganger": "^0.10.0-beta.
|
|
35
|
-
"@miso.ai/lorem": "^0.10.0-beta.
|
|
33
|
+
"@miso.ai/commons": "1.14.0-beta.4",
|
|
34
|
+
"@miso.ai/doggoganger": "^0.10.0-beta.18",
|
|
35
|
+
"@miso.ai/lorem": "^0.10.0-beta.18"
|
|
36
36
|
},
|
|
37
|
-
"version": "1.14.0-beta.
|
|
37
|
+
"version": "1.14.0-beta.4"
|
|
38
38
|
}
|
package/src/debug.js
CHANGED
|
@@ -2,6 +2,12 @@ import { Logs } from './logs.js';
|
|
|
2
2
|
|
|
3
3
|
const ID = 'std:debug';
|
|
4
4
|
|
|
5
|
+
// the item subworkflow contexts emit per item (one workflow per thread of
|
|
6
|
+
// the list, per message of the conversation), which floods the console.
|
|
7
|
+
// Muted paths stay out of the console only: they are still preserved for
|
|
8
|
+
// the log dump. Configurable via the `mute` option (`mute: []` shows all)
|
|
9
|
+
const DEFAULT_MUTE = Object.freeze(['workflow/thread-items', 'workflow/message-items']);
|
|
10
|
+
|
|
5
11
|
export default class DebugPlugin {
|
|
6
12
|
|
|
7
13
|
constructor(options = {}) {
|
|
@@ -55,6 +61,10 @@ export default class DebugPlugin {
|
|
|
55
61
|
this._handleApiEvent(name, { ...data, groupName: path[2] });
|
|
56
62
|
return;
|
|
57
63
|
}
|
|
64
|
+
if (path.length === 1 && (name === 'workflow' || name === 'postworkflow')) {
|
|
65
|
+
this._handleClientWorkflowEvent(name, data);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
58
68
|
break;
|
|
59
69
|
case 'plugins':
|
|
60
70
|
if (path.length === 1) {
|
|
@@ -103,8 +113,16 @@ export default class DebugPlugin {
|
|
|
103
113
|
this._log('plugins', eventName, `${plugin.id || '(anonymous)'}`, [plugin, ...data]);
|
|
104
114
|
}
|
|
105
115
|
|
|
116
|
+
// a workflow's creation events on the client follow its context: the
|
|
117
|
+
// workflows of a muted context (the item subworkflows) are muted as well
|
|
118
|
+
_handleClientWorkflowEvent(name, workflow) {
|
|
119
|
+
const context = workflow && workflow._context;
|
|
120
|
+
const silent = !!context && this._isMuted(_joinPath(_pluginComponentPath(context.meta.path)));
|
|
121
|
+
this._logw('client', name, workflow, { silent });
|
|
122
|
+
}
|
|
123
|
+
|
|
106
124
|
_handlePluginSpecificEvent(pluginId, path, name, data) {
|
|
107
|
-
this._logw([pluginId, path
|
|
125
|
+
this._logw(_pluginComponentPath([pluginId, ...path]), name, data);
|
|
108
126
|
}
|
|
109
127
|
|
|
110
128
|
_getPath(component) {
|
|
@@ -115,26 +133,44 @@ export default class DebugPlugin {
|
|
|
115
133
|
return path.reverse();
|
|
116
134
|
}
|
|
117
135
|
|
|
118
|
-
_logw(path, name, data) {
|
|
136
|
+
_logw(path, name, data, options) {
|
|
119
137
|
if (data === undefined) {
|
|
120
|
-
|
|
138
|
+
data = [];
|
|
121
139
|
} else if (Array.isArray(data)) {
|
|
122
|
-
|
|
140
|
+
data = data.map(_wrapObj);
|
|
123
141
|
} else {
|
|
124
|
-
|
|
142
|
+
data = [_wrapObj(data)];
|
|
125
143
|
}
|
|
144
|
+
this._logp(path, name, data, options);
|
|
126
145
|
}
|
|
127
146
|
|
|
128
147
|
_log(path, name, ...data) {
|
|
129
|
-
this.
|
|
148
|
+
this._logp(path, name, data);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_logp(path, name, data, { silent = false } = {}) {
|
|
152
|
+
path = _joinPath(path);
|
|
153
|
+
this._write([_path(path), _name(name), ...data], { silent: silent || this._isMuted(path), error: name === 'error' });
|
|
130
154
|
}
|
|
131
155
|
|
|
132
156
|
_logr(...data) {
|
|
157
|
+
this._write(data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_write(data, { silent = false, error = false } = {}) {
|
|
133
161
|
const options = this._options.console || {};
|
|
134
162
|
if (this._options.preserveLog) {
|
|
135
163
|
this._logs._logs.push(data);
|
|
136
164
|
}
|
|
137
|
-
|
|
165
|
+
if (silent) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
console.log(_tag(options), _style(options, error), ...data);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_isMuted(path) {
|
|
172
|
+
const { mute = DEFAULT_MUTE } = this._options;
|
|
173
|
+
return mute.includes(path);
|
|
138
174
|
}
|
|
139
175
|
|
|
140
176
|
}
|
|
@@ -143,13 +179,26 @@ function _tag({ text = 'Miso' } = {}) {
|
|
|
143
179
|
return `%c${text}`;
|
|
144
180
|
}
|
|
145
181
|
|
|
146
|
-
|
|
182
|
+
// an error event stands out with a red tag
|
|
183
|
+
function _style({ color = '#fff', background = '#334cbb', errorBackground = '#c0392b' } = {}, error = false) {
|
|
184
|
+
background = error ? errorBackground : background;
|
|
147
185
|
return `color: ${color}; background-color: ${background}; padding: 2px 2px 1px 4px;`;
|
|
148
186
|
}
|
|
149
187
|
|
|
150
188
|
// format path
|
|
151
189
|
function _path(path) {
|
|
152
|
-
return `<${
|
|
190
|
+
return `<${path}>`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// the log path of a component under a plugin, off its meta path — which
|
|
194
|
+
// starts at the plugin ([pluginId, ...rest]): the plugins root reaches the
|
|
195
|
+
// plugins as subtrees, not as parents
|
|
196
|
+
function _pluginComponentPath(path) {
|
|
197
|
+
return [path[0], path.slice(1).join('.')];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function _joinPath(path) {
|
|
201
|
+
return typeof path === 'string' ? path : path.filter(v => v).join('/');
|
|
153
202
|
}
|
|
154
203
|
|
|
155
204
|
// format event name
|