@sprucelabs/sprucebot-llm 2.2.0 → 2.4.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.
@@ -1,18 +1,21 @@
1
1
  import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
2
2
  import { Schema, SchemaValues } from '@sprucelabs/schema';
3
- import { BotOptions, LlmEventContract, LlmMessage, SerializedBot, SprucebotLlmBot } from '../llm.types';
3
+ import { BotOptions, LlmEventContract, LlmMessage, SerializedBot, SprucebotLlmBot, SprucebotLLmSkill } from '../llm.types';
4
4
  export default class SprucebotLlmBotImpl<StateSchema extends Schema = Schema, State extends SchemaValues<StateSchema> = SchemaValues<StateSchema>> extends AbstractEventEmitter<LlmEventContract> implements SprucebotLlmBot<StateSchema, State> {
5
+ static messageMemoryLimit: number;
5
6
  private adapter;
6
7
  private youAre;
7
8
  private stateSchema?;
8
9
  protected state?: Partial<State>;
9
10
  private isDone;
10
11
  protected messages: LlmMessage[];
11
- private skill?;
12
+ protected skill?: SprucebotLLmSkill;
12
13
  constructor(options: BotOptions<StateSchema, State>);
13
14
  markAsDone(): void;
14
15
  getIsDone(): boolean;
15
16
  serialize(): SerializedBot<StateSchema, State>;
16
17
  sendMessage(message: string): Promise<string>;
18
+ private trackMessage;
17
19
  updateState(newState: Partial<State>): Promise<void>;
20
+ setSkill(skill: SprucebotLLmSkill<any>): void;
18
21
  }
