@miso.ai/client-sdk-dev-tool 1.14.0-beta.2 → 1.14.0-beta.3
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 +60 -7
- package/package.json +4 -4
- package/src/debug.js +54 -7
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,25 +144,48 @@ 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
|
+
});
|
|
138
167
|
}
|
|
139
168
|
_logr(...data) {
|
|
169
|
+
this._write(data);
|
|
170
|
+
}
|
|
171
|
+
_write(data, {
|
|
172
|
+
silent = false
|
|
173
|
+
} = {}) {
|
|
140
174
|
const options = this._options.console || {};
|
|
141
175
|
if (this._options.preserveLog) {
|
|
142
176
|
this._logs._logs.push(data);
|
|
143
177
|
}
|
|
178
|
+
if (silent) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
144
181
|
console.log(_tag(options), _style(options), ...data);
|
|
145
182
|
}
|
|
183
|
+
_isMuted(path) {
|
|
184
|
+
const {
|
|
185
|
+
mute = DEFAULT_MUTE
|
|
186
|
+
} = this._options;
|
|
187
|
+
return mute.includes(path);
|
|
188
|
+
}
|
|
146
189
|
}
|
|
147
190
|
exports.default = DebugPlugin;
|
|
148
191
|
function _tag({
|
|
@@ -159,7 +202,17 @@ function _style({
|
|
|
159
202
|
|
|
160
203
|
// format path
|
|
161
204
|
function _path(path) {
|
|
162
|
-
return `<${
|
|
205
|
+
return `<${path}>`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// the log path of a component under a plugin, off its meta path — which
|
|
209
|
+
// starts at the plugin ([pluginId, ...rest]): the plugins root reaches the
|
|
210
|
+
// plugins as subtrees, not as parents
|
|
211
|
+
function _pluginComponentPath(path) {
|
|
212
|
+
return [path[0], path.slice(1).join('.')];
|
|
213
|
+
}
|
|
214
|
+
function _joinPath(path) {
|
|
215
|
+
return typeof path === 'string' ? path : path.filter(v => v).join('/');
|
|
163
216
|
}
|
|
164
217
|
|
|
165
218
|
// 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.3",
|
|
34
|
+
"@miso.ai/doggoganger": "^0.10.0-beta.17",
|
|
35
|
+
"@miso.ai/lorem": "^0.10.0-beta.17"
|
|
36
36
|
},
|
|
37
|
-
"version": "1.14.0-beta.
|
|
37
|
+
"version": "1.14.0-beta.3"
|
|
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,28 +133,46 @@ 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) });
|
|
130
154
|
}
|
|
131
155
|
|
|
132
156
|
_logr(...data) {
|
|
157
|
+
this._write(data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_write(data, { silent = false } = {}) {
|
|
133
161
|
const options = this._options.console || {};
|
|
134
162
|
if (this._options.preserveLog) {
|
|
135
163
|
this._logs._logs.push(data);
|
|
136
164
|
}
|
|
165
|
+
if (silent) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
137
168
|
console.log(_tag(options), _style(options), ...data);
|
|
138
169
|
}
|
|
139
170
|
|
|
171
|
+
_isMuted(path) {
|
|
172
|
+
const { mute = DEFAULT_MUTE } = this._options;
|
|
173
|
+
return mute.includes(path);
|
|
174
|
+
}
|
|
175
|
+
|
|
140
176
|
}
|
|
141
177
|
|
|
142
178
|
function _tag({ text = 'Miso' } = {}) {
|
|
@@ -149,7 +185,18 @@ function _style({ color = '#fff', background = '#334cbb' } = {}) {
|
|
|
149
185
|
|
|
150
186
|
// format path
|
|
151
187
|
function _path(path) {
|
|
152
|
-
return `<${
|
|
188
|
+
return `<${path}>`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// the log path of a component under a plugin, off its meta path — which
|
|
192
|
+
// starts at the plugin ([pluginId, ...rest]): the plugins root reaches the
|
|
193
|
+
// plugins as subtrees, not as parents
|
|
194
|
+
function _pluginComponentPath(path) {
|
|
195
|
+
return [path[0], path.slice(1).join('.')];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function _joinPath(path) {
|
|
199
|
+
return typeof path === 'string' ? path : path.filter(v => v).join('/');
|
|
153
200
|
}
|
|
154
201
|
|
|
155
202
|
// format event name
|