@primusclaw/personal-agent-runtime 0.12.0 → 0.14.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
@@ -351,10 +351,11 @@ var HttpAssistant = class {
351
351
  const query = new URLSearchParams({ lang, timezone }).toString();
352
352
  return dataOf(await this.http.json({ method: "GET", path: `/v1/assistant/brief?${query}`, key: key2 }), "the brief");
353
353
  }
354
- async decideConfirmation(token, confirmationId, decision) {
354
+ async decideConfirmation(token, confirmationId, decision, choice) {
355
355
  requireToken(token, "an answer to a held write");
356
356
  const path = `/v1/assistant/confirmations/${segment(confirmationId)}/decision`;
357
- const out = objectOf(await this.http.json({ method: "POST", path, key: token, body: { decision } }), "a decision");
357
+ const body = choice === void 0 ? { decision } : { decision, choice };
358
+ const out = objectOf(await this.http.json({ method: "POST", path, key: token, body }), "a decision");
358
359
  return dataOrSelf(out);
359
360
  }
360
361
  async startReviews(token, request) {
@@ -2999,6 +3000,14 @@ import {
2999
3000
  ASSISTANT_MESSAGE_KEEP_SECONDS,
3000
3001
  CONFIRM_CARD_KEEP_SECONDS
3001
3002
  } from "@primusclaw/personal-agent";
3003
+ function confirmOptions(text3) {
3004
+ return jsonList(text3 || "[]").flatMap((entry) => {
3005
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return [];
3006
+ const { id, label, detail } = entry;
3007
+ if (typeof id !== "string" || !id || typeof label !== "string") return [];
3008
+ return [{ id, label, detail: typeof detail === "string" ? detail : "" }];
3009
+ });
3010
+ }
3002
3011
  function moveCard(db, table, cardId, state, options = {}) {
3003
3012
  const from = options.onlyFrom;
3004
3013
  return from ? db.run(`UPDATE ${table} SET state = ? WHERE card_id = ? AND state = ?`, state, cardId, from) === 1 : db.run(`UPDATE ${table} SET state = ? WHERE card_id = ?`, state, cardId) === 1;
@@ -3137,24 +3146,25 @@ var SqliteAssistantButtonRepository = class {
3137
3146
  moveActionCard(cardId, state, options) {
3138
3147
  return moveCard(this.ctx.db, "assistant_action_cards", cardId, state, options);
3139
3148
  }
3140
- addConfirmCard(userId, confirmationId, kind, label = "") {
3149
+ addConfirmCard(userId, confirmationId, kind, label = "", options = []) {
3141
3150
  const now = this.ctx.now();
3142
3151
  this.ctx.db.run("DELETE FROM assistant_confirm_cards WHERE created_at < ?", now - CONFIRM_CARD_KEEP_SECONDS);
3143
3152
  const cardId = tokenUrlsafe(this.ctx.random, 12);
3144
3153
  this.ctx.db.run(
3145
- "INSERT INTO assistant_confirm_cards (card_id, aad_id, confirmation_id, kind, label, state, created_at) VALUES (?, ?, ?, ?, ?, 'open', ?)",
3154
+ "INSERT INTO assistant_confirm_cards (card_id, aad_id, confirmation_id, kind, label, state, created_at, options_json) VALUES (?, ?, ?, ?, ?, 'open', ?, ?)",
3146
3155
  cardId,
3147
3156
  userId,
3148
3157
  confirmationId,
3149
3158
  kind,
3150
3159
  label,
3151
- now
3160
+ now,
3161
+ JSON.stringify(options.map(({ id, label: shown, detail }) => ({ id, label: shown, detail })))
3152
3162
  );
3153
3163
  return cardId;
3154
3164
  }
3155
3165
  getConfirmCard(cardId) {
3156
3166
  const row = this.ctx.db.get(
3157
- "SELECT card_id, aad_id, confirmation_id, kind, label, state, created_at FROM assistant_confirm_cards WHERE card_id = ? AND created_at >= ?",
3167
+ "SELECT card_id, aad_id, confirmation_id, kind, label, options_json, state, created_at FROM assistant_confirm_cards WHERE card_id = ? AND created_at >= ?",
3158
3168
  cardId,
3159
3169
  this.ctx.now() - CONFIRM_CARD_KEEP_SECONDS
3160
3170
  );
@@ -3165,6 +3175,7 @@ var SqliteAssistantButtonRepository = class {
3165
3175
  confirmationId: col.str(row, "confirmation_id"),
3166
3176
  kind: col.str(row, "kind"),
3167
3177
  label: col.str(row, "label"),
3178
+ options: confirmOptions(col.str(row, "options_json")),
3168
3179
  state: col.str(row, "state"),
3169
3180
  createdAt: col.num(row, "created_at")
3170
3181
  };
@@ -4214,6 +4225,8 @@ var ADDED_COLUMNS = [
4214
4225
  ["render_json", "TEXT NOT NULL DEFAULT ''"]
4215
4226
  ]
4216
4227
  ],
4228
+ ["assistant_confirm_cards", [["options_json", "TEXT NOT NULL DEFAULT '[]'"]]],
4229
+ // a choice card's places; '[]' none
4217
4230
  [
4218
4231
  "pending_requests",
4219
4232
  [
@@ -4728,6 +4741,14 @@ var SqliteRemotePermissionRepository = class {
4728
4741
  p.lang ?? ""
4729
4742
  ) === 1;
4730
4743
  }
4744
+ keepRemotePermission(sessionId, actionId, expiresAt) {
4745
+ return this.ctx.db.run(
4746
+ "UPDATE remote_permissions SET state = 'pending', expires_at = ? WHERE session_id = ? AND action_id = ? AND state IN ('pending', 'expired')",
4747
+ expiresAt,
4748
+ sessionId,
4749
+ actionId
4750
+ ) === 1;
4751
+ }
4731
4752
  getRemotePermission(sessionId, actionId) {
4732
4753
  const row = this.ctx.db.get(
4733
4754
  `SELECT ${PERMISSION_COLUMNS} FROM remote_permissions WHERE session_id = ? AND action_id = ?`,
@@ -17,7 +17,7 @@ export declare class HttpAssistant implements ClawAssistantPort {
17
17
  }>;
18
18
  send(key: ClawCredential, sessionId: string, text: string, options?: AssistantMessageOptions): Promise<string | null>;
19
19
  brief(key: ClawCredential, lang: string, timezone: string): Promise<JsonObject>;
20
- decideConfirmation(token: ClawCredential, confirmationId: string, decision: string): Promise<JsonObject>;
20
+ decideConfirmation(token: ClawCredential, confirmationId: string, decision: string, choice?: string): Promise<JsonObject>;
21
21
  startReviews(token: ClawCredential, request: StartReviews): Promise<ReviewStart[]>;
22
22
  observeScope(key: ClawCredential, scope: string): Promise<JsonObject>;
23
23
  observe(key: ClawCredential, scope: string, content: string, messageId: string): Promise<JsonObject>;
@@ -1,6 +1,6 @@
1
1
  /** The assistant's cards and messages on SQLite (tables `assistant_cards`, `auto_replies`, `assistant_action_cards`,
2
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";
3
+ import { type ActionCard, type AssistantButtonRepository, type AssistantCard, type AssistantCardRepository, type AssistantMessage, type AssistantMessageRepository, type CardState, type ChoiceCard, type ConfirmCard, type ConfirmCardOption, 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;
@@ -29,7 +29,7 @@ export declare class SqliteAssistantButtonRepository implements AssistantButtonR
29
29
  addActionCard(userId: string, channelMessageId: string, name: string, args: string): string;
30
30
  getActionCard(cardId: string): ActionCard | null;
31
31
  moveActionCard(cardId: string, state: CardState, options?: MoveOptions): boolean;
32
- addConfirmCard(userId: string, confirmationId: string, kind: string, label?: string): string;
32
+ addConfirmCard(userId: string, confirmationId: string, kind: string, label?: string, options?: readonly ConfirmCardOption[]): string;
33
33
  getConfirmCard(cardId: string): ConfirmCard | null;
34
34
  moveConfirmCard(cardId: string, state: CardState, options?: MoveOptions): boolean;
35
35
  addChoiceCard(userId: string, choice: {
@@ -14,6 +14,7 @@ export declare class SqliteRemotePermissionRepository implements RemotePermissio
14
14
  private readonly ctx;
15
15
  constructor(ctx: StoreContext);
16
16
  saveRemotePermission(p: NewRemotePermission): boolean;
17
+ keepRemotePermission(sessionId: string, actionId: string, expiresAt: number): boolean;
17
18
  getRemotePermission(sessionId: string, actionId: string): RemotePermission | null;
18
19
  pendingRemotePermissions(userId: string, sessionId: string): RemotePermission[];
19
20
  waitingRemoteSessions(userId: string): Set<string>;
package/dist/worker.js CHANGED
@@ -533,6 +533,7 @@ function remoteAgents(base, inputs) {
533
533
  sessionNames: store.remoteSessionNames,
534
534
  permissions: store.remotePermissions,
535
535
  prefs: store.prefs,
536
+ groupLanguage: store.groupLanguage,
536
537
  references: store.references,
537
538
  conversationFor: conversationFor(base),
538
539
  credentialFor: async (person) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent-runtime",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Node adapters for the personal agent's ports (clock, randomness, logging, storage, Claw, metrics, HTTP), and, at @primusclaw/personal-agent-runtime/worker, the worker process on any chat surface.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@primusclaw/personal-agent": "0.12.0",
36
+ "@primusclaw/personal-agent": "0.14.0",
37
37
  "fastify": "^5.12.8",
38
38
  "zod": "^4.6.7"
39
39
  }