@agrentingai/paperclip-adapter 0.2.2 → 0.3.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.
@@ -438,9 +438,70 @@ declare function forwardCommentToAgrenting$1(config: AgrentingAdapterConfig, tas
438
438
  * Called by the webhook handler when it receives task messages.
439
439
  */
440
440
  declare function processIncomingMessage$1(message: TaskMessage): string;
441
+ /** Paperclip skill shape (subset of the canonical Paperclip Skill). */
442
+ interface PaperclipSkill {
443
+ id: string;
444
+ name: string;
445
+ description?: string;
446
+ }
447
+ /**
448
+ * Detect a sensible default model/provider for the configured Agrenting agent.
449
+ * Paperclip calls this to pre-populate the adapter UI when an agent is
450
+ * created. Returns null if no info is available.
451
+ */
452
+ declare function detectModel(config: Pick<AgrentingAdapterConfig, "agrentingUrl" | "apiKey" | "agentDid">): Promise<{
453
+ provider: string;
454
+ model: string;
455
+ } | null>;
456
+ /**
457
+ * Enumerate the configured Agrenting agent's capabilities and map them to
458
+ * Paperclip's Skill shape.
459
+ */
460
+ declare function listSkills(config: AgrentingAdapterConfig): Promise<PaperclipSkill[]>;
461
+ /**
462
+ * Reconcile the agent's current capabilities against Paperclip's local skill
463
+ * registry. Returns sets to add and remove.
464
+ */
465
+ declare function syncSkills(config: AgrentingAdapterConfig, existing: PaperclipSkill[]): Promise<{
466
+ added: PaperclipSkill[];
467
+ removed: PaperclipSkill[];
468
+ }>;
469
+ /**
470
+ * Session codec — Paperclip uses this to serialise session state across
471
+ * heartbeats. Hirings carry no rich session state, so we pass JSON through.
472
+ */
473
+ declare const sessionCodec: {
474
+ encode(state: unknown): string;
475
+ decode(blob: string | null | undefined): unknown;
476
+ };
477
+ /**
478
+ * Canonical `AgentAdapter.invoke`. Forwards to {@link execute}.
479
+ */
480
+ declare function invoke(config: AgrentingAdapterConfig, params: {
481
+ input: string;
482
+ capability: string;
483
+ instructions?: string;
484
+ maxPrice?: string;
485
+ paymentType?: string;
486
+ }): Promise<AgrentingExecutionResult>;
487
+ /**
488
+ * Canonical `AgentAdapter.status`. Returns the current run status.
489
+ */
490
+ declare function status(config: AgrentingAdapterConfig, taskId: string): Promise<{
491
+ status: AgrentingTaskStatus;
492
+ progressPercent: number;
493
+ progressMessage?: string;
494
+ }>;
495
+ /**
496
+ * Canonical `AgentAdapter.cancel`. Cancels a running task; throws on failure
497
+ * so Paperclip can treat the call as a void Promise.
498
+ */
499
+ declare function cancel(config: AgrentingAdapterConfig, taskId: string): Promise<void>;
441
500
  /**
442
501
  * Create the server-side adapter module.
443
- * This is the entry point for Paperclip's server adapter registry.
502
+ * Backward-compat convenience for callers that prefer a single bundle. New
503
+ * Paperclip plugin loaders should use the named exports directly via
504
+ * `~/.paperclip/adapter-plugins.json`.
444
505
  */
445
506
  declare function createServerAdapter(): {
446
507
  name: "agrenting";
@@ -474,6 +535,16 @@ declare function createServerAdapter(): {
474
535
  getTransactions: typeof getTransactions;
475
536
  deposit: typeof deposit;
476
537
  withdraw: typeof withdraw;
538
+ invoke: typeof invoke;
539
+ status: typeof status;
540
+ cancel: typeof cancel;
541
+ detectModel: typeof detectModel;
542
+ listSkills: typeof listSkills;
543
+ syncSkills: typeof syncSkills;
544
+ sessionCodec: {
545
+ encode(state: unknown): string;
546
+ decode(blob: string | null | undefined): unknown;
547
+ };
477
548
  };
478
549
 
479
550
  /**
@@ -892,4 +963,4 @@ declare function formatInsufficientBalanceComment(balanceInfo: BalanceInfo): str
892
963
  */
893
964
  declare function verifyWebhookSignature(rawBody: string, signature: string, secret: string): Promise<boolean>;
894
965
 
895
- export { type AgentInfo, type AgentProfile, type AgrentingAdapterConfig, AgrentingClient, type AgrentingExecutionResult, type AgrentingTask, type AgrentingTaskStatus, type AgrentingWebhookPayload, type AutoSelectOptions, type BalanceCheckOptions, type BalanceInfo, type Capability, type CreateTaskPaymentOptions, type DiscoverAgentsOptions, type HireAgentResult, type Hiring, type HiringMessage, MAX_POLLS, POLL_INTERVALS_MS, type PaperclipApiClient, type PaymentInfo, type PollOptions, type PollResult, type ReassignTaskResult, type RetryHiringOptions, type SendMessageOptions, type SendMessageResult, type TaskMessage, type TransactionInfo, type WebhookHandlerOptions, autoSelectAgent, canSubmitTask, checkBalance, createServerAdapter, createWebhookHandler, deregisterWebhook, executeWithRetry, formatAgentResponse, formatInsufficientBalanceComment, formatLowBalanceComment, forwardCommentToAgrenting, getActiveTaskMappings, getAgentProfile, getBackoffMs, getHiring, getHiringMessages, getTaskMessages, getWebhookGracePeriodMs, hireAgent, listCapabilities, listHirings, pollTaskUntilDone, processIncomingMessage, reassignTask, registerTaskMapping, registerWebhook, retryHiring, sendMessageToHiring, sendMessageToTask, unregisterTaskMapping, verifyWebhookSignature };
966
+ export { type AgentInfo, type AgentProfile, type AgrentingAdapterConfig, AgrentingClient, type AgrentingExecutionResult, type AgrentingTask, type AgrentingTaskStatus, type AgrentingWebhookPayload, type AutoSelectOptions, type BalanceCheckOptions, type BalanceInfo, type Capability, type CreateTaskPaymentOptions, type DiscoverAgentsOptions, type HireAgentResult, type Hiring, type HiringMessage, MAX_POLLS, POLL_INTERVALS_MS, type PaperclipApiClient, type PaperclipSkill, type PaymentInfo, type PollOptions, type PollResult, type ReassignTaskResult, type RetryHiringOptions, type SendMessageOptions, type SendMessageResult, type TaskMessage, type TransactionInfo, type WebhookHandlerOptions, autoSelectAgent, canSubmitTask, cancel, cancelTask, checkBalance, createServerAdapter, createWebhookHandler, deregisterWebhook, detectModel, execute, executeWithRetry, formatAgentResponse, formatInsufficientBalanceComment, formatLowBalanceComment, forwardCommentToAgrenting, getActiveTaskMappings, getAgentProfile, getBackoffMs, getConfigSchema, getHiring, getHiringMessages, getTaskMessages, getTaskProgress, getWebhookGracePeriodMs, hireAgent, invoke, listCapabilities, listHirings, listSkills, pollTaskUntilDone, processIncomingMessage, reassignTask, registerTaskMapping, registerWebhook, retryHiring, sendMessageToHiring, sendMessageToTask, sessionCodec, status, syncSkills, testEnvironment, unregisterTaskMapping, verifyWebhookSignature };
@@ -438,9 +438,70 @@ declare function forwardCommentToAgrenting$1(config: AgrentingAdapterConfig, tas
438
438
  * Called by the webhook handler when it receives task messages.
439
439
  */
440
440
  declare function processIncomingMessage$1(message: TaskMessage): string;
441
+ /** Paperclip skill shape (subset of the canonical Paperclip Skill). */
442
+ interface PaperclipSkill {
443
+ id: string;
444
+ name: string;
445
+ description?: string;
446
+ }
447
+ /**
448
+ * Detect a sensible default model/provider for the configured Agrenting agent.
449
+ * Paperclip calls this to pre-populate the adapter UI when an agent is
450
+ * created. Returns null if no info is available.
451
+ */
452
+ declare function detectModel(config: Pick<AgrentingAdapterConfig, "agrentingUrl" | "apiKey" | "agentDid">): Promise<{
453
+ provider: string;
454
+ model: string;
455
+ } | null>;
456
+ /**
457
+ * Enumerate the configured Agrenting agent's capabilities and map them to
458
+ * Paperclip's Skill shape.
459
+ */
460
+ declare function listSkills(config: AgrentingAdapterConfig): Promise<PaperclipSkill[]>;
461
+ /**
462
+ * Reconcile the agent's current capabilities against Paperclip's local skill
463
+ * registry. Returns sets to add and remove.
464
+ */
465
+ declare function syncSkills(config: AgrentingAdapterConfig, existing: PaperclipSkill[]): Promise<{
466
+ added: PaperclipSkill[];
467
+ removed: PaperclipSkill[];
468
+ }>;
469
+ /**
470
+ * Session codec — Paperclip uses this to serialise session state across
471
+ * heartbeats. Hirings carry no rich session state, so we pass JSON through.
472
+ */
473
+ declare const sessionCodec: {
474
+ encode(state: unknown): string;
475
+ decode(blob: string | null | undefined): unknown;
476
+ };
477
+ /**
478
+ * Canonical `AgentAdapter.invoke`. Forwards to {@link execute}.
479
+ */
480
+ declare function invoke(config: AgrentingAdapterConfig, params: {
481
+ input: string;
482
+ capability: string;
483
+ instructions?: string;
484
+ maxPrice?: string;
485
+ paymentType?: string;
486
+ }): Promise<AgrentingExecutionResult>;
487
+ /**
488
+ * Canonical `AgentAdapter.status`. Returns the current run status.
489
+ */
490
+ declare function status(config: AgrentingAdapterConfig, taskId: string): Promise<{
491
+ status: AgrentingTaskStatus;
492
+ progressPercent: number;
493
+ progressMessage?: string;
494
+ }>;
495
+ /**
496
+ * Canonical `AgentAdapter.cancel`. Cancels a running task; throws on failure
497
+ * so Paperclip can treat the call as a void Promise.
498
+ */
499
+ declare function cancel(config: AgrentingAdapterConfig, taskId: string): Promise<void>;
441
500
  /**
442
501
  * Create the server-side adapter module.
443
- * This is the entry point for Paperclip's server adapter registry.
502
+ * Backward-compat convenience for callers that prefer a single bundle. New
503
+ * Paperclip plugin loaders should use the named exports directly via
504
+ * `~/.paperclip/adapter-plugins.json`.
444
505
  */
445
506
  declare function createServerAdapter(): {
446
507
  name: "agrenting";
@@ -474,6 +535,16 @@ declare function createServerAdapter(): {
474
535
  getTransactions: typeof getTransactions;
475
536
  deposit: typeof deposit;
476
537
  withdraw: typeof withdraw;
538
+ invoke: typeof invoke;
539
+ status: typeof status;
540
+ cancel: typeof cancel;
541
+ detectModel: typeof detectModel;
542
+ listSkills: typeof listSkills;
543
+ syncSkills: typeof syncSkills;
544
+ sessionCodec: {
545
+ encode(state: unknown): string;
546
+ decode(blob: string | null | undefined): unknown;
547
+ };
477
548
  };
478
549
 
479
550
  /**
@@ -892,4 +963,4 @@ declare function formatInsufficientBalanceComment(balanceInfo: BalanceInfo): str
892
963
  */
893
964
  declare function verifyWebhookSignature(rawBody: string, signature: string, secret: string): Promise<boolean>;
894
965
 
895
- export { type AgentInfo, type AgentProfile, type AgrentingAdapterConfig, AgrentingClient, type AgrentingExecutionResult, type AgrentingTask, type AgrentingTaskStatus, type AgrentingWebhookPayload, type AutoSelectOptions, type BalanceCheckOptions, type BalanceInfo, type Capability, type CreateTaskPaymentOptions, type DiscoverAgentsOptions, type HireAgentResult, type Hiring, type HiringMessage, MAX_POLLS, POLL_INTERVALS_MS, type PaperclipApiClient, type PaymentInfo, type PollOptions, type PollResult, type ReassignTaskResult, type RetryHiringOptions, type SendMessageOptions, type SendMessageResult, type TaskMessage, type TransactionInfo, type WebhookHandlerOptions, autoSelectAgent, canSubmitTask, checkBalance, createServerAdapter, createWebhookHandler, deregisterWebhook, executeWithRetry, formatAgentResponse, formatInsufficientBalanceComment, formatLowBalanceComment, forwardCommentToAgrenting, getActiveTaskMappings, getAgentProfile, getBackoffMs, getHiring, getHiringMessages, getTaskMessages, getWebhookGracePeriodMs, hireAgent, listCapabilities, listHirings, pollTaskUntilDone, processIncomingMessage, reassignTask, registerTaskMapping, registerWebhook, retryHiring, sendMessageToHiring, sendMessageToTask, unregisterTaskMapping, verifyWebhookSignature };
966
+ export { type AgentInfo, type AgentProfile, type AgrentingAdapterConfig, AgrentingClient, type AgrentingExecutionResult, type AgrentingTask, type AgrentingTaskStatus, type AgrentingWebhookPayload, type AutoSelectOptions, type BalanceCheckOptions, type BalanceInfo, type Capability, type CreateTaskPaymentOptions, type DiscoverAgentsOptions, type HireAgentResult, type Hiring, type HiringMessage, MAX_POLLS, POLL_INTERVALS_MS, type PaperclipApiClient, type PaperclipSkill, type PaymentInfo, type PollOptions, type PollResult, type ReassignTaskResult, type RetryHiringOptions, type SendMessageOptions, type SendMessageResult, type TaskMessage, type TransactionInfo, type WebhookHandlerOptions, autoSelectAgent, canSubmitTask, cancel, cancelTask, checkBalance, createServerAdapter, createWebhookHandler, deregisterWebhook, detectModel, execute, executeWithRetry, formatAgentResponse, formatInsufficientBalanceComment, formatLowBalanceComment, forwardCommentToAgrenting, getActiveTaskMappings, getAgentProfile, getBackoffMs, getConfigSchema, getHiring, getHiringMessages, getTaskMessages, getTaskProgress, getWebhookGracePeriodMs, hireAgent, invoke, listCapabilities, listHirings, listSkills, pollTaskUntilDone, processIncomingMessage, reassignTask, registerTaskMapping, registerWebhook, retryHiring, sendMessageToHiring, sendMessageToTask, sessionCodec, status, syncSkills, testEnvironment, unregisterTaskMapping, verifyWebhookSignature };
@@ -841,11 +841,11 @@ async function startWebhookListener(config) {
841
841
  if (resolvedTaskId) {
842
842
  const pending = pendingTasks.get(resolvedTaskId);
843
843
  if (pending && !pending.settled) {
844
- const status = payload.status ?? pending.status;
845
- pending.status = status;
844
+ const status2 = payload.status ?? pending.status;
845
+ pending.status = status2;
846
846
  pending.progressPercent = payload.progress_percent ?? pending.progressPercent;
847
847
  pending.progressMessage = payload.progress_message ?? pending.progressMessage;
848
- if (status === "completed") {
848
+ if (status2 === "completed") {
849
849
  pending.settled = true;
850
850
  pending.resolve({
851
851
  success: true,
@@ -853,7 +853,7 @@ async function startWebhookListener(config) {
853
853
  taskId: resolvedTaskId,
854
854
  durationMs: Date.now() - pending.startedAt
855
855
  });
856
- } else if (status === "failed") {
856
+ } else if (status2 === "failed") {
857
857
  pending.settled = true;
858
858
  pending.resolve({
859
859
  success: false,
@@ -861,7 +861,7 @@ async function startWebhookListener(config) {
861
861
  taskId: resolvedTaskId,
862
862
  durationMs: Date.now() - pending.startedAt
863
863
  });
864
- } else if (status === "cancelled") {
864
+ } else if (status2 === "cancelled") {
865
865
  pending.settled = true;
866
866
  pending.resolve({
867
867
  success: false,
@@ -1262,6 +1262,65 @@ function processIncomingMessage2(message) {
1262
1262
  const senderName = message.sender_name ?? "Agent";
1263
1263
  return formatAgentResponse(senderName, message.content);
1264
1264
  }
1265
+ async function detectModel(config) {
1266
+ if (!config.agentDid) return null;
1267
+ try {
1268
+ const profile = await getAgentProfile(config, config.agentDid);
1269
+ const provider = profile.ai_provider ?? null;
1270
+ const model = profile.ai_model ?? null;
1271
+ if (provider && model) return { provider, model };
1272
+ } catch {
1273
+ }
1274
+ return null;
1275
+ }
1276
+ async function listSkills(config) {
1277
+ const profile = await getAgentProfile(config, config.agentDid);
1278
+ const capabilities = profile.capabilities ?? [];
1279
+ return capabilities.map((cap) => ({
1280
+ id: `${config.agentDid}:${cap}`,
1281
+ name: cap,
1282
+ description: `Capability "${cap}" of agent ${config.agentDid}`
1283
+ }));
1284
+ }
1285
+ async function syncSkills(config, existing) {
1286
+ const remote = await listSkills(config);
1287
+ const remoteIds = new Set(remote.map((s) => s.id));
1288
+ const existingIds = new Set(existing.map((s) => s.id));
1289
+ return {
1290
+ added: remote.filter((s) => !existingIds.has(s.id)),
1291
+ removed: existing.filter((s) => !remoteIds.has(s.id))
1292
+ };
1293
+ }
1294
+ var sessionCodec = {
1295
+ encode(state) {
1296
+ return JSON.stringify(state ?? null);
1297
+ },
1298
+ decode(blob) {
1299
+ if (!blob) return null;
1300
+ try {
1301
+ return JSON.parse(blob);
1302
+ } catch {
1303
+ return null;
1304
+ }
1305
+ }
1306
+ };
1307
+ async function invoke(config, params) {
1308
+ return execute(config, params);
1309
+ }
1310
+ async function status(config, taskId) {
1311
+ const progress = await getTaskProgress(config, taskId);
1312
+ return {
1313
+ status: progress.status,
1314
+ progressPercent: progress.progressPercent,
1315
+ progressMessage: progress.progressMessage
1316
+ };
1317
+ }
1318
+ async function cancel(config, taskId) {
1319
+ const result = await cancelTask(config, taskId);
1320
+ if (!result.success) {
1321
+ throw new Error(result.error ?? "Failed to cancel task");
1322
+ }
1323
+ }
1265
1324
  function createServerAdapter() {
1266
1325
  return {
1267
1326
  name: "agrenting",
@@ -1294,7 +1353,15 @@ function createServerAdapter() {
1294
1353
  getBalance,
1295
1354
  getTransactions,
1296
1355
  deposit,
1297
- withdraw
1356
+ withdraw,
1357
+ // Canonical contract additions:
1358
+ invoke,
1359
+ status,
1360
+ cancel,
1361
+ detectModel,
1362
+ listSkills,
1363
+ syncSkills,
1364
+ sessionCodec
1298
1365
  };
1299
1366
  }
1300
1367
  export {
@@ -1303,10 +1370,14 @@ export {
1303
1370
  POLL_INTERVALS_MS,
1304
1371
  autoSelectAgent,
1305
1372
  canSubmitTask,
1373
+ cancel,
1374
+ cancelTask,
1306
1375
  checkBalance,
1307
1376
  createServerAdapter,
1308
1377
  createWebhookHandler,
1309
1378
  deregisterWebhook,
1379
+ detectModel,
1380
+ execute,
1310
1381
  executeWithRetry,
1311
1382
  formatAgentResponse,
1312
1383
  formatInsufficientBalanceComment,
@@ -1315,13 +1386,17 @@ export {
1315
1386
  getActiveTaskMappings,
1316
1387
  getAgentProfile,
1317
1388
  getBackoffMs,
1389
+ getConfigSchema,
1318
1390
  getHiring,
1319
1391
  getHiringMessages,
1320
1392
  getTaskMessages,
1393
+ getTaskProgress,
1321
1394
  getWebhookGracePeriodMs,
1322
1395
  hireAgent,
1396
+ invoke,
1323
1397
  listCapabilities,
1324
1398
  listHirings,
1399
+ listSkills,
1325
1400
  pollTaskUntilDone,
1326
1401
  processIncomingMessage,
1327
1402
  reassignTask,
@@ -1330,6 +1405,10 @@ export {
1330
1405
  retryHiring,
1331
1406
  sendMessageToHiring,
1332
1407
  sendMessageToTask,
1408
+ sessionCodec,
1409
+ status,
1410
+ syncSkills,
1411
+ testEnvironment,
1333
1412
  unregisterTaskMapping,
1334
1413
  verifyWebhookSignature
1335
1414
  };