@economic/agents 1.2.0 → 1.2.1

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/index.d.mts CHANGED
@@ -176,17 +176,6 @@ declare abstract class ChatAgent<Env extends Cloudflare.Env = Cloudflare.Env> ex
176
176
  protected buildLLMParams<TBody = Record<string, unknown>>(config: BuildLLMParamsConfig & {
177
177
  options?: OnChatMessageOptions;
178
178
  }): Promise<LLMParams>;
179
- /**
180
- * Extracts skill state from activate_skill results, persists to DO SQLite,
181
- * then strips all skill meta-tool messages before delegating to super.
182
- *
183
- * 1. Scans activate_skill tool results for SKILL_STATE_SENTINEL. When found,
184
- * the embedded JSON array of loaded skill names is written to DO SQLite.
185
- *
186
- * 2. Strips all activate_skill and list_capabilities messages from history.
187
- *
188
- * 3. Delegates to super.persistMessages for message storage and WS broadcast.
189
- */
190
179
  persistMessages(messages: UIMessage[], excludeBroadcastIds?: string[], options?: {
191
180
  _deleteStaleRows?: boolean;
192
181
  }): Promise<void>;
package/dist/index.mjs CHANGED
@@ -162,9 +162,23 @@ function getStoredSkills(sql) {
162
162
  * Persists the current list of loaded skill names to DO SQLite.
163
163
  * Upserts the single `skill_state` row (id = 1).
164
164
  */
165
- function saveStoredSkills(sql, skills) {
165
+ function saveSkillStateFromMessages(sql, messages) {
166
+ let latestSkillState;
167
+ for (const msg of messages) {
168
+ if (msg.role !== "assistant" || !msg.parts) continue;
169
+ for (const part of msg.parts) {
170
+ if (!("toolCallId" in part)) continue;
171
+ if (part.type !== `tool-activate_skill` || typeof part.output !== "string") continue;
172
+ const sentinelIndex = part.output.indexOf(SKILL_STATE_SENTINEL);
173
+ if (sentinelIndex !== -1) try {
174
+ const stateJson = part.output.slice(sentinelIndex + 18);
175
+ latestSkillState = JSON.parse(stateJson);
176
+ } catch {}
177
+ }
178
+ }
179
+ if (latestSkillState == void 0) return;
166
180
  ensureSkillTable(sql);
167
- sql`INSERT OR REPLACE INTO skill_state(id, active_skills) VALUES(1, ${JSON.stringify(skills)})`;
181
+ sql`INSERT OR REPLACE INTO skill_state(id, active_skills) VALUES(1, ${JSON.stringify(latestSkillState)})`;
168
182
  }
169
183
  //#endregion
170
184
  //#region src/server/llm.ts
@@ -732,37 +746,11 @@ var ChatAgent = class extends AIChatAgent {
732
746
  onFinish
733
747
  });
734
748
  }
735
- /**
736
- * Extracts skill state from activate_skill results, persists to DO SQLite,
737
- * then strips all skill meta-tool messages before delegating to super.
738
- *
739
- * 1. Scans activate_skill tool results for SKILL_STATE_SENTINEL. When found,
740
- * the embedded JSON array of loaded skill names is written to DO SQLite.
741
- *
742
- * 2. Strips all activate_skill and list_capabilities messages from history.
743
- *
744
- * 3. Delegates to super.persistMessages for message storage and WS broadcast.
745
- */
746
749
  async persistMessages(messages, excludeBroadcastIds = [], options) {
747
- let latestSkillState;
748
- for (const msg of messages) {
749
- if (msg.role !== "assistant" || !msg.parts) continue;
750
- for (const part of msg.parts) {
751
- if (!("toolCallId" in part)) continue;
752
- const { type, output } = part;
753
- if (type !== `tool-activate_skill` || typeof output !== "string") continue;
754
- const sentinelIdx = output.indexOf(SKILL_STATE_SENTINEL);
755
- if (sentinelIdx !== -1) try {
756
- const stateJson = output.slice(sentinelIdx + 18);
757
- latestSkillState = JSON.parse(stateJson);
758
- } catch {}
759
- }
760
- }
761
- if (latestSkillState !== void 0) saveStoredSkills(this.sql.bind(this), latestSkillState);
762
750
  const filtered = filterEphemeralMessages(messages);
763
- const result = await super.persistMessages(filtered, excludeBroadcastIds, options);
751
+ await super.persistMessages(filtered, excludeBroadcastIds, options);
752
+ saveSkillStateFromMessages(this.sql.bind(this), messages);
764
753
  this.scheduleConversationForDeletion();
765
- return result;
766
754
  }
767
755
  @callable({ description: "Returns all conversations for the current user" }) async getConversations() {
768
756
  return getConversations(this.env.AGENT_DB, this.getUserId());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@cloudflare/ai-chat": ">=0.1.0 <1.0.0",
46
- "agents": "^0.10.1",
46
+ "agents": "^0.10.2",
47
47
  "ai": "^6.0.0",
48
48
  "hono": "^4.0.0",
49
49
  "jose": "^6.0.0"