@primusclaw/personal-agent-runtime 0.5.0 → 0.7.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"
@@ -3985,6 +4031,40 @@ var SqliteGroupContextRepository = class {
3985
4031
  }
3986
4032
  };
3987
4033
 
4034
+ // packages/runtime/src/sqlite/group-language-repository.ts
4035
+ var LANGS = /* @__PURE__ */ new Set(["zh", "en", "auto"]);
4036
+ var SqliteGroupLanguageRepository = class {
4037
+ constructor(ctx) {
4038
+ this.ctx = ctx;
4039
+ }
4040
+ ctx;
4041
+ groupLanguage(conversationId) {
4042
+ const row = this.ctx.db.get("SELECT lang FROM group_language WHERE conversation_id = ?", conversationId);
4043
+ if (row === void 0) return null;
4044
+ const lang = row["lang"];
4045
+ return typeof lang === "string" && LANGS.has(lang) ? lang : "";
4046
+ }
4047
+ setGroupLanguage(conversationId, lang) {
4048
+ this.ctx.db.run(
4049
+ "INSERT INTO group_language (conversation_id, lang, updated_at) VALUES (?, ?, ?) ON CONFLICT (conversation_id) DO UPDATE SET lang = excluded.lang, updated_at = excluded.updated_at",
4050
+ conversationId,
4051
+ lang,
4052
+ this.ctx.now()
4053
+ );
4054
+ }
4055
+ markGroupLanguageAsked(conversationId) {
4056
+ const changes = this.ctx.db.run(
4057
+ "INSERT INTO group_language (conversation_id, lang, updated_at) VALUES (?, '', ?) ON CONFLICT (conversation_id) DO NOTHING",
4058
+ conversationId,
4059
+ this.ctx.now()
4060
+ );
4061
+ return changes > 0;
4062
+ }
4063
+ unmarkGroupLanguageAsked(conversationId) {
4064
+ this.ctx.db.run("DELETE FROM group_language WHERE conversation_id = ? AND lang = ''", conversationId);
4065
+ }
4066
+ };
4067
+
3988
4068
  // packages/runtime/src/sqlite/people-repository.ts
3989
4069
  import {
3990
4070
  DEFAULT_QUIET,
@@ -4660,6 +4740,7 @@ var SqliteStore = class {
4660
4740
  approvals;
4661
4741
  observe;
4662
4742
  groupContext;
4743
+ groupLanguage;
4663
4744
  assistantCards;
4664
4745
  assistantButtons;
4665
4746
  assistantMessages;
@@ -4692,6 +4773,7 @@ var SqliteStore = class {
4692
4773
  this.approvals = new SqliteApprovalRepository(ctx);
4693
4774
  this.observe = new SqliteObserveRepository(ctx);
4694
4775
  this.groupContext = new SqliteGroupContextRepository(ctx);
4776
+ this.groupLanguage = new SqliteGroupLanguageRepository(ctx);
4695
4777
  this.assistantCards = new SqliteAssistantCardRepository(ctx);
4696
4778
  this.assistantButtons = new SqliteAssistantButtonRepository(ctx);
4697
4779
  this.assistantMessages = new SqliteAssistantMessageRepository(ctx);
@@ -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);
@@ -122,5 +125,7 @@ CREATE TABLE IF NOT EXISTS observe_cards (
122
125
  CREATE INDEX IF NOT EXISTS observe_cards_by_suggestion ON observe_cards (aad_id, run_id, seq);
123
126
  CREATE TABLE IF NOT EXISTS group_context_off (
124
127
  conversation_id TEXT PRIMARY KEY, updated_at REAL NOT NULL);
128
+ CREATE TABLE IF NOT EXISTS group_language (
129
+ conversation_id TEXT PRIMARY KEY, lang TEXT NOT NULL, updated_at REAL NOT NULL);
125
130
  CREATE TABLE IF NOT EXISTS bound_users (
126
131
  aad_id TEXT PRIMARY KEY, claw_user_id TEXT NOT NULL, token_hash TEXT NOT NULL, updated_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;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * GroupLanguageRepository on SQLite (table `group_language`: one row per group chat that was asked which language to use, or set
3
+ * one; `lang` "" while it was asked and nobody chose).
4
+ */
5
+ import type { GroupLanguage, GroupLanguageRepository } from "@primusclaw/personal-agent";
6
+ import type { StoreContext } from "./context.js";
7
+ export declare class SqliteGroupLanguageRepository implements GroupLanguageRepository {
8
+ private readonly ctx;
9
+ constructor(ctx: StoreContext);
10
+ groupLanguage(conversationId: string): GroupLanguage | "" | null;
11
+ setGroupLanguage(conversationId: string, lang: GroupLanguage): void;
12
+ markGroupLanguageAsked(conversationId: string): boolean;
13
+ unmarkGroupLanguageAsked(conversationId: string): void;
14
+ }
@@ -14,6 +14,7 @@ import { SqliteMemberDirectoryRepository } from "./member-repository.js";
14
14
  import { SqliteNotifySubscriptionRepository } from "./notify-repository.js";
15
15
  import { SqliteObserveRepository } from "./observe-repository.js";
16
16
  import { SqliteGroupContextRepository } from "./group-context-repository.js";
17
+ import { SqliteGroupLanguageRepository } from "./group-language-repository.js";
17
18
  import { SqliteOnboardingRepository } from "./onboarding-repository.js";
18
19
  import { SqliteConversationRefRepository, SqliteHeldEventRepository, SqlitePrefsRepository } from "./people-repository.js";
19
20
  import { type ReencryptCounts } from "./reencrypt.js";
@@ -47,6 +48,7 @@ export declare class SqliteStore implements StorePort {
47
48
  readonly approvals: SqliteApprovalRepository;
48
49
  readonly observe: SqliteObserveRepository;
49
50
  readonly groupContext: SqliteGroupContextRepository;
51
+ readonly groupLanguage: SqliteGroupLanguageRepository;
50
52
  readonly assistantCards: SqliteAssistantCardRepository;
51
53
  readonly assistantButtons: SqliteAssistantButtonRepository;
52
54
  readonly assistantMessages: SqliteAssistantMessageRepository;
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.7.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.7.0",
33
33
  "fastify": "^5.12.8",
34
34
  "zod": "^4.6.7"
35
35
  }