@deepagents/text2sql 0.12.0 → 0.12.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.
@@ -437,7 +437,7 @@ function message(content) {
437
437
  } : content;
438
438
  return {
439
439
  id: message2.id,
440
- name: "message",
440
+ name: message2.role,
441
441
  data: "content",
442
442
  type: "message",
443
443
  persist: true,
@@ -459,6 +459,22 @@ function assistantText(content, options) {
459
459
  parts: [{ type: "text", text: content }]
460
460
  });
461
461
  }
462
+ var LAZY_ID = Symbol("lazy-id");
463
+ function isLazyFragment(fragment2) {
464
+ return LAZY_ID in fragment2;
465
+ }
466
+ function lastAssistantMessage(content) {
467
+ return {
468
+ name: "assistant",
469
+ type: "message",
470
+ persist: true,
471
+ data: "content",
472
+ [LAZY_ID]: {
473
+ type: "last-assistant",
474
+ content
475
+ }
476
+ };
477
+ }
462
478
  var ContextRenderer = class {
463
479
  options;
464
480
  constructor(options = {}) {
@@ -955,6 +971,12 @@ var ContextEngine = class {
955
971
  if (this.#pendingMessages.length === 0) {
956
972
  return;
957
973
  }
974
+ for (let i = 0; i < this.#pendingMessages.length; i++) {
975
+ const fragment2 = this.#pendingMessages[i];
976
+ if (isLazyFragment(fragment2)) {
977
+ this.#pendingMessages[i] = await this.#resolveLazyFragment(fragment2);
978
+ }
979
+ }
958
980
  let parentId = this.#branch.headMessageId;
959
981
  const now = Date.now();
960
982
  for (const fragment2 of this.#pendingMessages) {
@@ -974,6 +996,39 @@ var ContextEngine = class {
974
996
  this.#branch.headMessageId = parentId;
975
997
  this.#pendingMessages = [];
976
998
  }
999
+ /**
1000
+ * Resolve a lazy fragment by finding the appropriate ID.
1001
+ */
1002
+ async #resolveLazyFragment(fragment2) {
1003
+ const lazy = fragment2[LAZY_ID];
1004
+ if (lazy.type === "last-assistant") {
1005
+ const lastId = await this.#getLastAssistantId();
1006
+ return assistantText(lazy.content, { id: lastId ?? crypto.randomUUID() });
1007
+ }
1008
+ throw new Error(`Unknown lazy fragment type: ${lazy.type}`);
1009
+ }
1010
+ /**
1011
+ * Find the most recent assistant message ID (pending or persisted).
1012
+ */
1013
+ async #getLastAssistantId() {
1014
+ for (let i = this.#pendingMessages.length - 1; i >= 0; i--) {
1015
+ const msg = this.#pendingMessages[i];
1016
+ if (msg.name === "assistant" && !isLazyFragment(msg)) {
1017
+ return msg.id;
1018
+ }
1019
+ }
1020
+ if (this.#branch?.headMessageId) {
1021
+ const chain = await this.#store.getMessageChain(
1022
+ this.#branch.headMessageId
1023
+ );
1024
+ for (let i = chain.length - 1; i >= 0; i--) {
1025
+ if (chain[i].name === "assistant") {
1026
+ return chain[i].id;
1027
+ }
1028
+ }
1029
+ }
1030
+ return void 0;
1031
+ }
977
1032
  /**
978
1033
  * Estimate token count and cost for the full context.
979
1034
  *
@@ -1253,6 +1308,35 @@ var ContextEngine = class {
1253
1308
  consolidate() {
1254
1309
  return void 0;
1255
1310
  }
1311
+ /**
1312
+ * Extract skill path mappings from available_skills fragments.
1313
+ * Returns array of { host, sandbox } for mounting in sandbox filesystem.
1314
+ *
1315
+ * Reads the original `paths` configuration stored in fragment metadata
1316
+ * by the skills() fragment helper.
1317
+ *
1318
+ * @example
1319
+ * ```ts
1320
+ * const context = new ContextEngine({ store, chatId, userId })
1321
+ * .set(skills({ paths: [{ host: './skills', sandbox: '/skills' }] }));
1322
+ *
1323
+ * const mounts = context.getSkillMounts();
1324
+ * // [{ host: './skills', sandbox: '/skills' }]
1325
+ * ```
1326
+ */
1327
+ getSkillMounts() {
1328
+ const mounts = [];
1329
+ for (const fragment2 of this.#fragments) {
1330
+ if (fragment2.name === "available_skills" && fragment2.metadata && Array.isArray(fragment2.metadata.paths)) {
1331
+ for (const mapping of fragment2.metadata.paths) {
1332
+ if (typeof mapping === "object" && mapping !== null && typeof mapping.host === "string" && typeof mapping.sandbox === "string") {
1333
+ mounts.push({ host: mapping.host, sandbox: mapping.sandbox });
1334
+ }
1335
+ }
1336
+ }
1337
+ }
1338
+ return mounts;
1339
+ }
1256
1340
  /**
1257
1341
  * Inspect the full context state for debugging.
1258
1342
  * Returns a JSON-serializable object with context information.
@@ -1571,18 +1655,19 @@ var SqliteContextStore = class extends ContextStore {
1571
1655
  // Message Operations (Graph Nodes)
1572
1656
  // ==========================================================================
1573
1657
  async addMessage(message2) {
1658
+ const existingParent = message2.parentId === message2.id ? this.#db.prepare("SELECT parentId FROM messages WHERE id = ?").get(message2.id) : void 0;
1659
+ const parentId = message2.parentId === message2.id ? existingParent?.parentId ?? null : message2.parentId;
1574
1660
  this.#db.prepare(
1575
1661
  `INSERT INTO messages (id, chatId, parentId, name, type, data, createdAt)
1576
1662
  VALUES (?, ?, ?, ?, ?, ?, ?)
1577
1663
  ON CONFLICT(id) DO UPDATE SET
1578
- parentId = excluded.parentId,
1579
1664
  name = excluded.name,
1580
1665
  type = excluded.type,
1581
1666
  data = excluded.data`
1582
1667
  ).run(
1583
1668
  message2.id,
1584
1669
  message2.chatId,
1585
- message2.parentId,
1670
+ parentId,
1586
1671
  message2.name,
1587
1672
  message2.type ?? null,
1588
1673
  JSON.stringify(message2.data),
@@ -2050,13 +2135,9 @@ var Agent = class _Agent {
2050
2135
  writer.write({ type: "finish" });
2051
2136
  return;
2052
2137
  }
2053
- writer.write({
2054
- type: "text-delta",
2055
- id: generateId2(),
2056
- delta: ` ${failureFeedback}`
2057
- });
2138
+ writeText(writer, failureFeedback);
2058
2139
  const selfCorrectionText = accumulatedText + " " + failureFeedback;
2059
- context.set(assistantText(selfCorrectionText));
2140
+ context.set(lastAssistantMessage(selfCorrectionText));
2060
2141
  await context.save();
2061
2142
  currentResult = await this.#createRawStream(
2062
2143
  contextVariables,
@@ -2109,6 +2190,22 @@ var repairToolCall = async ({
2109
2190
  });
2110
2191
  return { ...toolCall, input: JSON.stringify(output) };
2111
2192
  };
2193
+ function writeText(writer, text) {
2194
+ const feedbackPartId = generateId2();
2195
+ writer.write({
2196
+ id: feedbackPartId,
2197
+ type: "text-start"
2198
+ });
2199
+ writer.write({
2200
+ id: feedbackPartId,
2201
+ type: "text-delta",
2202
+ delta: ` ${text}`
2203
+ });
2204
+ writer.write({
2205
+ id: feedbackPartId,
2206
+ type: "text-end"
2207
+ });
2208
+ }
2112
2209
 
2113
2210
  // packages/text2sql/src/lib/adapters/groundings/report.grounding.ts
2114
2211
  var ReportGrounding = class extends AbstractGrounding {