@sprucelabs/sprucebot-llm 13.1.3 → 13.1.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.
@@ -0,0 +1,5 @@
1
+ import SprucebotLlmBotImpl from './SprucebotLlmBotImpl';
2
+ import SprucebotLlmSkillImpl from './SprucebotLlmSkillImpl';
3
+ export default class InternalStateUpdater {
4
+ static updateState(skill: SprucebotLlmSkillImpl | SprucebotLlmBotImpl, updates: Record<string, any>): Promise<void>;
5
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@sprucelabs/schema");
4
+ class InternalStateUpdater {
5
+ static async updateState(skill, updates) {
6
+ (0, schema_1.validateSchemaValues)(skill.getStateSchema(), updates);
7
+ const state = { ...skill.getState(), ...updates };
8
+ const normalized = (0, schema_1.normalizeSchemaValues)(skill.getStateSchema(), state, {
9
+ shouldIncludeNullAndUndefinedFields: false,
10
+ });
11
+ skill.silentlySetState(normalized);
12
+ await skill.emit('did-update-state');
13
+ }
14
+ }
15
+ exports.default = InternalStateUpdater;
@@ -19,6 +19,9 @@ export default class SprucebotLlmBotImpl<StateSchema extends Schema = Schema, St
19
19
  sendMessage(message: SendMessage, cb?: MessageResponseCallback): Promise<string>;
20
20
  private optionallyUpdateState;
21
21
  private trackMessage;
22
- updateState(newState: Partial<State>): Promise<void>;
22
+ updateState(updates: Partial<State>): Promise<void>;
23
23
  setSkill(skill: SprucebotLLmSkill<any>): void;
24
+ getStateSchema(): StateSchema | undefined;
25
+ getState(): Partial<State> | undefined;
26
+ silentlySetState(state: Partial<State>): void;
24
27
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const mercury_event_emitter_1 = require("@sprucelabs/mercury-event-emitter");
7
7
  const schema_1 = require("@sprucelabs/schema");
8
8
  const llm_types_1 = require("../llm.types");
9
+ const InternalStateUpdater_1 = __importDefault(require("./InternalStateUpdater"));
9
10
  const TurnRequest_1 = __importDefault(require("./TurnRequest"));
10
11
  class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
11
12
  constructor(options) {
@@ -81,15 +82,22 @@ class SprucebotLlmBotImpl extends mercury_event_emitter_1.AbstractEventEmitter {
81
82
  }
82
83
  this.messages.push(m);
83
84
  }
84
- async updateState(newState) {
85
- (0, schema_1.validateSchemaValues)(this.stateSchema, newState);
86
- this.state = { ...this.state, ...newState };
87
- await this.emit('did-update-state');
85
+ async updateState(updates) {
86
+ await InternalStateUpdater_1.default.updateState(this, updates);
88
87
  }
89
88
  setSkill(skill) {
90
89
  this.skill = skill;
91
90
  this.isDone = false;
92
91
  }
92
+ getStateSchema() {
93
+ return this.stateSchema;
94
+ }
95
+ getState() {
96
+ return this.state;
97
+ }
98
+ silentlySetState(state) {
99
+ this.state = state;
100
+ }
93
101
  }
94
102
  SprucebotLlmBotImpl.messageMemoryLimit = 10;
95
103
  exports.default = SprucebotLlmBotImpl;
@@ -10,4 +10,6 @@ export default class SprucebotLlmSkillImpl<StateSchema extends Schema = Schema,
10
10
  getState(): Partial<State> | undefined;
11
11
  setModel(model: string): void;
12
12
  serialize(): SerializedSkill<StateSchema, State>;
13
+ silentlySetState(state: Partial<State>): void;
14
+ getStateSchema(): StateSchema | undefined;
13
15
  }
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const mercury_event_emitter_1 = require("@sprucelabs/mercury-event-emitter");
4
7
  const schema_1 = require("@sprucelabs/schema");
5
8
  const llm_types_1 = require("../llm.types");
9
+ const InternalStateUpdater_1 = __importDefault(require("./InternalStateUpdater"));
6
10
  class SprucebotLlmSkillImpl extends mercury_event_emitter_1.AbstractEventEmitter {
7
11
  constructor(options) {
8
12
  super(llm_types_1.llmEventContract);
@@ -18,9 +22,7 @@ class SprucebotLlmSkillImpl extends mercury_event_emitter_1.AbstractEventEmitter
18
22
  : undefined;
19
23
  }
20
24
  async updateState(updates) {
21
- (0, schema_1.validateSchemaValues)(this.stateSchema, updates);
22
- this.state = { ...this.state, ...updates };
23
- await this.emit('did-update-state');
25
+ await InternalStateUpdater_1.default.updateState(this, updates);
24
26
  }
25
27
  getState() {
26
28
  return this.state;
@@ -35,5 +37,11 @@ class SprucebotLlmSkillImpl extends mercury_event_emitter_1.AbstractEventEmitter
35
37
  state: this.state,
36
38
  };
37
39
  }
40
+ silentlySetState(state) {
41
+ this.state = state;
42
+ }
43
+ getStateSchema() {
44
+ return this.stateSchema;
45
+ }
38
46
  }
39
47
  exports.default = SprucebotLlmSkillImpl;
