@primusclaw/personal-agent-runtime 0.5.0 → 0.6.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
@@ -2876,6 +2876,51 @@ var SqliteAssistantButtonRepository = class {
2876
2876
  moveConfirmCard(cardId, state, options) {
2877
2877
  return moveCard(this.ctx.db, "assistant_confirm_cards", cardId, state, options);
2878
2878
  }
2879
+ addChoiceCard(userId, choice) {
2880
+ const now = this.ctx.now();
2881
+ this.ctx.db.run("DELETE FROM assistant_choice_cards WHERE created_at < ?", now - ASSISTANT_MESSAGE_KEEP_SECONDS);
2882
+ const cardId = tokenUrlsafe(this.ctx.random, 12);
2883
+ this.ctx.db.run(
2884
+ "INSERT INTO assistant_choice_cards (card_id, aad_id, text, options_json, multiple, lang, state, created_at) VALUES (?, ?, ?, ?, ?, ?, 'open', ?)",
2885
+ cardId,
2886
+ userId,
2887
+ choice.text,
2888
+ pyJsonDumps(choice.options),
2889
+ flag(choice.multiple),
2890
+ choice.lang,
2891
+ now
2892
+ );
2893
+ return cardId;
2894
+ }
2895
+ getChoiceCard(cardId) {
2896
+ const row = this.ctx.db.get(
2897
+ "SELECT card_id, aad_id, text, options_json, multiple, chosen_json, lang, state, created_at FROM assistant_choice_cards WHERE card_id = ? AND created_at >= ?",
2898
+ cardId,
2899
+ this.ctx.now() - ASSISTANT_MESSAGE_KEEP_SECONDS
2900
+ );
2901
+ if (!row) return null;
2902
+ return {
2903
+ cardId: col.str(row, "card_id"),
2904
+ userId: col.str(row, "aad_id"),
2905
+ text: col.str(row, "text"),
2906
+ options: jsonStrings(col.str(row, "options_json") || "[]"),
2907
+ multiple: col.bool(row, "multiple"),
2908
+ chosen: jsonStrings(col.str(row, "chosen_json") || "[]"),
2909
+ lang: col.str(row, "lang"),
2910
+ state: col.str(row, "state"),
2911
+ createdAt: col.num(row, "created_at")
2912
+ };
2913
+ }
2914
+ claimChoiceCard(cardId, chosen) {
2915
+ return this.ctx.db.run(
2916
+ "UPDATE assistant_choice_cards SET state = 'busy', chosen_json = ? WHERE card_id = ? AND state = 'open'",
2917
+ pyJsonDumps(chosen),
2918
+ cardId
2919
+ ) === 1;
2920
+ }
2921
+ moveChoiceCard(cardId, state, options) {
2922
+ return moveCard(this.ctx.db, "assistant_choice_cards", cardId, state, options);
2923
+ }
2879
2924
  };
2880
2925
  var SqliteAssistantMessageRepository = class {
2881
2926
  constructor(ctx) {
@@ -3426,6 +3471,7 @@ var PERSON_TABLES = [
3426
3471
  "auto_replies",
3427
3472
  "assistant_action_cards",
3428
3473
  "assistant_confirm_cards",
3474
+ "assistant_choice_cards",
3429
3475
  "observed_groups",
3430
3476
  "observe_cards",
3431
3477
  "pending_requests"
@@ -109,6 +109,9 @@ CREATE TABLE IF NOT EXISTS assistant_action_cards (
109
109
  CREATE TABLE IF NOT EXISTS assistant_confirm_cards (
110
110
  card_id TEXT PRIMARY KEY, aad_id TEXT NOT NULL, confirmation_id TEXT NOT NULL, kind TEXT NOT NULL, label TEXT NOT NULL DEFAULT '',
111
111
  state TEXT NOT NULL DEFAULT 'open', created_at REAL NOT NULL);
112
+ CREATE TABLE IF NOT EXISTS assistant_choice_cards (
113
+ card_id TEXT PRIMARY KEY, aad_id TEXT NOT NULL, text TEXT NOT NULL DEFAULT '', options_json TEXT NOT NULL, multiple INTEGER NOT NULL,
114
+ chosen_json TEXT NOT NULL DEFAULT '[]', lang TEXT NOT NULL DEFAULT '', state TEXT NOT NULL DEFAULT 'open', created_at REAL NOT NULL);
112
115
  CREATE TABLE IF NOT EXISTS asker_follows (
113
116
  item_id TEXT PRIMARY KEY, batch_id TEXT NOT NULL, review_json TEXT NOT NULL, reference_json TEXT NOT NULL,
114
117
  said TEXT NOT NULL DEFAULT '', reviewer_told INTEGER NOT NULL DEFAULT 0, deadline REAL NOT NULL, created_at REAL NOT NULL);
@@ -1,6 +1,6 @@
1
1
  /** The assistant's cards and messages on SQLite (tables `assistant_cards`, `auto_replies`, `assistant_action_cards`,
2
- * `assistant_confirm_cards`, `assistant_messages`). */
3
- import { type ActionCard, type AssistantButtonRepository, type AssistantCard, type AssistantCardRepository, type AssistantMessage, type AssistantMessageRepository, type CardState, type ConfirmCard, type JsonObject, type MoveOptions, type PlacedCard } from "@primusclaw/personal-agent";
2
+ * `assistant_confirm_cards`, `assistant_choice_cards`, `assistant_messages`). */
3
+ import { type ActionCard, type AssistantButtonRepository, type AssistantCard, type AssistantCardRepository, type AssistantMessage, type AssistantMessageRepository, type CardState, type ChoiceCard, type ConfirmCard, type JsonObject, type MoveOptions, type PlacedCard } from "@primusclaw/personal-agent";
4
4
  import { type StoreContext } from "./context.js";
5
5
  export declare class SqliteAssistantCardRepository implements AssistantCardRepository {
6
6
  private readonly ctx;
@@ -32,6 +32,15 @@ export declare class SqliteAssistantButtonRepository implements AssistantButtonR
32
32
  addConfirmCard(userId: string, confirmationId: string, kind: string, label?: string): string;
33
33
  getConfirmCard(cardId: string): ConfirmCard | null;
34
34
  moveConfirmCard(cardId: string, state: CardState, options?: MoveOptions): boolean;
35
+ addChoiceCard(userId: string, choice: {
36
+ readonly text: string;
37
+ readonly options: readonly string[];
38
+ readonly multiple: boolean;
39
+ readonly lang: string;
40
+ }): string;
41
+ getChoiceCard(cardId: string): ChoiceCard | null;
42
+ claimChoiceCard(cardId: string, chosen: readonly string[]): boolean;
43
+ moveChoiceCard(cardId: string, state: CardState, options?: MoveOptions): boolean;
35
44
  }
36
45
  export declare class SqliteAssistantMessageRepository implements AssistantMessageRepository {
37
46
  private readonly ctx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-runtime",
3
- "version": "0.5.0",
3
+ "version": "0.6.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.5.0",
32
+ "@primusclaw/personal-agent": "0.6.0",
33
33
  "fastify": "^5.12.8",
34
34
  "zod": "^4.6.7"
35
35
  }