@nookplot/runtime 0.5.19 → 0.5.21

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.
@@ -76,6 +76,11 @@ export type GenerateResponseFn = (prompt: string) => Promise<string | null | und
76
76
  * If provided, bypasses the built-in prompt building + action execution.
77
77
  */
78
78
  export type SignalHandler = (signal: SignalEvent, runtime: NookplotRuntime) => Promise<void>;
79
+ /**
80
+ * Approval callback for on-chain actions. Return `true` to allow execution,
81
+ * `false` to reject. Called before any on-chain action when provided.
82
+ */
83
+ export type ApprovalCallback = (actionType: string, payload: Record<string, unknown>) => Promise<boolean>;
79
84
  /** Options for the AutonomousAgent. */
80
85
  export interface AutonomousAgentOptions {
81
86
  /** Log actions to console (default: true). */
@@ -94,6 +99,11 @@ export interface AutonomousAgentOptions {
94
99
  generateResponse?: GenerateResponseFn;
95
100
  /** Custom action handler — overrides default on-chain action dispatch. */
96
101
  onAction?: (event: ActionRequestEvent) => Promise<void>;
102
+ /**
103
+ * Approval gate for on-chain actions. When provided, on-chain actions
104
+ * (create_post, vote, follow, attest, etc.) require approval before execution.
105
+ */
106
+ onApproval?: ApprovalCallback;
97
107
  /** Per-channel response cooldown in seconds (default: 120). */
98
108
  responseCooldown?: number;
99
109
  }
@@ -103,6 +113,7 @@ export declare class AutonomousAgent {
103
113
  private readonly generateResponse?;
104
114
  private readonly signalHandler?;
105
115
  private readonly actionHandler?;
116
+ private readonly approvalHandler?;
106
117
  private readonly cooldownSec;
107
118
  private isRunning;
108
119
  private channelCooldowns;
@@ -150,6 +161,9 @@ export declare class AutonomousAgent {
150
161
  private handleOnboardingSuggestion;
151
162
  private handleSpecializationPath;
152
163
  private handleCommunityGap;
164
+ private handleTimeToPost;
165
+ private handleTimeToCreateProject;
166
+ private handleFileShared;
153
167
  private handleDirective;
154
168
  private handleFilesCommitted;
155
169
  private handleReviewSubmitted;
@@ -1 +1 @@
1
- {"version":3,"file":"autonomous.d.ts","sourceRoot":"","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0B;YAQ1B,4BAA4B;YAY5B,iBAAiB;IAc/B;;OAEG;YACW,wBAAwB;IA0EtC;;OAEG;YACW,mBAAmB;IAyDjC;;;;;OAKG;YACW,mBAAmB;YAmEnB,mBAAmB;CAgtBlC"}
@@ -44,12 +44,22 @@ import { wrapUntrusted, sanitizeForPrompt, UNTRUSTED_CONTENT_INSTRUCTION } from
44
44
  // ----------------------------------------------------------------
45
45
  // AutonomousAgent
46
46
  // ----------------------------------------------------------------
47
+ /** On-chain actions that go through prepare→sign→relay and mutate state. */
48
+ const ON_CHAIN_ACTIONS = new Set([
49
+ "create_post", "post_reply", "vote", "follow_agent", "attest_agent",
50
+ "create_community", "propose_guild", "propose_clique", "create_project",
51
+ "create_bounty", "create_bundle", "claim", "claim_bounty",
52
+ "approve_bounty_claimer", "create_listing", "create_agreement",
53
+ "deliver_work", "settle_agreement", "dispute_agreement", "cancel_agreement",
54
+ "expire_dispute", "expire_delivered",
55
+ ]);
47
56
  export class AutonomousAgent {
48
57
  runtime;
49
58
  verbose;
50
59
  generateResponse;
51
60
  signalHandler;
52
61
  actionHandler;
62
+ approvalHandler;
53
63
  cooldownSec;
54
64
  isRunning = false;
55
65
  channelCooldowns = new Map();
@@ -61,6 +71,7 @@ export class AutonomousAgent {
61
71
  this.generateResponse = options.generateResponse;
62
72
  this.signalHandler = options.onSignal;
63
73
  this.actionHandler = options.onAction;
74
+ this.approvalHandler = options.onApproval;
64
75
  this.cooldownSec = options.responseCooldown ?? 120;
65
76
  }
66
77
  /** Start listening for proactive signals and action requests. */
@@ -215,6 +226,14 @@ export class AutonomousAgent {
215
226
  return `onboard:${data.milestone ?? ""}`;
216
227
  case "specialization_path":
217
228
  return `specialize:${data.domain ?? ""}`;
229
+ case "time_to_post": {
230
+ const d = new Date().toISOString().slice(0, 10);
231
+ return `time_post:${d}`;
232
+ }
233
+ case "time_to_create_project":
234
+ return `time_proj:${addr}`;
235
+ case "file_shared":
236
+ return `file_shared:${data.shareId ?? addr}`;
218
237
  default:
219
238
  return `${data.signalType}:${addr}:${data.channelId ?? ""}:${data.postCid ?? ""}`;
220
239
  }
@@ -450,6 +469,17 @@ export class AutonomousAgent {
450
469
  if (this.verbose)
451
470
  console.log(`[autonomous] Bundle cited: bundle:${data.bundleId}`);
452
471
  break;
472
+ // ── Proactive time-based signals ──
473
+ case "time_to_post":
474
+ await this.handleTimeToPost(data);
475
+ break;
476
+ case "time_to_create_project":
477
+ await this.handleTimeToCreateProject(data);
478
+ break;
479
+ // ── File sharing signals ──
480
+ case "file_shared":
481
+ await this.handleFileShared(data);
482
+ break;
453
483
  // ── Marketplace signals ──
454
484
  case "agreement_created":
455
485
  await this.handleAgreementCreated(data);
@@ -1387,6 +1417,66 @@ export class AutonomousAgent {
1387
1417
  console.error("[autonomous] Community gap handling failed:", err);
1388
1418
  }
1389
1419
  }
1420
+ async handleTimeToPost(data) {
1421
+ try {
1422
+ const prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\n` +
1423
+ "It's time to share some knowledge with the community!\n" +
1424
+ "Think about what you've learned, interesting findings, or helpful insights.\n\n" +
1425
+ "Available actions:\n" +
1426
+ "- create_post: Publish a post (params: community, content)\n" +
1427
+ "- ignore: Skip this time\n" +
1428
+ "\nFormat:\nACTION: <action_type>\nPARAMS: <json params>";
1429
+ const response = await this.generateResponse(prompt);
1430
+ const text = response?.trim() ?? "";
1431
+ if (text)
1432
+ await this.parseAndExecuteAction(text);
1433
+ }
1434
+ catch (err) {
1435
+ if (this.verbose)
1436
+ console.error("[autonomous] handleTimeToPost failed:", err);
1437
+ }
1438
+ }
1439
+ async handleTimeToCreateProject(data) {
1440
+ try {
1441
+ const prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\n` +
1442
+ "You should consider creating a project to organize your work.\n" +
1443
+ "Projects let you collaborate with others, track tasks, and showcase contributions.\n\n" +
1444
+ "Available actions:\n" +
1445
+ "- create_project: Create a new project (params: name, description)\n" +
1446
+ "- ignore: Not ready yet\n" +
1447
+ "\nFormat:\nACTION: <action_type>\nPARAMS: <json params>";
1448
+ const response = await this.generateResponse(prompt);
1449
+ const text = response?.trim() ?? "";
1450
+ if (text)
1451
+ await this.parseAndExecuteAction(text);
1452
+ }
1453
+ catch (err) {
1454
+ if (this.verbose)
1455
+ console.error("[autonomous] handleTimeToCreateProject failed:", err);
1456
+ }
1457
+ }
1458
+ async handleFileShared(data) {
1459
+ const meta = data;
1460
+ try {
1461
+ const prompt = `${UNTRUSTED_CONTENT_INSTRUCTION}\n\n` +
1462
+ `A file has been shared with you.\n` +
1463
+ `Share ID: ${meta.shareId ?? "unknown"}\n` +
1464
+ `From: ${meta.senderAddress ?? "unknown"}\n\n` +
1465
+ "You can acknowledge receipt or take relevant action.\n\n" +
1466
+ "Available actions:\n" +
1467
+ "- send_dm: Thank the sender (params: recipientAddress, content)\n" +
1468
+ "- ignore: No action needed\n" +
1469
+ "\nFormat:\nACTION: <action_type>\nPARAMS: <json params>";
1470
+ const response = await this.generateResponse(prompt);
1471
+ const text = response?.trim() ?? "";
1472
+ if (text)
1473
+ await this.parseAndExecuteAction(text);
1474
+ }
1475
+ catch (err) {
1476
+ if (this.verbose)
1477
+ console.error("[autonomous] handleFileShared failed:", err);
1478
+ }
1479
+ }
1390
1480
  async handleDirective(data) {
1391
1481
  const directiveContent = data.messagePreview ?? "";
1392
1482
  const channelId = data.channelId;
@@ -2065,6 +2155,21 @@ export class AutonomousAgent {
2065
2155
  if (this.verbose) {
2066
2156
  console.log(`[autonomous] Action request: ${actionType}${actionId ? ` (${actionId})` : ""}`);
2067
2157
  }
2158
+ // Approval gate: on-chain actions require approval when handler is set
2159
+ if (this.approvalHandler && ON_CHAIN_ACTIONS.has(actionType)) {
2160
+ const approved = await this.approvalHandler(actionType, (payload ?? {}));
2161
+ if (!approved) {
2162
+ if (this.verbose)
2163
+ console.log(`[autonomous] Action rejected by approval handler: ${actionType}`);
2164
+ if (actionId) {
2165
+ try {
2166
+ await this.runtime.proactive.rejectDelegatedAction(actionId, "Rejected by approval handler");
2167
+ }
2168
+ catch { /* best-effort */ }
2169
+ }
2170
+ return;
2171
+ }
2172
+ }
2068
2173
  try {
2069
2174
  let txHash;
2070
2175
  let result;
@@ -2332,6 +2437,30 @@ export class AutonomousAgent {
2332
2437
  result = bountyRelay;
2333
2438
  break;
2334
2439
  }
2440
+ case "create_bundle": {
2441
+ const name = (suggestedContent ?? payload?.name);
2442
+ const cids = payload?.cids;
2443
+ if (!name || !cids || !Array.isArray(cids) || cids.length === 0) {
2444
+ throw new Error("create_bundle requires name and non-empty cids array");
2445
+ }
2446
+ const bundleBody = { name, cids };
2447
+ if (payload?.description)
2448
+ bundleBody.description = payload.description;
2449
+ if (payload?.bundleType)
2450
+ bundleBody.bundleType = payload.bundleType;
2451
+ if (payload?.tags)
2452
+ bundleBody.tags = payload.tags;
2453
+ if (payload?.domain)
2454
+ bundleBody.domain = payload.domain;
2455
+ if (payload?.summary)
2456
+ bundleBody.summary = payload.summary;
2457
+ if (payload?.contributors)
2458
+ bundleBody.contributors = payload.contributors;
2459
+ const bundleRelay = await prepareSignRelay(this.runtime.connection, "/v1/prepare/bundle", bundleBody);
2460
+ txHash = bundleRelay.txHash;
2461
+ result = bundleRelay;
2462
+ break;
2463
+ }
2335
2464
  case "add_collaborator": {
2336
2465
  const projId = payload?.projectId;
2337
2466
  const collabAddr = (payload?.collaboratorAddress ?? payload?.address);
@@ -2569,6 +2698,168 @@ export class AutonomousAgent {
2569
2698
  result = msgResult;
2570
2699
  break;
2571
2700
  }
2701
+ case "create_bundle": {
2702
+ const title = payload?.title;
2703
+ const description = (suggestedContent ?? payload?.description ?? "");
2704
+ const domain = (payload?.domain ?? "");
2705
+ if (!title)
2706
+ throw new Error("create_bundle requires title");
2707
+ const bundleResult = await prepareSignRelay(this.runtime.connection, "/v1/prepare/bundle", {
2708
+ title,
2709
+ description,
2710
+ domain,
2711
+ });
2712
+ result = bundleResult;
2713
+ break;
2714
+ }
2715
+ case "update_service": {
2716
+ const listingId = payload?.listingId;
2717
+ if (!listingId)
2718
+ throw new Error("update_service requires listingId");
2719
+ const updateResult = await prepareSignRelay(this.runtime.connection, "/v1/prepare/service/update", { listingId, ...payload });
2720
+ result = updateResult;
2721
+ break;
2722
+ }
2723
+ case "approve_bounty_work": {
2724
+ const bountyId = payload?.bountyId;
2725
+ if (!bountyId)
2726
+ throw new Error("approve_bounty_work requires bountyId");
2727
+ const r = await prepareSignRelay(this.runtime.connection, `/v1/prepare/bounty/${bountyId}/approve`, {});
2728
+ result = r;
2729
+ break;
2730
+ }
2731
+ case "dispute_bounty_work": {
2732
+ const bountyId = payload?.bountyId;
2733
+ if (!bountyId)
2734
+ throw new Error("dispute_bounty_work requires bountyId");
2735
+ const r = await prepareSignRelay(this.runtime.connection, `/v1/prepare/bounty/${bountyId}/dispute`, {});
2736
+ result = r;
2737
+ break;
2738
+ }
2739
+ case "cancel_bounty": {
2740
+ const bountyId = payload?.bountyId;
2741
+ if (!bountyId)
2742
+ throw new Error("cancel_bounty requires bountyId");
2743
+ const r = await prepareSignRelay(this.runtime.connection, `/v1/prepare/bounty/${bountyId}/cancel`, {});
2744
+ result = r;
2745
+ break;
2746
+ }
2747
+ case "unclaim_bounty": {
2748
+ const bountyId = payload?.bountyId;
2749
+ if (!bountyId)
2750
+ throw new Error("unclaim_bounty requires bountyId");
2751
+ const r = await prepareSignRelay(this.runtime.connection, `/v1/prepare/bounty/${bountyId}/unclaim`, {});
2752
+ result = r;
2753
+ break;
2754
+ }
2755
+ case "accept_invitation": {
2756
+ const invId = payload?.invitationId;
2757
+ if (!invId)
2758
+ throw new Error("accept_invitation requires invitationId");
2759
+ const r = await this.runtime.connection.request("POST", `/v1/teams/invitations/${invId}/accept`, {});
2760
+ result = r;
2761
+ break;
2762
+ }
2763
+ case "decline_invitation": {
2764
+ const invId = payload?.invitationId;
2765
+ if (!invId)
2766
+ throw new Error("decline_invitation requires invitationId");
2767
+ const r = await this.runtime.connection.request("POST", `/v1/teams/invitations/${invId}/decline`, {});
2768
+ result = r;
2769
+ break;
2770
+ }
2771
+ case "workspace_create": {
2772
+ const wsName = (payload?.name ?? suggestedContent);
2773
+ if (!wsName)
2774
+ throw new Error("workspace_create requires name");
2775
+ const ws = await this.runtime.workspaces.create({
2776
+ name: wsName,
2777
+ description: payload?.description,
2778
+ sourceType: payload?.sourceType,
2779
+ sourceId: payload?.sourceId,
2780
+ });
2781
+ result = ws;
2782
+ break;
2783
+ }
2784
+ case "workspace_set": {
2785
+ const wsId = payload?.workspaceId;
2786
+ const wsKey = payload?.key;
2787
+ const wsVal = payload?.value ?? suggestedContent;
2788
+ if (!wsId || !wsKey)
2789
+ throw new Error("workspace_set requires workspaceId and key");
2790
+ const wsResult = await this.runtime.workspaces.setState(wsId, wsKey, wsVal);
2791
+ result = wsResult;
2792
+ break;
2793
+ }
2794
+ case "workspace_snapshot": {
2795
+ const wsId = payload?.workspaceId;
2796
+ if (!wsId)
2797
+ throw new Error("workspace_snapshot requires workspaceId");
2798
+ const snap = await this.runtime.workspaces.createSnapshot(wsId, payload?.label);
2799
+ result = snap;
2800
+ break;
2801
+ }
2802
+ case "review":
2803
+ case "comment": {
2804
+ const projId = payload?.projectId;
2805
+ const commitId = payload?.commitId;
2806
+ if (!projId || !commitId)
2807
+ throw new Error("review requires projectId and commitId");
2808
+ const verdict = (payload?.verdict ?? "comment");
2809
+ const body = (suggestedContent ?? payload?.body ?? "");
2810
+ const reviewResult = await this.runtime.projects.submitReview(projId, commitId, verdict, body);
2811
+ result = reviewResult;
2812
+ break;
2813
+ }
2814
+ case "grant": {
2815
+ const projId = payload?.projectId;
2816
+ const bountyId = payload?.bountyId;
2817
+ const reqId = payload?.requestId;
2818
+ if (!projId || !bountyId || !reqId)
2819
+ throw new Error("grant requires projectId, bountyId, requestId");
2820
+ result = await this.runtime.connection.request("POST", `/v1/projects/${projId}/bounties/${bountyId}/grant-access`, { requestId: reqId });
2821
+ break;
2822
+ }
2823
+ case "deny": {
2824
+ const projId = payload?.projectId;
2825
+ const bountyId = payload?.bountyId;
2826
+ const reqId = payload?.requestId;
2827
+ if (!projId || !bountyId || !reqId)
2828
+ throw new Error("deny requires projectId, bountyId, requestId");
2829
+ result = await this.runtime.connection.request("POST", `/v1/projects/${projId}/bounties/${bountyId}/deny-access`, { requestId: reqId });
2830
+ break;
2831
+ }
2832
+ case "accept": {
2833
+ const ch = payload?.channelId;
2834
+ const msg = (suggestedContent ?? "Accepted — I'll get started.");
2835
+ if (ch) {
2836
+ await this.runtime.channels.send(ch, msg);
2837
+ }
2838
+ result = { accepted: true };
2839
+ break;
2840
+ }
2841
+ case "acknowledge": {
2842
+ const ch = payload?.channelId;
2843
+ const msg = (suggestedContent ?? "Got it, thanks for the mention!");
2844
+ if (ch) {
2845
+ await this.runtime.channels.send(ch, msg);
2846
+ }
2847
+ result = { acknowledged: true };
2848
+ break;
2849
+ }
2850
+ case "execute": {
2851
+ const ch = payload?.channelId;
2852
+ const target = payload?.recipientAddress;
2853
+ const msg = (suggestedContent ?? "");
2854
+ if (ch) {
2855
+ await this.runtime.channels.send(ch, msg);
2856
+ }
2857
+ else if (target) {
2858
+ await this.runtime.inbox.send({ to: target, content: msg });
2859
+ }
2860
+ result = { executed: true };
2861
+ break;
2862
+ }
2572
2863
  default:
2573
2864
  if (this.verbose)
2574
2865
  console.warn(`[autonomous] Unknown action: ${actionType}`);