@@ -0,0 +1,5 @@
1
+ import SprucebotLlmBotImpl from './SprucebotLlmBotImpl';
2
+ import SprucebotLlmSkillImpl from './SprucebotLlmSkillImpl';
3
+ export default class InternalStateUpdater {
4
+ static updateState(skill: SprucebotLlmSkillImpl | SprucebotLlmBotImpl, updates: Record<string, any>): Promise<void>;
5
+ }
@@ -0,0 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { normalizeSchemaValues, validateSchemaValues } from '@sprucelabs/schema';
11
+ export default class InternalStateUpdater {
12
+ static updateState(skill, updates) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ validateSchemaValues(skill.getStateSchema(), updates);
15
+ const state = Object.assign(Object.assign({}, skill.getState()), updates);
16
+ const normalized = normalizeSchemaValues(skill.getStateSchema(), state, {
17
+ shouldIncludeNullAndUndefinedFields: false,
18
+ });
19
+ skill.silentlySetState(normalized);
20
+ yield skill.emit('did-update-state');
21
+ });
22
+ }
23
+ }
@@ -19,6 +19,9 @@ export default class SprucebotLlmBotImpl<StateSchema extends Schema = Schema, St
19
19
  sendMessage(message: SendMessage, cb?: MessageResponseCallback): Promise<string>;
20
20
  private optionallyUpdateState;
21
21
  private trackMessage;
22
- updateState(newState: Partial<State>): Promise<void>;
22
+ updateState(updates: Partial<State>): Promise<void>;
23
23
  setSkill(skill: SprucebotLLmSkill<any>): void;
24
+ getStateSchema(): StateSchema | undefined;
25
+ getState(): Partial<State> | undefined;
26
+ silentlySetState(state: Partial<State>): void;
24
27
  }
@@ -8,8 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
11
- import { assertOptions, defaultSchemaValues, validateSchemaValues, } from '@sprucelabs/schema';
11
+ import { assertOptions, defaultSchemaValues, } from '@sprucelabs/schema';
12
12
  import { llmEventContract, } from '../llm.types.js';
13
+ import InternalStateUpdater from './InternalStateUpdater.js';
13
14
  import TurnRequest from './TurnRequest.js';
14
15
  class SprucebotLlmBotImpl extends AbstractEventEmitter {
15
16
  constructor(options) {
@@ -89,17 +90,24 @@ class SprucebotLlmBotImpl extends AbstractEventEmitter {
89
90
  }
90
91
  this.messages.push(m);
91
92
  }
92
- updateState(newState) {
93
+ updateState(updates) {
93
94
  return __awaiter(this, void 0, void 0, function* () {
94
- validateSchemaValues(this.stateSchema, newState);
95
- this.state = Object.assign(Object.assign({}, this.state), newState);
96
- yield this.emit('did-update-state');
95
+ yield InternalStateUpdater.updateState(this, updates);
97
96
  });
98
97
  }
99
98
  setSkill(skill) {
100
99
  this.skill = skill;
101
100
  this.isDone = false;
102
101
  }
102
+ getStateSchema() {
103
+ return this.stateSchema;
104
+ }
105
+ getState() {
106
+ return this.state;
107
+ }
108
+ silentlySetState(state) {
109
+ this.state = state;
110
+ }
103
111
  }
104
112
  SprucebotLlmBotImpl.messageMemoryLimit = 10;
105
113
  export default SprucebotLlmBotImpl;
@@ -10,4 +10,6 @@ export default class SprucebotLlmSkillImpl<StateSchema extends Schema = Schema,
10
10
  getState(): Partial<State> | undefined;
11
11
  setModel(model: string): void;
12
12
  serialize(): SerializedSkill<StateSchema, State>;
13
+ silentlySetState(state: Partial<State>): void;
14
+ getStateSchema(): StateSchema | undefined;
13
15
  }
@@ -19,8 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
22
- import { defaultSchemaValues, validateSchemaValues, } from '@sprucelabs/schema';
22
+ import { defaultSchemaValues } from '@sprucelabs/schema';
23
23
  import { llmEventContract, } from '../llm.types.js';
24
+ import InternalStateUpdater from './InternalStateUpdater.js';
24
25
  export default class SprucebotLlmSkillImpl extends AbstractEventEmitter {
25
26
  constructor(options) {
26
27
  super(llmEventContract);
@@ -34,9 +35,7 @@ export default class SprucebotLlmSkillImpl extends AbstractEventEmitter {
34
35
  }
35
36
  updateState(updates) {
36
37
  return __awaiter(this, void 0, void 0, function* () {
37
- validateSchemaValues(this.stateSchema, updates);
38
- this.state = Object.assign(Object.assign({}, this.state), updates);
39
- yield this.emit('did-update-state');
38
+ yield InternalStateUpdater.updateState(this, updates);
40
39
  });
41
40
  }
42
41
  getState() {
@@ -48,4 +47,10 @@ export default class SprucebotLlmSkillImpl extends AbstractEventEmitter {
48
47
  serialize() {
49
48
  return Object.assign(Object.assign({}, this.options), { stateSchema: this.stateSchema, state: this.state });
50
49
  }
50
+ silentlySetState(state) {
51
+ this.state = state;
52
+ }
53
+ getStateSchema() {
54
+ return this.stateSchema;
55
+ }
51
56
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "eta"
9
9
  ]
10
10
  },
11
- "version": "13.1.3",
11
+ "version": "13.1.4",
12
12
  "files": [
13
13
  "build"
14
14
  ],