@primusclaw/personal-agent-runtime 0.3.0 → 0.5.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.
package/dist/index.js CHANGED
@@ -2031,7 +2031,8 @@ function groupContextSettings(read2) {
2031
2031
  return {
2032
2032
  messages,
2033
2033
  maxAgeSeconds: read2.positiveInt("TEAMS_GROUP_CONTEXT_HOURS", DEFAULT_GROUP_CONTEXT.maxAgeSeconds / 3600) * 3600,
2034
- messageChars: read2.positiveInt("TEAMS_GROUP_CONTEXT_CHARS", DEFAULT_GROUP_CONTEXT.messageChars)
2034
+ messageChars: read2.positiveInt("TEAMS_GROUP_CONTEXT_CHARS", DEFAULT_GROUP_CONTEXT.messageChars),
2035
+ granted: read2.raw("TEAMS_GROUP_CONTEXT_GRANTED") === "1"
2035
2036
  };
2036
2037
  }
2037
2038
  function secret(read2, store, name) {
@@ -2516,7 +2517,8 @@ import {
2516
2517
 
2517
2518
  // packages/runtime/src/sqlite/approval-repository.ts
2518
2519
  import {
2519
- APPROVAL_TTL_SECONDS
2520
+ APPROVAL_TTL_SECONDS,
2521
+ QUESTION_TOOL
2520
2522
  } from "@primusclaw/personal-agent";
2521
2523
 
2522
2524
  // packages/runtime/src/sqlite/py-json.ts
@@ -2567,6 +2569,15 @@ function storedObject(text3) {
2567
2569
  }
2568
2570
 
2569
2571
  // packages/runtime/src/sqlite/approval-repository.ts
2572
+ function storedQuestions(text3) {
2573
+ if (!text3) return [];
2574
+ try {
2575
+ const parsed = JSON.parse(text3);
2576
+ return Array.isArray(parsed) ? parsed.filter((q) => typeof q === "object" && q !== null && !Array.isArray(q)) : [];
2577
+ } catch {
2578
+ return [];
2579
+ }
2580
+ }
2570
2581
  var key = (sessionId, toolUseId) => JSON.stringify([sessionId, toolUseId]);
2571
2582
  var SqliteApprovalRepository = class {
2572
2583
  constructor(ctx) {
@@ -2578,22 +2589,24 @@ var SqliteApprovalRepository = class {
2578
2589
  const now = this.ctx.now();
2579
2590
  this.ctx.db.run("DELETE FROM approvals WHERE expires_at < ?", now - APPROVAL_TTL_SECONDS);
2580
2591
  const recorded = this.ctx.db.run(
2581
- "INSERT OR IGNORE INTO approvals (session_id, tool_use_id, aad_id, tool, expires_at, created_at, card_sent, card_json) VALUES (?, ?, ?, ?, ?, ?, 0, ?)",
2592
+ "INSERT OR IGNORE INTO approvals (session_id, tool_use_id, aad_id, tool, expires_at, created_at, card_sent, card_json, questions_json) VALUES (?, ?, ?, ?, ?, ?, 0, ?, ?)",
2582
2593
  approval.sessionId,
2583
2594
  approval.toolUseId,
2584
2595
  approval.userId,
2585
2596
  approval.tool,
2586
2597
  approval.expiresAt,
2587
2598
  now,
2588
- approval.envelope === void 0 || approval.envelope === null ? null : pyJsonDumps(approval.envelope)
2599
+ approval.envelope === void 0 || approval.envelope === null ? null : pyJsonDumps(approval.envelope),
2600
+ approval.questions?.length ? JSON.stringify(approval.questions) : ""
2589
2601
  ) === 1;
2590
2602
  if (recorded) this.#sending.add(key(approval.sessionId, approval.toolUseId));
2591
2603
  return recorded;
2592
2604
  }
2593
- approvalSent(sessionId, toolUseId) {
2605
+ approvalSent(sessionId, toolUseId, cardId = "") {
2594
2606
  this.#sending.delete(key(sessionId, toolUseId));
2595
2607
  this.ctx.db.run(
2596
- "UPDATE approvals SET card_sent = 1, card_json = NULL WHERE session_id = ? AND tool_use_id = ?",
2608
+ "UPDATE approvals SET card_sent = 1, card_json = NULL, card_id = ? WHERE session_id = ? AND tool_use_id = ?",
2609
+ cardId,
2597
2610
  sessionId,
2598
2611
  toolUseId
2599
2612
  );
@@ -2653,6 +2666,26 @@ var SqliteApprovalRepository = class {
2653
2666
  state: col.str(row, "state")
2654
2667
  };
2655
2668
  }
2669
+ pendingQuestion(sessionId, userId) {
2670
+ const row = this.ctx.db.get(
2671
+ "SELECT tool_use_id, expires_at, questions_json, card_id FROM approvals WHERE session_id = ? AND aad_id = ? AND tool = ? AND state = 'pending' AND card_sent = 1 AND expires_at > ? AND questions_json != '' ORDER BY created_at DESC LIMIT 1",
2672
+ sessionId,
2673
+ userId,
2674
+ QUESTION_TOOL,
2675
+ this.ctx.now()
2676
+ );
2677
+ if (!row) return null;
2678
+ const questions = storedQuestions(col.str(row, "questions_json"));
2679
+ if (questions.length === 0) return null;
2680
+ return {
2681
+ sessionId,
2682
+ toolUseId: col.str(row, "tool_use_id"),
2683
+ userId,
2684
+ expiresAt: col.num(row, "expires_at"),
2685
+ questions,
2686
+ cardId: col.str(row, "card_id")
2687
+ };
2688
+ }
2656
2689
  closeApproval(sessionId, toolUseId, state, options = {}) {
2657
2690
  const onlyIfPending = options.onlyIfPending ?? true;
2658
2691
  return this.ctx.db.run(
@@ -3682,7 +3715,11 @@ var ADDED_COLUMNS = [
3682
3715
  "approvals",
3683
3716
  [
3684
3717
  ["card_sent", "INTEGER NOT NULL DEFAULT 1"],
3685
- ["card_json", "TEXT"]
3718
+ ["card_json", "TEXT"],
3719
+ ["card_id", "TEXT NOT NULL DEFAULT ''"],
3720
+ // '' = the channel never said the card's id
3721
+ ["questions_json", "TEXT NOT NULL DEFAULT ''"]
3722
+ // '' = not a turn's question card
3686
3723
  ]
3687
3724
  ],
3688
3725
  ["notify_subs", [["types_version", "INTEGER NOT NULL DEFAULT 0"]]],
@@ -1,18 +1,19 @@
1
1
  /** ApprovalRepository on SQLite (table `approvals`). Which cards are being sent right now is kept in this process only;
2
2
  * what outlives a crash is the `card_sent` column: a card recorded and not marked sent is sent by the next process. */
3
- import { type Approval, type ApprovalRepository, type ApprovalState, type NewApproval, type UnsentCard } from "@primusclaw/personal-agent";
3
+ import { type Approval, type ApprovalRepository, type ApprovalState, type NewApproval, type PendingQuestion, type UnsentCard } from "@primusclaw/personal-agent";
4
4
  import type { StoreContext } from "./context.js";
5
5
  export declare class SqliteApprovalRepository implements ApprovalRepository {
6
6
  #private;
7
7
  private readonly ctx;
8
8
  constructor(ctx: StoreContext);
9
9
  saveApproval(approval: NewApproval): boolean;
10
- approvalSent(sessionId: string, toolUseId: string): void;
10
+ approvalSent(sessionId: string, toolUseId: string, cardId?: string): void;
11
11
  approvalInFlight(sessionId: string, toolUseId: string): boolean;
12
12
  forgetApproval(sessionId: string, toolUseId: string): void;
13
13
  claimUnsentApprovals(): UnsentCard[];
14
14
  approvalSendFailed(sessionId: string, toolUseId: string): void;
15
15
  getApproval(sessionId: string, toolUseId: string): Approval | null;
16
+ pendingQuestion(sessionId: string, userId: string): PendingQuestion | null;
16
17
  closeApproval(sessionId: string, toolUseId: string, state: ApprovalState, options?: {
17
18
  readonly onlyIfPending?: boolean;
18
19
  }): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-runtime",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Node adapters for the personal agent's ports: clock, randomness, logging (and, as the port lands, storage, Claw, metrics, HTTP).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@primusclaw/personal-agent": "0.3.0",
32
+ "@primusclaw/personal-agent": "0.5.0",
33
33
  "fastify": "^5.12.8",
34
34
  "zod": "^4.6.7"
35
35
  }