@sprucelabs/sprucebot-llm 8.1.3 → 8.2.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.
- package/build/.spruce/errors/errors.types.d.ts +28 -0
- package/build/.spruce/errors/options.types.d.ts +4 -1
- package/build/.spruce/errors/sprucebotLlm/invalidCallback.schema.d.ts +3 -0
- package/build/.spruce/errors/sprucebotLlm/invalidCallback.schema.js +26 -0
- package/build/errors/SpruceError.js +3 -0
- package/build/errors/invalidCallback.builder.d.ts +17 -0
- package/build/errors/invalidCallback.builder.js +19 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +28 -0
- package/build/esm/.spruce/errors/options.types.d.ts +4 -1
- package/build/esm/errors/SpruceError.js +3 -0
- package/build/esm/errors/invalidCallback.builder.d.ts +17 -0
- package/build/esm/errors/invalidCallback.builder.js +17 -0
- package/build/esm/parsingResponses/ResponseParser.js +11 -1
- package/build/parsingResponses/ResponseParser.js +10 -0
- package/package.json +3 -3
|
@@ -11,3 +11,31 @@ export declare namespace SpruceErrors.SprucebotLlm {
|
|
|
11
11
|
}
|
|
12
12
|
type NoBotInstanceSetEntity = SchemaEntity<SpruceErrors.SprucebotLlm.NoBotInstanceSetSchema>;
|
|
13
13
|
}
|
|
14
|
+
export declare namespace SpruceErrors.SprucebotLlm {
|
|
15
|
+
interface InvalidCallback {
|
|
16
|
+
'validCallbacks': string[];
|
|
17
|
+
'matchedCallback': string;
|
|
18
|
+
}
|
|
19
|
+
interface InvalidCallbackSchema extends SpruceSchema.Schema {
|
|
20
|
+
id: 'invalidCallback';
|
|
21
|
+
namespace: 'SprucebotLlm';
|
|
22
|
+
name: 'Invalid callback';
|
|
23
|
+
fields: {
|
|
24
|
+
/** . */
|
|
25
|
+
'validCallbacks': {
|
|
26
|
+
type: 'text';
|
|
27
|
+
isRequired: true;
|
|
28
|
+
isArray: true;
|
|
29
|
+
minArrayLength: 0;
|
|
30
|
+
options: undefined;
|
|
31
|
+
};
|
|
32
|
+
/** . */
|
|
33
|
+
'matchedCallback': {
|
|
34
|
+
type: 'text';
|
|
35
|
+
isRequired: true;
|
|
36
|
+
options: undefined;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
type InvalidCallbackEntity = SchemaEntity<SpruceErrors.SprucebotLlm.InvalidCallbackSchema>;
|
|
41
|
+
}
|
|
@@ -3,5 +3,8 @@ import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
|
|
|
3
3
|
export interface NoBotInstanceSetErrorOptions extends SpruceErrors.SprucebotLlm.NoBotInstanceSet, ISpruceErrorOptions {
|
|
4
4
|
code: 'NO_BOT_INSTANCE_SET';
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
export interface InvalidCallbackErrorOptions extends SpruceErrors.SprucebotLlm.InvalidCallback, ISpruceErrorOptions {
|
|
7
|
+
code: 'INVALID_CALLBACK';
|
|
8
|
+
}
|
|
9
|
+
type ErrorOptions = NoBotInstanceSetErrorOptions | InvalidCallbackErrorOptions;
|
|
7
10
|
export default ErrorOptions;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
const invalidCallbackSchema = {
|
|
5
|
+
id: 'invalidCallback',
|
|
6
|
+
namespace: 'SprucebotLlm',
|
|
7
|
+
name: 'Invalid callback',
|
|
8
|
+
fields: {
|
|
9
|
+
/** . */
|
|
10
|
+
'validCallbacks': {
|
|
11
|
+
type: 'text',
|
|
12
|
+
isRequired: true,
|
|
13
|
+
isArray: true,
|
|
14
|
+
minArrayLength: 0,
|
|
15
|
+
options: undefined
|
|
16
|
+
},
|
|
17
|
+
/** . */
|
|
18
|
+
'matchedCallback': {
|
|
19
|
+
type: 'text',
|
|
20
|
+
isRequired: true,
|
|
21
|
+
options: undefined
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(invalidCallbackSchema);
|
|
26
|
+
exports.default = invalidCallbackSchema;
|
|
@@ -13,6 +13,9 @@ class SpruceError extends error_1.default {
|
|
|
13
13
|
case 'NO_BOT_INSTANCE_SET':
|
|
14
14
|
message = `You must create a bot and set it using 'SprucebotLlmFactory.setInstance(bot)' before you can get an instance of it.`;
|
|
15
15
|
break;
|
|
16
|
+
case 'INVALID_CALLBACK':
|
|
17
|
+
message = `The callback you tried to invoke (${options.matchedCallback}) is not valid. Valid callbacks are:\n${options.validCallbacks.map((name, idx) => `${idx + 1}: ${name}`).join('\n')}`;
|
|
18
|
+
break;
|
|
16
19
|
default:
|
|
17
20
|
message = super.friendlyMessage();
|
|
18
21
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
fields: {
|
|
5
|
+
validCallbacks: {
|
|
6
|
+
type: "text";
|
|
7
|
+
isRequired: true;
|
|
8
|
+
isArray: true;
|
|
9
|
+
minArrayLength: number;
|
|
10
|
+
};
|
|
11
|
+
matchedCallback: {
|
|
12
|
+
type: "text";
|
|
13
|
+
isRequired: true;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
exports.default = (0, schema_1.buildErrorSchema)({
|
|
5
|
+
id: 'invalidCallback',
|
|
6
|
+
name: 'Invalid callback',
|
|
7
|
+
fields: {
|
|
8
|
+
validCallbacks: {
|
|
9
|
+
type: 'text',
|
|
10
|
+
isRequired: true,
|
|
11
|
+
isArray: true,
|
|
12
|
+
minArrayLength: 0,
|
|
13
|
+
},
|
|
14
|
+
matchedCallback: {
|
|
15
|
+
type: 'text',
|
|
16
|
+
isRequired: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -11,3 +11,31 @@ export declare namespace SpruceErrors.SprucebotLlm {
|
|
|
11
11
|
}
|
|
12
12
|
type NoBotInstanceSetEntity = SchemaEntity<SpruceErrors.SprucebotLlm.NoBotInstanceSetSchema>;
|
|
13
13
|
}
|
|
14
|
+
export declare namespace SpruceErrors.SprucebotLlm {
|
|
15
|
+
interface InvalidCallback {
|
|
16
|
+
'validCallbacks': string[];
|
|
17
|
+
'matchedCallback': string;
|
|
18
|
+
}
|
|
19
|
+
interface InvalidCallbackSchema extends SpruceSchema.Schema {
|
|
20
|
+
id: 'invalidCallback';
|
|
21
|
+
namespace: 'SprucebotLlm';
|
|
22
|
+
name: 'Invalid callback';
|
|
23
|
+
fields: {
|
|
24
|
+
/** . */
|
|
25
|
+
'validCallbacks': {
|
|
26
|
+
type: 'text';
|
|
27
|
+
isRequired: true;
|
|
28
|
+
isArray: true;
|
|
29
|
+
minArrayLength: 0;
|
|
30
|
+
options: undefined;
|
|
31
|
+
};
|
|
32
|
+
/** . */
|
|
33
|
+
'matchedCallback': {
|
|
34
|
+
type: 'text';
|
|
35
|
+
isRequired: true;
|
|
36
|
+
options: undefined;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
type InvalidCallbackEntity = SchemaEntity<SpruceErrors.SprucebotLlm.InvalidCallbackSchema>;
|
|
41
|
+
}
|
|
@@ -3,5 +3,8 @@ import { ErrorOptions as ISpruceErrorOptions } from "@sprucelabs/error";
|
|
|
3
3
|
export interface NoBotInstanceSetErrorOptions extends SpruceErrors.SprucebotLlm.NoBotInstanceSet, ISpruceErrorOptions {
|
|
4
4
|
code: 'NO_BOT_INSTANCE_SET';
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
export interface InvalidCallbackErrorOptions extends SpruceErrors.SprucebotLlm.InvalidCallback, ISpruceErrorOptions {
|
|
7
|
+
code: 'INVALID_CALLBACK';
|
|
8
|
+
}
|
|
9
|
+
type ErrorOptions = NoBotInstanceSetErrorOptions | InvalidCallbackErrorOptions;
|
|
7
10
|
export default ErrorOptions;
|
|
@@ -8,6 +8,9 @@ export default class SpruceError extends BaseSpruceError {
|
|
|
8
8
|
case 'NO_BOT_INSTANCE_SET':
|
|
9
9
|
message = `You must create a bot and set it using 'SprucebotLlmFactory.setInstance(bot)' before you can get an instance of it.`;
|
|
10
10
|
break;
|
|
11
|
+
case 'INVALID_CALLBACK':
|
|
12
|
+
message = `The callback you tried to invoke (${options.matchedCallback}) is not valid. Valid callbacks are:\n${options.validCallbacks.map((name, idx) => `${idx + 1}: ${name}`).join('\n')}`;
|
|
13
|
+
break;
|
|
11
14
|
default:
|
|
12
15
|
message = super.friendlyMessage();
|
|
13
16
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
fields: {
|
|
5
|
+
validCallbacks: {
|
|
6
|
+
type: "text";
|
|
7
|
+
isRequired: true;
|
|
8
|
+
isArray: true;
|
|
9
|
+
minArrayLength: number;
|
|
10
|
+
};
|
|
11
|
+
matchedCallback: {
|
|
12
|
+
type: "text";
|
|
13
|
+
isRequired: true;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { buildErrorSchema } from '@sprucelabs/schema';
|
|
2
|
+
export default buildErrorSchema({
|
|
3
|
+
id: 'invalidCallback',
|
|
4
|
+
name: 'Invalid callback',
|
|
5
|
+
fields: {
|
|
6
|
+
validCallbacks: {
|
|
7
|
+
type: 'text',
|
|
8
|
+
isRequired: true,
|
|
9
|
+
isArray: true,
|
|
10
|
+
minArrayLength: 0,
|
|
11
|
+
},
|
|
12
|
+
matchedCallback: {
|
|
13
|
+
type: 'text',
|
|
14
|
+
isRequired: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { DONE_TOKEN, STATE_BOUNDARY } from '../bots/templates.js';
|
|
11
|
+
import SpruceError from '../errors/SpruceError.js';
|
|
11
12
|
import renderLegacyPlaceholder from './renderPlaceholder.js';
|
|
12
13
|
class ResponseParser {
|
|
13
14
|
static setInstance(parser) {
|
|
@@ -18,7 +19,7 @@ class ResponseParser {
|
|
|
18
19
|
}
|
|
19
20
|
parse(response, callbacks) {
|
|
20
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
var _a;
|
|
22
|
+
var _a, _b;
|
|
22
23
|
let message = response.replace(DONE_TOKEN, '').trim();
|
|
23
24
|
let state;
|
|
24
25
|
let callbackResults;
|
|
@@ -43,6 +44,15 @@ class ResponseParser {
|
|
|
43
44
|
message = message.replace(simpleMatches[0], '').trim();
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
let extraMatches = message.match(new RegExp(`<<(.*)\/>>`, 'g'));
|
|
48
|
+
if (extraMatches && ((_b = extraMatches === null || extraMatches === void 0 ? void 0 : extraMatches.length) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
49
|
+
debugger;
|
|
50
|
+
throw new SpruceError({
|
|
51
|
+
code: 'INVALID_CALLBACK',
|
|
52
|
+
validCallbacks: Object.keys(callbacks !== null && callbacks !== void 0 ? callbacks : {}),
|
|
53
|
+
matchedCallback: extraMatches[0],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
46
56
|
const { match, fullMatch } = this.parseState(message);
|
|
47
57
|
if (match && fullMatch) {
|
|
48
58
|
message = message.replace(fullMatch, '').trim();
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const templates_1 = require("../bots/templates");
|
|
7
|
+
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
7
8
|
const renderPlaceholder_1 = __importDefault(require("./renderPlaceholder"));
|
|
8
9
|
class ResponseParser {
|
|
9
10
|
static setInstance(parser) {
|
|
@@ -37,6 +38,15 @@ class ResponseParser {
|
|
|
37
38
|
message = message.replace(simpleMatches[0], '').trim();
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
let extraMatches = message.match(new RegExp(`<<(.*)\/>>`, 'g'));
|
|
42
|
+
if (extraMatches && (extraMatches?.length ?? 0) > 0) {
|
|
43
|
+
debugger;
|
|
44
|
+
throw new SpruceError_1.default({
|
|
45
|
+
code: 'INVALID_CALLBACK',
|
|
46
|
+
validCallbacks: Object.keys(callbacks ?? {}),
|
|
47
|
+
matchedCallback: extraMatches[0],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
40
50
|
const { match, fullMatch } = this.parseState(message);
|
|
41
51
|
if (match && fullMatch) {
|
|
42
52
|
message = message.replace(fullMatch, '').trim();
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@sprucelabs/spruce-test-fixtures"
|
|
10
10
|
]
|
|
11
11
|
},
|
|
12
|
-
"version": "8.
|
|
12
|
+
"version": "8.2.0",
|
|
13
13
|
"files": [
|
|
14
14
|
"build"
|
|
15
15
|
],
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@sprucelabs/error": "^6.0.566",
|
|
57
|
-
"@sprucelabs/mercury-event-emitter": "^42.0.
|
|
57
|
+
"@sprucelabs/mercury-event-emitter": "^42.0.692",
|
|
58
58
|
"@sprucelabs/mercury-types": "^47.2.0",
|
|
59
59
|
"@sprucelabs/schema": "^31.0.19",
|
|
60
60
|
"@sprucelabs/spruce-skill-utils": "^31.2.18",
|
|
61
61
|
"eta": "^3.5.0",
|
|
62
|
-
"openai": "^4.
|
|
62
|
+
"openai": "^4.80.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@sprucelabs/esm-postbuild": "^6.0.540",
|