@@ -41,7 +41,7 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
41
41
  async sendMessage(message) {
42
42
  var _a, _b;
43
43
  (0, schema_1.assertOptions)({ message }, ['message']);
44
- this.messages.push({
44
+ this.trackMessage({
45
45
  from: 'Me',
46
46
  message,
47
47
  });
@@ -55,15 +55,25 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
55
55
  else if (state) {
56
56
  await ((_b = this.skill) === null || _b === void 0 ? void 0 : _b.updateState(state));
57
57
  }
58
- this.messages.push({
58
+ this.trackMessage({
59
59
  from: 'You',
60
60
  message: parsedResponse,
61
61
  });
62
62
  return parsedResponse;
63
63
  }
64
+ trackMessage(m) {
65
+ if (this.messages.length === SprucebotLlmBotImpl.messageMemoryLimit) {
66
+ this.messages.shift();
67
+ }
68
+ this.messages.push(m);
69
+ }
64
70
  async updateState(newState) {
65
71
  this.state = Object.assign(Object.assign({}, this.state), newState);
66
72
  await this.emit('did-update-state');
67
73
  }
74
+ setSkill(skill) {
75
+ this.skill = skill;
76
+ }
68
77
  }
78
+ SprucebotLlmBotImpl.messageMemoryLimit = 10;
69
79
  exports.default = SprucebotLlmBotImpl;
@@ -3,6 +3,7 @@ export default class SprucebotLlmFactory {
3
3
  private instance?;
4
4
  static FactoryClass?: typeof SprucebotLlmFactory;
5
5
  static BotClass?: new (options: any) => SprucebotLlmBot;
6
+ static SkillClass?: new (options: any) => SprucebotLLmSkill;
6
7
  Bot(options: BotOptions): SprucebotLlmBot;
7
8
  Skill(options: SkillOptions): SprucebotLLmSkill;
8
9
  getBotInstance(): SprucebotLlmBot<import("@sprucelabs/schema").Schema, import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/schema").Schema, false, never, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/schema").Schema, false>>>;
@@ -15,8 +15,9 @@ class SprucebotLlmFactory {
15
15
  return new ((_a = Class !== null && Class !== void 0 ? Class : SprucebotLlmFactory.BotClass) !== null && _a !== void 0 ? _a : SprucebotLlmBotImpl_1.default)(options);
16
16
  }
17
17
  Skill(options) {
18
+ var _a;
18
19
  (0, schema_1.assertOptions)(options, ['yourJobIfYouChooseToAcceptItIs']);
19
- return new SprucebotLlmSkillImpl_1.default(options);
20
+ return new ((_a = SprucebotLlmFactory.SkillClass) !== null && _a !== void 0 ? _a : SprucebotLlmSkillImpl_1.default)(options);
20
21
  }
21
22
  getBotInstance() {
22
23
  if (!this.instance) {
@@ -36,6 +37,7 @@ class SprucebotLlmFactory {
36
37
  static reset() {
37
38
  this.BotClass = undefined;
38
39
  this.FactoryClass = undefined;
40
+ this.SkillClass = undefined;
39
41
  }
40
42
  }
41
43
  exports.default = SprucebotLlmFactory;
@@ -1,18 +1,21 @@
1
1
  import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
2
2
  import { Schema, SchemaValues } from '@sprucelabs/schema';
3
- import { BotOptions, LlmEventContract, LlmMessage, SerializedBot, SprucebotLlmBot } from '../llm.types';
3
+ import { BotOptions, LlmEventContract, LlmMessage, SerializedBot, SprucebotLlmBot, SprucebotLLmSkill } from '../llm.types';
4
4
  export default class SprucebotLlmBotImpl<StateSchema extends Schema = Schema, State extends SchemaValues<StateSchema> = SchemaValues<StateSchema>> extends AbstractEventEmitter<LlmEventContract> implements SprucebotLlmBot<StateSchema, State> {
5
+ static messageMemoryLimit: number;
5
6
  private adapter;
6
7
  private youAre;
7
8
  private stateSchema?;
8
9
  protected state?: Partial<State>;
9
10
  private isDone;
10
11
  protected messages: LlmMessage[];
11
- private skill?;
12
+ protected skill?: SprucebotLLmSkill;
12
13
  constructor(options: BotOptions<StateSchema, State>);
13
14
  markAsDone(): void;
14
15
  getIsDone(): boolean;
15
16
  serialize(): SerializedBot<StateSchema, State>;
16
17
  sendMessage(message: string): Promise<string>;
18
+ private trackMessage;
17
19
  updateState(newState: Partial<State>): Promise<void>;
20
+ setSkill(skill: SprucebotLLmSkill<any>): void;
18
21
  }
@@ -11,7 +11,7 @@ import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
11
11
  import { assertOptions, defaultSchemaValues, } from '@sprucelabs/schema';
12
12
  import { llmEventContract, } from '../llm.types.js';
13
13
  import ResponseParser from '../parsingResponses/ResponseParser.js';
14
- export default class SprucebotLlmBotImpl extends AbstractEventEmitter {
14
+ class SprucebotLlmBotImpl extends AbstractEventEmitter {
15
15
  constructor(options) {
16
16
  const { adapter, youAre, stateSchema, state, skill } = options;
17
17
  super(llmEventContract);
@@ -46,7 +46,7 @@ export default class SprucebotLlmBotImpl extends AbstractEventEmitter {
46
46
  var _a, _b;
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
48
  assertOptions({ message }, ['message']);
49
- this.messages.push({
49
+ this.trackMessage({
50
50
  from: 'Me',
51
51
  message,
52
52
  });
@@ -60,17 +60,28 @@ export default class SprucebotLlmBotImpl extends AbstractEventEmitter {
60
60
  else if (state) {
61
61
  yield ((_b = this.skill) === null || _b === void 0 ? void 0 : _b.updateState(state));
62
62
  }
63
- this.messages.push({
63
+ this.trackMessage({
64
64
  from: 'You',
65
65
  message: parsedResponse,
66
66
  });
67
67
  return parsedResponse;
68
68
  });
69
69
  }
70
+ trackMessage(m) {
71
+ if (this.messages.length === SprucebotLlmBotImpl.messageMemoryLimit) {
72
+ this.messages.shift();
73
+ }
74
+ this.messages.push(m);
75
+ }
70
76
  updateState(newState) {
71
77
  return __awaiter(this, void 0, void 0, function* () {
72
78
  this.state = Object.assign(Object.assign({}, this.state), newState);
73
79
  yield this.emit('did-update-state');
74
80
  });
75
81
  }
82
+ setSkill(skill) {
83
+ this.skill = skill;
84
+ }
76
85
  }
86
+ SprucebotLlmBotImpl.messageMemoryLimit = 10;
87
+ export default SprucebotLlmBotImpl;
@@ -3,6 +3,7 @@ export default class SprucebotLlmFactory {
3
3
  private instance?;
4
4
  static FactoryClass?: typeof SprucebotLlmFactory;
5
5
  static BotClass?: new (options: any) => SprucebotLlmBot;
6
+ static SkillClass?: new (options: any) => SprucebotLLmSkill;
6
7
  Bot(options: BotOptions): SprucebotLlmBot;
7
8
  Skill(options: SkillOptions): SprucebotLLmSkill;
8
9
  getBotInstance(): SprucebotLlmBot<import("@sprucelabs/schema").Schema, import("@sprucelabs/schema").SchemaStaticValues<import("@sprucelabs/schema").Schema, false, never, import("@sprucelabs/schema").StaticSchemaAllValues<import("@sprucelabs/schema").Schema, false>>>;
@@ -10,8 +10,9 @@ export default class SprucebotLlmFactory {
10
10
  return new ((_a = Class !== null && Class !== void 0 ? Class : SprucebotLlmFactory.BotClass) !== null && _a !== void 0 ? _a : SprucebotLlmBotImpl)(options);
11
11
  }
12
12
  Skill(options) {
13
+ var _a;
13
14
  assertOptions(options, ['yourJobIfYouChooseToAcceptItIs']);
14
- return new SprucebotLlmSkillImpl(options);
15
+ return new ((_a = SprucebotLlmFactory.SkillClass) !== null && _a !== void 0 ? _a : SprucebotLlmSkillImpl)(options);
15
16
  }
16
17
  getBotInstance() {
17
18
  if (!this.instance) {
@@ -31,5 +32,6 @@ export default class SprucebotLlmFactory {
31
32
  static reset() {
32
33
  this.BotClass = undefined;
33
34
  this.FactoryClass = undefined;
35
+ this.SkillClass = undefined;
34
36
  }
35
37
  }
@@ -1,4 +1,5 @@
1
1
  export { default as SprucebotLlmFactory } from './bots/SprucebotLlmFactory';
2
2
  export { default as SprucebotLlmBotImpl } from './bots/SprucebotLlmBotImpl';
3
+ export { default as SprucebotLlmSkillImpl } from './bots/SprucebotLlmSkillImpl';
3
4
  export { OpenAiAdapter } from './bots/adapters/OpenAi';
4
5
  export * from './llm.types';
@@ -1,4 +1,5 @@
1
1
  export { default as SprucebotLlmFactory } from './bots/SprucebotLlmFactory.js';
2
2
  export { default as SprucebotLlmBotImpl } from './bots/SprucebotLlmBotImpl.js';
3
+ export { default as SprucebotLlmSkillImpl } from './bots/SprucebotLlmSkillImpl.js';
3
4
  export { OpenAiAdapter } from './bots/adapters/OpenAi.js';
4
5
  export * from './llm.types.js';
@@ -11,6 +11,7 @@ export interface SprucebotLlmBot<StateSchema extends Schema = Schema, State exte
11
11
  sendMessage(message: string): Promise<string>;
12
12
  serialize(): SerializedBot<StateSchema, State>;
13
13
  updateState(state: Partial<State>): Promise<void>;
14
+ setSkill(skill: SprucebotLLmSkill<any>): void;
14
15
  }
15
16
  export interface LlmAdapter {
16
17
  sendMessage(bot: SprucebotLlmBot<Schema>): Promise<string>;
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as SprucebotLlmFactory } from './bots/SprucebotLlmFactory';
2
2
  export { default as SprucebotLlmBotImpl } from './bots/SprucebotLlmBotImpl';
3
+ export { default as SprucebotLlmSkillImpl } from './bots/SprucebotLlmSkillImpl';
3
4
  export { OpenAiAdapter } from './bots/adapters/OpenAi';
4
5
  export * from './llm.types';
package/build/index.js CHANGED
@@ -17,11 +17,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.OpenAiAdapter = exports.SprucebotLlmBotImpl = exports.SprucebotLlmFactory = void 0;
20
+ exports.OpenAiAdapter = exports.SprucebotLlmSkillImpl = exports.SprucebotLlmBotImpl = exports.SprucebotLlmFactory = void 0;
21
21
  var SprucebotLlmFactory_1 = require("./bots/SprucebotLlmFactory");
22
22
  Object.defineProperty(exports, "SprucebotLlmFactory", { enumerable: true, get: function () { return __importDefault(SprucebotLlmFactory_1).default; } });
23
23
  var SprucebotLlmBotImpl_1 = require("./bots/SprucebotLlmBotImpl");
24
24
  Object.defineProperty(exports, "SprucebotLlmBotImpl", { enumerable: true, get: function () { return __importDefault(SprucebotLlmBotImpl_1).default; } });
25
+ var SprucebotLlmSkillImpl_1 = require("./bots/SprucebotLlmSkillImpl");
26
+ Object.defineProperty(exports, "SprucebotLlmSkillImpl", { enumerable: true, get: function () { return __importDefault(SprucebotLlmSkillImpl_1).default; } });
25
27
  var OpenAi_1 = require("./bots/adapters/OpenAi");
26
28
  Object.defineProperty(exports, "OpenAiAdapter", { enumerable: true, get: function () { return OpenAi_1.OpenAiAdapter; } });
27
29
  __exportStar(require("./llm.types"), exports);
@@ -11,6 +11,7 @@ export interface SprucebotLlmBot<StateSchema extends Schema = Schema, State exte
11
11
  sendMessage(message: string): Promise<string>;
12
12
  serialize(): SerializedBot<StateSchema, State>;
13
13
  updateState(state: Partial<State>): Promise<void>;
14
+ setSkill(skill: SprucebotLLmSkill<any>): void;
14
15
  }
15
16
  export interface LlmAdapter {
16
17
  sendMessage(bot: SprucebotLlmBot<Schema>): Promise<string>;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "@sprucelabs/spruce-test-fixtures"
10
10
  ]
11
11
  },
12
- "version": "2.2.0",
12
+ "version": "2.4.0",
13
13
  "files": [
14
14
  "build"
15
15
  ],