@sprucelabs/sprucebot-llm 2.3.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;
@@ -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;
@@ -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>;
@@ -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.3.0",
12
+ "version": "2.4.0",
13
13
  "files": [
14
14
  "build"
15
15
  ],