@agent-wire/terminal 1.7.5 → 1.7.7

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/api.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ import type { CreditAmount } from './contracts/credit-amount.js';
1
2
  import type { WireNodeConfig } from './config.js';
2
3
  import type { MarketNativeDocsIngestMode, RemoteDocument } from './sync/types.js';
4
+ export declare class RegistrationError extends Error {
5
+ readonly status: number;
6
+ constructor(status: number, message: string);
7
+ }
3
8
  type LegacyActionInvokeParams = {
4
9
  action_id: string;
5
10
  mode: string;
@@ -11,8 +16,18 @@ type LegacyActionInvokeParams = {
11
16
  type LegacyActionChainParams = LegacyActionInvokeParams & {
12
17
  chain_id?: string;
13
18
  };
19
+ export interface MeshScopeParams {
20
+ scope?: 'agent' | 'fleet' | 'circle';
21
+ circle_id?: string;
22
+ }
14
23
  export interface QueryParams {
15
- text: string;
24
+ text?: string;
25
+ types?: string | string[];
26
+ type?: string;
27
+ exclude_types?: string | string[];
28
+ exclude_type?: string;
29
+ creator?: string;
30
+ agent?: string;
16
31
  domain?: string;
17
32
  limit?: number;
18
33
  offset?: number;
@@ -46,14 +61,14 @@ export interface ContributeParams {
46
61
  claim: string;
47
62
  trackable: boolean;
48
63
  }>;
49
- price?: number;
64
+ price?: CreditAmount;
50
65
  pricing_curve?: Array<{
51
66
  credits: number;
52
67
  after_hours: number;
53
68
  }>;
54
69
  curve_power?: number;
55
70
  bid?: {
56
- amount: number;
71
+ amount: CreditAmount;
57
72
  duration_hours: number;
58
73
  };
59
74
  embargo_until?: string;
@@ -111,7 +126,7 @@ export interface StakeResult {
111
126
  position: {
112
127
  id: string;
113
128
  side: string;
114
- amount: number;
129
+ amount: CreditAmount;
115
130
  created_at: string;
116
131
  };
117
132
  market: {
@@ -133,7 +148,7 @@ export interface MarketStatus {
133
148
  your_positions: Array<{
134
149
  id: string;
135
150
  side: string;
136
- amount: number;
151
+ amount: CreditAmount;
137
152
  created_at: string;
138
153
  }>;
139
154
  resolution: {
@@ -165,8 +180,8 @@ export interface PinPreview {
165
180
  export interface RetractionResult {
166
181
  retracted: boolean;
167
182
  contribution_id: string;
168
- deposit_refund: number;
169
- deposit_forfeit: number;
183
+ deposit_refund: CreditAmount;
184
+ deposit_forfeit: CreditAmount;
170
185
  bounty_clawback: number;
171
186
  }
172
187
  export interface RateParams {
@@ -271,13 +286,15 @@ export type WireEventStreamMessage = {
271
286
  event: string;
272
287
  data: unknown;
273
288
  };
274
- declare function normalizeHelpTopic(topic: string | undefined): string;
289
+ export declare function normalizeWaitTimeoutSeconds(timeoutSeconds: number | undefined): number;
290
+ export declare function normalizeHelpTopic(topic: string | undefined): string;
275
291
  export declare const __wireApiTestInternals: {
276
292
  normalizeHelpTopic: typeof normalizeHelpTopic;
277
293
  parseSseBlock: typeof parseSseBlock;
278
294
  };
279
295
  declare function parseSseBlock(block: string): WireEventStreamMessage | null;
280
296
  export declare class WireAPI {
297
+ claims(params: Record<string, unknown>): Promise<unknown>;
281
298
  private baseUrl;
282
299
  private token;
283
300
  private nodeId;
@@ -327,7 +344,7 @@ export declare class WireAPI {
327
344
  }>;
328
345
  submitResult(workId: string, result: Record<string, unknown>): Promise<{
329
346
  credits_awarded: number;
330
- balance_after: number;
347
+ balance_after: CreditAmount;
331
348
  }>;
332
349
  heartbeat(nodeId: string): Promise<{
333
350
  status: string;
@@ -359,7 +376,32 @@ export declare class WireAPI {
359
376
  accessContribution(contributionId: string): Promise<Record<string, unknown>>;
360
377
  private verifyLocalContributionReadRoute;
361
378
  private localHeaders;
379
+ private localAuthToken;
362
380
  private tryLocalContributionRead;
381
+ /**
382
+ * Generic local-node fetch for the pyramid consume-head proxies. Returns the
383
+ * parsed JSON body on success, throws a descriptive error on non-2xx.
384
+ */
385
+ private localNodeFetch;
386
+ /**
387
+ * pyramid_map — GET /pyramid/{slug}/map.
388
+ * Apex synthesis + freshness counts + nav skeleton + unresolved gaps.
389
+ * Orient first at boot, then drill via pyramid_hydrate using nav node ids.
390
+ */
391
+ getPyramidMap(slug: string): Promise<Record<string, unknown>>;
392
+ /**
393
+ * pyramid_hydrate — GET /pyramid/{slug}/drill/{node_id}.
394
+ * Returns the DrillResult: full node content (headline/distilled/narrative
395
+ * via the node payload) plus children, evidence, gaps, web_edges, and
396
+ * question context. Pull one node/region after orienting via pyramid_map.
397
+ */
398
+ getPyramidDrill(slug: string, nodeId: string): Promise<Record<string, unknown>>;
399
+ /**
400
+ * pyramid_ask — POST /pyramid/{slug}/question body { question }.
401
+ * Cheap (<5s, no-LLM) mechanical retrieval over the existing pyramid;
402
+ * returns a markdown answer plus node-id citations / sources.
403
+ */
404
+ askPyramid(slug: string, question: string): Promise<Record<string, unknown>>;
363
405
  /**
364
406
  * Rate a Wire item. Free. Must have accessed it first.
365
407
  */
@@ -416,31 +458,31 @@ export declare class WireAPI {
416
458
  /**
417
459
  * Get full mesh status: active threads, intents, blackboard.
418
460
  */
419
- meshStatus(): Promise<Record<string, unknown>>;
461
+ meshStatus(scope?: MeshScopeParams): Promise<Record<string, unknown>>;
420
462
  /**
421
463
  * Read the shared blackboard.
422
464
  */
423
- meshBoardRead(): Promise<Record<string, unknown>>;
465
+ meshBoardRead(scope?: MeshScopeParams): Promise<Record<string, unknown>>;
424
466
  /**
425
467
  * Write a key-value entry to the shared blackboard.
426
468
  */
427
- meshBoardWrite(key: string, value: unknown, ttl?: number): Promise<Record<string, unknown>>;
469
+ meshBoardWrite(key: string, value: unknown, ttl?: number, scope?: MeshScopeParams): Promise<Record<string, unknown>>;
428
470
  /**
429
471
  * Delete a key from the shared blackboard.
430
472
  */
431
- meshBoardDelete(key: string): Promise<Record<string, unknown>>;
473
+ meshBoardDelete(key: string, scope?: MeshScopeParams): Promise<Record<string, unknown>>;
432
474
  /**
433
475
  * Declare an intent (what this thread is about to do).
434
476
  */
435
- meshDeclareIntent(action: string, domain?: string, meta?: Record<string, unknown>, ttl?: number): Promise<Record<string, unknown>>;
477
+ meshDeclareIntent(action: string, domain?: string, meta?: Record<string, unknown>, ttl?: number, scope?: MeshScopeParams): Promise<Record<string, unknown>>;
436
478
  /**
437
479
  * Release (delete) an intent.
438
480
  */
439
- meshReleaseIntent(intentId: string): Promise<Record<string, unknown>>;
481
+ meshReleaseIntent(intentId: string, scope?: MeshScopeParams): Promise<Record<string, unknown>>;
440
482
  /**
441
483
  * Get active intents for this agent.
442
484
  */
443
- meshGetIntents(): Promise<Record<string, unknown>>;
485
+ meshGetIntents(scope?: MeshScopeParams): Promise<Record<string, unknown>>;
444
486
  /**
445
487
  * Stake credits on a prediction market attached to a contribution.
446
488
  * The contribution must have a claim with `market.enabled: true`.
@@ -450,7 +492,7 @@ export declare class WireAPI {
450
492
  * @param side - 'agree' or 'disagree'
451
493
  * @param amount - Number of credits to stake (must be >= market's min_stake)
452
494
  */
453
- stakeMarket(contributionId: string, side: 'agree' | 'disagree', amount: number): Promise<StakeResult>;
495
+ stakeMarket(contributionId: string, side: 'agree' | 'disagree', amount: CreditAmount, requestId?: string): Promise<StakeResult>;
454
496
  /**
455
497
  * Get the current status of a prediction market, including pool sizes,
456
498
  * your positions, and resolution status if resolved.
@@ -616,9 +658,10 @@ export declare class WireAPI {
616
658
  proposeSupersession(targetId: string, contributionId: string): Promise<Record<string, unknown>>;
617
659
  acceptSupersession(proposalId: string): Promise<Record<string, unknown>>;
618
660
  rejectSupersession(proposalId: string): Promise<Record<string, unknown>>;
619
- executeSupersession(targetId: string, newContributionId: string): Promise<Record<string, unknown>>;
620
- submitCorrection(targetId: string, correctionContributionId: string, depositAmount: number): Promise<Record<string, unknown>>;
621
- endorseCorrection(correctionId: string, depositAmount: number): Promise<Record<string, unknown>>;
661
+ executeSupersession(targetId: string, newContributionId: string, allowTypeChange?: boolean): Promise<Record<string, unknown>>;
662
+ submitCorrection(targetId: string, correctionContributionId: string, depositAmount: CreditAmount): Promise<Record<string, unknown>>;
663
+ withdrawCorrection(correctionId: string): Promise<Record<string, unknown>>;
664
+ endorseCorrection(correctionId: string, depositAmount: CreditAmount): Promise<Record<string, unknown>>;
622
665
  listCircles(): Promise<Record<string, unknown>>;
623
666
  createCircle(name: string, partnerEmail: string, description?: string): Promise<Record<string, unknown>>;
624
667
  joinCircle(circleId: string): Promise<Record<string, unknown>>;
@@ -727,4 +770,13 @@ export declare class WireAPI {
727
770
  getRosterWithDeviceSecret(deviceSecret: string, harness?: string, hintName?: string): Promise<Record<string, unknown>>;
728
771
  resumeAgent(agentName: string, deviceSecret: string, nonce: string): Promise<Record<string, unknown>>;
729
772
  }
773
+ /**
774
+ * Paginate through all results from a fetch function.
775
+ * Concatenates pages until a page returns fewer than pageSize items.
776
+ *
777
+ * @param fetchPage - Function that fetches a page (1-indexed page number, pageSize)
778
+ * @param pageSize - Number of items per page (default 100)
779
+ * @returns All items concatenated
780
+ */
781
+ export declare function paginateAll<T>(fetchPage: (page: number, pageSize: number) => Promise<T[]>, pageSize?: number): Promise<T[]>;
730
782
  export {};
package/dist/api.js CHANGED
@@ -1,8 +1,15 @@
1
- import { paginateAll } from './sync/paginate.js';
2
1
  const DEFAULT_TRUSTED_CHAIN_TIMEOUT_MS = 600_000;
3
2
  const TRUSTED_CHAIN_CLIENT_GRACE_MS = 5_000;
4
3
  const DEFAULT_WIRE_SYNC_TIMEOUT_MS = DEFAULT_TRUSTED_CHAIN_TIMEOUT_MS + TRUSTED_CHAIN_CLIENT_GRACE_MS;
5
4
  const DEFAULT_ACTION_QUOTE_TIMEOUT_MS = 30_000;
5
+ export class RegistrationError extends Error {
6
+ status;
7
+ constructor(status, message) {
8
+ super(`Registration failed (${status}): ${message}`);
9
+ this.status = status;
10
+ this.name = 'RegistrationError';
11
+ }
12
+ }
6
13
  function legacyActionRequestOptions(params) {
7
14
  if (params.mode === 'quote') {
8
15
  return { body: params, timeoutMs: DEFAULT_ACTION_QUOTE_TIMEOUT_MS };
@@ -13,15 +20,32 @@ function legacyActionRequestOptions(params) {
13
20
  timeoutMs: timeoutMs + TRUSTED_CHAIN_CLIENT_GRACE_MS,
14
21
  };
15
22
  }
23
+ function meshQuery(params, extra = {}) {
24
+ const query = new URLSearchParams(extra);
25
+ if (params.scope)
26
+ query.set('scope', params.scope);
27
+ if (params.circle_id)
28
+ query.set('circle_id', params.circle_id);
29
+ return query.size ? `?${query}` : '';
30
+ }
16
31
  const DEFAULT_WAIT_TIMEOUT_SECONDS = 30;
17
- const MAX_WAIT_TIMEOUT_SECONDS = 1800;
32
+ // Raised from 1800 (30m): the SSE event stream is server-side UNCAPPED + 30s-keepalived, so a long
33
+ // client park is just a client-side deadline, not an infra limit. 86400 = 24h finite ceiling.
34
+ const MAX_WAIT_TIMEOUT_SECONDS = 86_400;
35
+ // Sentinel: timeout_seconds < 0 parks INDEFINITELY (until an event) — no client deadline, so the
36
+ // SSE + reconnect loop runs until a match arrives = ZERO re-arm cycles. The hair-trigger is
37
+ // preserved (SSE delivers instantly). 0 keeps its "immediate poll" meaning.
38
+ const INDEFINITE_WAIT_TIMEOUT_SECONDS = -1;
18
39
  const DEFAULT_WAIT_LIMIT = 50;
19
40
  const MAX_WAIT_LIMIT = 200;
20
41
  const WAIT_RECONNECT_DELAY_MS = 1_000;
21
- function normalizeWaitTimeoutSeconds(timeoutSeconds) {
42
+ export function normalizeWaitTimeoutSeconds(timeoutSeconds) {
22
43
  if (timeoutSeconds === undefined)
23
44
  return DEFAULT_WAIT_TIMEOUT_SECONDS;
24
- return Math.min(Math.max(Math.floor(timeoutSeconds), 0), MAX_WAIT_TIMEOUT_SECONDS);
45
+ const floored = Math.floor(timeoutSeconds);
46
+ if (floored < 0)
47
+ return INDEFINITE_WAIT_TIMEOUT_SECONDS;
48
+ return Math.min(floored, MAX_WAIT_TIMEOUT_SECONDS);
25
49
  }
26
50
  function normalizeWaitLimit(limit) {
27
51
  if (limit === undefined)
@@ -60,7 +84,7 @@ function appendWaitParams(url, params) {
60
84
  url.searchParams.set(key, String(value));
61
85
  }
62
86
  }
63
- function normalizeHelpTopic(topic) {
87
+ export function normalizeHelpTopic(topic) {
64
88
  return (topic || '')
65
89
  .trim()
66
90
  .replace(/^https?:\/\/[^/]+\/api\/v1\/help\/?/i, '')
@@ -88,7 +112,7 @@ function isLocalRouteServedStatus(status) {
88
112
  return status === 200 || status === 401 || status === 403 || status === 404;
89
113
  }
90
114
  function isLocalReadFallbackStatus(status) {
91
- return status === 404 || status === 409 || status === 410 || status === 412 || status === 428 || status === 503 || status === 504;
115
+ return status === 401 || status === 403 || status === 404 || status === 409 || status === 410 || status === 412 || status === 428 || status === 503 || status === 504;
92
116
  }
93
117
  function parseSseBlock(block) {
94
118
  let event = 'message';
@@ -122,6 +146,13 @@ function parseSseBlock(block) {
122
146
  }
123
147
  }
124
148
  export class WireAPI {
149
+ async claims(params) {
150
+ const { action, claim_id } = params;
151
+ if (action === 'get' || action === 'list') {
152
+ return this.request('GET', '/wire/claims' + (claim_id ? `?claim_id=${encodeURIComponent(String(claim_id))}` : ''));
153
+ }
154
+ return this.request('POST', '/wire/claims', params, 120_000);
155
+ }
125
156
  baseUrl;
126
157
  token;
127
158
  nodeId;
@@ -213,7 +244,7 @@ export class WireAPI {
213
244
  return response;
214
245
  }
215
246
  async getMe() {
216
- return this.request('GET', '/me');
247
+ return this.unwrapEnvelopeOrPlain(await this.request('GET', '/me'));
217
248
  }
218
249
  async registerNode(name, capabilities) {
219
250
  return this.request('POST', '/node/register', { name, capabilities });
@@ -233,7 +264,7 @@ export class WireAPI {
233
264
  });
234
265
  if (!res.ok) {
235
266
  const err = await res.json().catch(() => ({ error: res.statusText }));
236
- throw new Error(`Registration failed (${res.status}): ${err.error || res.statusText}`);
267
+ throw new RegistrationError(res.status, err.error || res.statusText);
237
268
  }
238
269
  // Server wraps response in wireEnvelope: { data: { ... }, mesh, fleet, ... }
239
270
  const envelope = await res.json();
@@ -254,21 +285,10 @@ export class WireAPI {
254
285
  }
255
286
  async query(params) {
256
287
  const qs = new URLSearchParams();
257
- qs.set('text', params.text);
258
- qs.set('domain', params.domain || 'all');
259
- if (params.limit !== undefined)
260
- qs.set('limit', String(params.limit));
261
- if (params.offset !== undefined)
262
- qs.set('offset', String(params.offset));
263
- qs.set('sort', params.sort || 'recency');
264
- if (params.watchlist)
265
- qs.set('watchlist', 'true');
266
- if (params.list)
267
- qs.set('list', params.list);
268
- if (params.changed_only)
269
- qs.set('changed_only', 'true');
270
- if (params.price_below !== undefined)
271
- qs.set('price_below', String(params.price_below));
288
+ for (const [key, value] of Object.entries({ domain: 'all', sort: 'recency', ...params })) {
289
+ if (value !== undefined && value !== null)
290
+ qs.set(key, String(value));
291
+ }
272
292
  return this.request('GET', `/wire/query?${qs.toString()}`);
273
293
  }
274
294
  async help(params = {}) {
@@ -397,7 +417,7 @@ export class WireAPI {
397
417
  async verifyLocalContributionReadRoute() {
398
418
  if (!this.localNodeEnabled)
399
419
  return 'unavailable';
400
- if (!this.localNodeToken)
420
+ if (!this.localAuthToken())
401
421
  return 'unavailable';
402
422
  if (this.localContributionRouteStatus)
403
423
  return this.localContributionRouteStatus;
@@ -425,7 +445,7 @@ export class WireAPI {
425
445
  }
426
446
  localHeaders() {
427
447
  const headers = {
428
- 'Authorization': `Bearer ${this.localNodeToken}`,
448
+ 'Authorization': `Bearer ${this.localAuthToken()}`,
429
449
  'Content-Type': 'application/json',
430
450
  };
431
451
  if (this.threadId) {
@@ -433,6 +453,9 @@ export class WireAPI {
433
453
  }
434
454
  return headers;
435
455
  }
456
+ localAuthToken() {
457
+ return this.localNodeToken || this.token || '';
458
+ }
436
459
  async tryLocalContributionRead(identifier) {
437
460
  if (!this.localNodeEnabled)
438
461
  return null;
@@ -464,6 +487,55 @@ export class WireAPI {
464
487
  return null;
465
488
  }
466
489
  }
490
+ // ── Pyramid consume-head proxies (spec green playful/176/24) ───────────
491
+ // Thin HTTP proxies to the LOCAL AWN node's read-time pyramid routes
492
+ // (pyramid_routes mounted at /pyramid/*). They forward (slug, args) to the
493
+ // route and return the parsed JSON as-is. Auth: pass the local Bearer token
494
+ // (this.localHeaders()); the AWN routes enforce dual-auth + access-tier +
495
+ // nano-payment. Same local-node fetch pattern as tryLocalContributionRead.
496
+ /**
497
+ * Generic local-node fetch for the pyramid consume-head proxies. Returns the
498
+ * parsed JSON body on success, throws a descriptive error on non-2xx.
499
+ */
500
+ async localNodeFetch(method, path, body, timeoutMs = 15_000) {
501
+ const res = await fetch(`${this.localNodeUrl}${path}`, {
502
+ method,
503
+ headers: this.localHeaders(),
504
+ body: body !== undefined ? JSON.stringify(body) : undefined,
505
+ signal: AbortSignal.timeout(timeoutMs),
506
+ });
507
+ if (!res.ok) {
508
+ const err = await res.json().catch(() => ({ error: res.statusText }));
509
+ const message = err.error || res.statusText;
510
+ throw new Error(`Local node ${method} ${path} failed (${res.status}): ${message}`);
511
+ }
512
+ return await res.json();
513
+ }
514
+ /**
515
+ * pyramid_map — GET /pyramid/{slug}/map.
516
+ * Apex synthesis + freshness counts + nav skeleton + unresolved gaps.
517
+ * Orient first at boot, then drill via pyramid_hydrate using nav node ids.
518
+ */
519
+ async getPyramidMap(slug) {
520
+ return this.localNodeFetch('GET', `/pyramid/${encodeURIComponent(slug)}/map`);
521
+ }
522
+ /**
523
+ * pyramid_hydrate — GET /pyramid/{slug}/drill/{node_id}.
524
+ * Returns the DrillResult: full node content (headline/distilled/narrative
525
+ * via the node payload) plus children, evidence, gaps, web_edges, and
526
+ * question context. Pull one node/region after orienting via pyramid_map.
527
+ */
528
+ async getPyramidDrill(slug, nodeId) {
529
+ return this.localNodeFetch('GET', `/pyramid/${encodeURIComponent(slug)}/drill/${encodeURIComponent(nodeId)}`);
530
+ }
531
+ /**
532
+ * pyramid_ask — POST /pyramid/{slug}/question body { question }.
533
+ * Cheap (<5s, no-LLM) mechanical retrieval over the existing pyramid;
534
+ * returns a markdown answer plus node-id citations / sources.
535
+ */
536
+ async askPyramid(slug, question) {
537
+ return this.localNodeFetch('POST', `/pyramid/${encodeURIComponent(slug)}/question`, { question });
538
+ }
467
539
  /**
468
540
  * Rate a Wire item. Free. Must have accessed it first.
469
541
  */
@@ -511,7 +583,8 @@ export class WireAPI {
511
583
  * Read a source document by ID.
512
584
  */
513
585
  async readDocument(documentId) {
514
- return this.request('GET', `/wire/documents/${documentId}?include_body=true`, undefined, 30_000);
586
+ const quote = await this.request('GET', `/wire/documents/${documentId}`, undefined, 30_000);
587
+ return this.request('POST', `/wire/documents/${quote.id ?? quote.data?.id ?? documentId}`, { max_price: quote.current_price ?? quote.data?.current_price ?? 0 }, 30_000);
515
588
  }
516
589
  /**
517
590
  * Find unscouted documents — unclaimed bounties.
@@ -554,7 +627,7 @@ export class WireAPI {
554
627
  return paginateAll(async (page, pageSize) => {
555
628
  const offset = (page - 1) * pageSize;
556
629
  const result = await this.request('GET', `/wire/corpora/${encodeURIComponent(slug)}/documents?limit=${pageSize}&offset=${offset}`);
557
- return result.documents || [];
630
+ return result.documents || result.items || [];
558
631
  }, 100);
559
632
  }
560
633
  /**
@@ -584,44 +657,44 @@ export class WireAPI {
584
657
  /**
585
658
  * Get full mesh status: active threads, intents, blackboard.
586
659
  */
587
- async meshStatus() {
588
- return this.request('GET', '/mesh/status');
660
+ async meshStatus(scope = {}) {
661
+ return this.request('GET', `/mesh/status${meshQuery(scope)}`);
589
662
  }
590
663
  /**
591
664
  * Read the shared blackboard.
592
665
  */
593
- async meshBoardRead() {
594
- return this.request('GET', '/mesh/board');
666
+ async meshBoardRead(scope = {}) {
667
+ return this.request('GET', `/mesh/board${meshQuery(scope)}`);
595
668
  }
596
669
  /**
597
670
  * Write a key-value entry to the shared blackboard.
598
671
  */
599
- async meshBoardWrite(key, value, ttl) {
600
- return this.request('POST', '/mesh/board', { key, value, ttl });
672
+ async meshBoardWrite(key, value, ttl, scope = {}) {
673
+ return this.request('POST', '/mesh/board', { key, value, ttl, ...scope });
601
674
  }
602
675
  /**
603
676
  * Delete a key from the shared blackboard.
604
677
  */
605
- async meshBoardDelete(key) {
606
- return this.request('DELETE', `/mesh/board?key=${encodeURIComponent(key)}`);
678
+ async meshBoardDelete(key, scope = {}) {
679
+ return this.request('DELETE', `/mesh/board${meshQuery(scope, { key })}`);
607
680
  }
608
681
  /**
609
682
  * Declare an intent (what this thread is about to do).
610
683
  */
611
- async meshDeclareIntent(action, domain, meta, ttl) {
612
- return this.request('POST', '/mesh/intent', { action, domain, meta, ttl });
684
+ async meshDeclareIntent(action, domain, meta, ttl, scope = {}) {
685
+ return this.request('POST', '/mesh/intent', { action, domain, meta, ttl, ...scope });
613
686
  }
614
687
  /**
615
688
  * Release (delete) an intent.
616
689
  */
617
- async meshReleaseIntent(intentId) {
618
- return this.request('DELETE', `/mesh/intent?intent_id=${encodeURIComponent(intentId)}`);
690
+ async meshReleaseIntent(intentId, scope = {}) {
691
+ return this.request('DELETE', `/mesh/intent${meshQuery(scope, { intent_id: intentId })}`);
619
692
  }
620
693
  /**
621
694
  * Get active intents for this agent.
622
695
  */
623
- async meshGetIntents() {
624
- return this.request('GET', '/mesh/intent');
696
+ async meshGetIntents(scope = {}) {
697
+ return this.request('GET', `/mesh/intent${meshQuery(scope)}`);
625
698
  }
626
699
  // ── Prediction Markets ─────────────────────────────────────
627
700
  /**
@@ -633,8 +706,8 @@ export class WireAPI {
633
706
  * @param side - 'agree' or 'disagree'
634
707
  * @param amount - Number of credits to stake (must be >= market's min_stake)
635
708
  */
636
- async stakeMarket(contributionId, side, amount) {
637
- return this.request('POST', `/wire/market/${contributionId}/stake`, { side, amount });
709
+ async stakeMarket(contributionId, side, amount, requestId = crypto.randomUUID()) {
710
+ return this.request('POST', `/wire/market/${contributionId}/stake`, { side, amount, request_id: requestId });
638
711
  }
639
712
  /**
640
713
  * Get the current status of a prediction market, including pool sizes,
@@ -858,11 +931,14 @@ export class WireAPI {
858
931
  if (timeoutSeconds === 0) {
859
932
  return this.requestUnwrap('POST', '/wire/wait', params, 15_000);
860
933
  }
934
+ // timeoutSeconds < 0 ⇒ park INDEFINITELY: no deadline timer, so the SSE + reconnect loop runs
935
+ // until a matching event arrives (or the process aborts). Zero re-arm cycles.
936
+ const indefinite = timeoutSeconds < 0;
861
937
  const limit = normalizeWaitLimit(params.limit);
862
938
  const events = [];
863
939
  let nextCursor = params.cursor;
864
940
  const controller = new AbortController();
865
- const deadlineTimer = setTimeout(() => controller.abort(), timeoutSeconds * 1000);
941
+ const deadlineTimer = indefinite ? null : setTimeout(() => controller.abort(), timeoutSeconds * 1000);
866
942
  try {
867
943
  while (!controller.signal.aborted) {
868
944
  try {
@@ -905,7 +981,8 @@ export class WireAPI {
905
981
  }
906
982
  }
907
983
  finally {
908
- clearTimeout(deadlineTimer);
984
+ if (deadlineTimer)
985
+ clearTimeout(deadlineTimer);
909
986
  controller.abort();
910
987
  }
911
988
  return {
@@ -992,13 +1069,21 @@ export class WireAPI {
992
1069
  async rejectSupersession(proposalId) {
993
1070
  return this.request('POST', `/wire/contributions/${encodeURIComponent(proposalId)}/reject-supersession`);
994
1071
  }
995
- async executeSupersession(targetId, newContributionId) {
996
- return this.request('POST', `/wire/contributions/${encodeURIComponent(targetId)}/supersede`, { new_contribution_id: newContributionId });
1072
+ async executeSupersession(targetId, newContributionId, allowTypeChange) {
1073
+ // allow_type_change forwards to the REST endpoint (which already honors it) so a CROSS-TYPE
1074
+ // supersession is reachable via the CLI/MCP, not only via raw REST (WI playful/170/177).
1075
+ const body = { new_contribution_id: newContributionId };
1076
+ if (allowTypeChange)
1077
+ body.allow_type_change = true;
1078
+ return this.request('POST', `/wire/contributions/${encodeURIComponent(targetId)}/supersede`, body);
997
1079
  }
998
1080
  // ── Corrections ───────────────────────────────────────────
999
1081
  async submitCorrection(targetId, correctionContributionId, depositAmount) {
1000
1082
  return this.request('POST', `/wire/contributions/${encodeURIComponent(targetId)}/correct`, { correction_contribution_id: correctionContributionId, deposit_amount: depositAmount });
1001
1083
  }
1084
+ async withdrawCorrection(correctionId) {
1085
+ return this.request('DELETE', `/wire/contributions/${encodeURIComponent(correctionId)}/endorse-correction`);
1086
+ }
1002
1087
  async endorseCorrection(correctionId, depositAmount) {
1003
1088
  return this.request('POST', `/wire/contributions/${encodeURIComponent(correctionId)}/endorse-correction`, { deposit_amount: depositAmount });
1004
1089
  }
@@ -1292,4 +1377,30 @@ export class WireAPI {
1292
1377
  return json.data || json;
1293
1378
  }
1294
1379
  }
1380
+ /**
1381
+ * Paginate through all results from a fetch function.
1382
+ * Concatenates pages until a page returns fewer than pageSize items.
1383
+ *
1384
+ * @param fetchPage - Function that fetches a page (1-indexed page number, pageSize)
1385
+ * @param pageSize - Number of items per page (default 100)
1386
+ * @returns All items concatenated
1387
+ */
1388
+ export async function paginateAll(fetchPage, pageSize = 100) {
1389
+ const allItems = [];
1390
+ let page = 1;
1391
+ const MAX_PAGES = 500; // 500 pages * 100 per page = 50k docs max
1392
+ while (true) {
1393
+ if (page > MAX_PAGES) {
1394
+ console.error(`[wire-sync] Pagination stopped at ${MAX_PAGES} pages (${allItems.length} items). If your corpus has more documents, contact support.`);
1395
+ break;
1396
+ }
1397
+ const items = await fetchPage(page, pageSize);
1398
+ allItems.push(...items);
1399
+ if (items.length < pageSize) {
1400
+ break;
1401
+ }
1402
+ page++;
1403
+ }
1404
+ return allItems;
1405
+ }
1295
1406
  //# sourceMappingURL=api.js.map