@pulseai/sdk 0.1.2 → 0.1.4

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.d.ts CHANGED
@@ -16,7 +16,7 @@ declare const TESTNET_ADDRESSES: PulseAddresses;
16
16
  /** Full Pulse contract addresses on MegaETH Mainnet. */
17
17
  declare const MAINNET_ADDRESSES: PulseAddresses;
18
18
  /** Platform buyer agent ID on MegaETH Mainnet (owned by BuyerRelay). */
19
- declare const PLATFORM_BUYER_AGENT_ID = 8154n;
19
+ declare const PLATFORM_BUYER_AGENT_ID = 8155n;
20
20
  /** Default indexer URLs by network. */
21
21
  declare const DEFAULT_INDEXER_URLS: {
22
22
  readonly testnet: "https://pulse-indexer.up.railway.app";
@@ -95,6 +95,7 @@ type JobOffering = {
95
95
  serviceType: ServiceType;
96
96
  priceUSDm: bigint;
97
97
  slaMinutes: number;
98
+ name: string;
98
99
  description: string;
99
100
  requirementsSchemaURI: string;
100
101
  active: boolean;
@@ -138,6 +139,7 @@ type ListOfferingParams = {
138
139
  serviceType: ServiceType;
139
140
  priceUSDm: bigint;
140
141
  slaMinutes: number;
142
+ name: string;
141
143
  description: string;
142
144
  requirementsSchemaURI?: string;
143
145
  };
@@ -147,7 +149,9 @@ declare function listOffering(client: PulseClient, params: ListOfferingParams):
147
149
  txHash: Hash;
148
150
  }>;
149
151
  /** Update mutable fields of an offering. */
150
- declare function updateOffering(client: PulseClient, offeringId: bigint, priceUSDm: bigint, slaMinutes: number, description: string): Promise<Hash>;
152
+ declare function updateOffering(client: PulseClient, offeringId: bigint, priceUSDm: bigint, slaMinutes: number, name: string, description: string): Promise<Hash>;
153
+ /** Update the requirements schema URI of an offering. */
154
+ declare function updateOfferingSchema(client: PulseClient, offeringId: bigint, requirementsSchemaURI: string): Promise<Hash>;
151
155
  /** Deactivate an offering. */
152
156
  declare function deactivateOffering(client: PulseClient, offeringId: bigint): Promise<Hash>;
153
157
  /** Activate a previously deactivated offering. */
@@ -163,8 +167,8 @@ type CreateJobParams = {
163
167
  warrenTermsHash: Hex;
164
168
  };
165
169
  /**
166
- * Create a job: approve USDm + call createJob.
167
- * Reads the offering price automatically.
170
+ * Create a job: approve USDm (if needed) + call createJob.
171
+ * Reads the offering price automatically and skips approve if allowance is sufficient.
168
172
  */
169
173
  declare function createJob(client: PulseClient, params: CreateJobParams): Promise<{
170
174
  jobId: bigint;
@@ -223,15 +227,15 @@ declare function deployJobTerms(client: PulseClient, agentId: bigint, params: Jo
223
227
  hash: Hex;
224
228
  txHash: Hash;
225
229
  }>;
226
- /** Deploy deliverable to WARREN + submit on-chain + register with indexer. */
227
- declare function deployDeliverable(client: PulseClient, agentId: bigint, jobId: bigint, params: DeliverableParams, indexerUrl?: string): Promise<{
228
- masterAddress: Address;
229
- pageAddress: Address;
230
+ /** Submit deliverable hash on-chain and store content in indexer.
231
+ * Previously deployed to SSTORE2 (WARREN) but removed to save provider gas costs.
232
+ * Integrity is guaranteed by on-chain deliverableHash in JobEngine. */
233
+ declare function deployDeliverable(client: PulseClient, jobId: bigint, params: DeliverableParams, indexerUrl?: string): Promise<{
230
234
  hash: Hex;
231
235
  txHash: Hash;
232
236
  }>;
233
- /** Read deliverable from WARREN via indexer lookup. */
234
- declare function readDeliverable(client: PulseClient, jobId: bigint, indexerUrl: string): Promise<DeliverableData>;
237
+ /** Read deliverable from indexer and verify content hash. */
238
+ declare function readDeliverable(jobId: bigint, indexerUrl: string): Promise<DeliverableData>;
235
239
  /** Deploy requirements to WARREN + register with indexer (link_type='requirements'). */
236
240
  declare function deployRequirements(client: PulseClient, agentId: bigint, jobId: bigint, params: RequirementsParams, indexerUrl?: string): Promise<{
237
241
  masterAddress: Address;
@@ -321,6 +325,32 @@ declare function createRequirements(params: RequirementsParams): {
321
325
  hash: Hex;
322
326
  };
323
327
 
328
+ type JsonSchema = {
329
+ type: 'object';
330
+ properties: Record<string, {
331
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
332
+ description?: string;
333
+ enum?: unknown[];
334
+ items?: {
335
+ type: string;
336
+ };
337
+ }>;
338
+ required?: string[];
339
+ };
340
+ /** Pulse offering schema document (JSON Schema-based). */
341
+ type OfferingSchema = {
342
+ version: number;
343
+ serviceRequirements: JsonSchema;
344
+ deliverableRequirements: JsonSchema;
345
+ };
346
+ /** Default schemas by service type (Custom/5 intentionally omitted). */
347
+ declare const DEFAULT_SCHEMAS: Record<number, OfferingSchema>;
348
+ /** Validate runtime data against a compact JSON Schema object definition. */
349
+ declare function validateAgainstSchema(data: Record<string, unknown> | undefined, schema: JsonSchema): {
350
+ valid: boolean;
351
+ reason?: string;
352
+ };
353
+
324
354
  type JobContext = {
325
355
  jobId: bigint;
326
356
  offeringId: bigint;
@@ -336,6 +366,11 @@ type ExecuteJobResult = {
336
366
  content?: string;
337
367
  url?: string;
338
368
  mimeType?: string;
369
+ usage?: {
370
+ provider: string;
371
+ inputTokens: number;
372
+ outputTokens: number;
373
+ };
339
374
  };
340
375
  type ValidationResult = {
341
376
  valid: boolean;
@@ -344,6 +379,7 @@ type ValidationResult = {
344
379
  interface OfferingHandler {
345
380
  offeringId: number;
346
381
  autoAccept?: boolean;
382
+ schema?: OfferingSchema;
347
383
  validateRequirements?(context: JobContext): Promise<ValidationResult>;
348
384
  executeJob(context: JobContext): Promise<ExecuteJobResult>;
349
385
  }
@@ -360,6 +396,7 @@ type SiteModifierConfig = {
360
396
  declare class SiteModifierHandler implements OfferingHandler {
361
397
  readonly offeringId: number;
362
398
  readonly autoAccept?: boolean;
399
+ readonly schema: OfferingSchema;
363
400
  private readonly config;
364
401
  constructor(offeringId: number, config: SiteModifierConfig, options?: {
365
402
  autoAccept?: boolean;
@@ -370,6 +407,24 @@ declare class SiteModifierHandler implements OfferingHandler {
370
407
  private fetchHtmlWithTimeout;
371
408
  }
372
409
 
410
+ type PromptHandlerConfig = {
411
+ systemPrompt: string;
412
+ aiProvider: 'anthropic' | 'google' | 'openai';
413
+ aiModel?: string;
414
+ maxTokens?: number;
415
+ getApiKey: (provider: string) => Promise<string | null>;
416
+ };
417
+ declare class PromptHandler implements OfferingHandler {
418
+ readonly offeringId: number;
419
+ readonly autoAccept = true;
420
+ readonly schema: OfferingSchema;
421
+ private readonly config;
422
+ constructor(offeringId: number, config: PromptHandlerConfig);
423
+ validateRequirements(context: JobContext): Promise<ValidationResult>;
424
+ executeJob(context: JobContext): Promise<ExecuteJobResult>;
425
+ private parseRequirements;
426
+ }
427
+
373
428
  /**
374
429
  * EIP-712 type definition matching MemoLib.sol MEMO_TYPEHASH:
375
430
  * "Memo(uint256 jobId,address signer,bytes32 contentHash,uint64 timestamp,uint256 nonce)"
@@ -423,18 +478,12 @@ declare function parseUsdm(value: string): bigint;
423
478
  declare function formatUsdm(amount: bigint): string;
424
479
 
425
480
  declare const megaethTestnet: {
426
- blockExplorers?: {
427
- [key: string]: {
428
- name: string;
429
- url: string;
430
- apiUrl?: string | undefined;
431
- };
432
- default: {
433
- name: string;
434
- url: string;
435
- apiUrl?: string | undefined;
481
+ blockExplorers: {
482
+ readonly default: {
483
+ readonly name: "Blockscout";
484
+ readonly url: "https://megaeth-testnet-v2.blockscout.com";
436
485
  };
437
- } | undefined | undefined;
486
+ };
438
487
  blockTime?: number | undefined | undefined;
439
488
  contracts?: {
440
489
  [x: string]: viem.ChainContract | {
@@ -476,18 +525,12 @@ declare const megaethTestnet: {
476
525
  verifyHash?: ((client: viem.Client, parameters: viem.VerifyHashActionParameters) => Promise<viem.VerifyHashActionReturnType>) | undefined;
477
526
  };
478
527
  declare const megaethMainnet: {
479
- blockExplorers?: {
480
- [key: string]: {
481
- name: string;
482
- url: string;
483
- apiUrl?: string | undefined;
484
- };
485
- default: {
486
- name: string;
487
- url: string;
488
- apiUrl?: string | undefined;
528
+ blockExplorers: {
529
+ readonly default: {
530
+ readonly name: "Blockscout";
531
+ readonly url: "https://megaeth.blockscout.com";
489
532
  };
490
- } | undefined | undefined;
533
+ };
491
534
  blockTime?: number | undefined | undefined;
492
535
  contracts?: {
493
536
  [x: string]: viem.ChainContract | {
@@ -542,10 +585,15 @@ type CallAIParams = {
542
585
  maxTokens?: number;
543
586
  signal?: AbortSignal;
544
587
  };
588
+ type AIUsage = {
589
+ inputTokens: number;
590
+ outputTokens: number;
591
+ };
545
592
  type CallAIResult = {
546
593
  content: string;
547
594
  truncated: boolean;
548
595
  raw: unknown;
596
+ usage?: AIUsage;
549
597
  };
550
598
  type AICallOptions = CallAIParams;
551
599
  type AICallResult = CallAIResult;
@@ -588,6 +636,7 @@ interface IndexerOffering {
588
636
  priceUsdm: string;
589
637
  slaMinutes: number | null;
590
638
  description: string | null;
639
+ requirementsSchemaUri?: string;
591
640
  active: boolean;
592
641
  blockNumber: number | null;
593
642
  txHash: string | null;
@@ -720,6 +769,7 @@ declare class HandlerProviderRuntime {
720
769
  private running;
721
770
  private processedJobs;
722
771
  private failedJobs;
772
+ private schemaCache;
723
773
  private readonly maxRetries;
724
774
  private onError?;
725
775
  constructor(client: PulseClient, agentId: bigint, options: HandlerProviderRuntimeOptions);
@@ -734,6 +784,11 @@ declare class HandlerProviderRuntime {
734
784
  private canProcess;
735
785
  private markProcessed;
736
786
  private markFailed;
787
+ private validateSchemaRequirements;
788
+ private resolveOfferingSchemaFromUri;
789
+ private parseDataUriJson;
790
+ private isOfferingSchema;
791
+ private isJsonSchema;
737
792
  private getRemainingSlaMs;
738
793
  }
739
794
 
@@ -965,6 +1020,10 @@ declare const serviceMarketplaceAbi: readonly [{
965
1020
  readonly name: "slaMinutes";
966
1021
  readonly type: "uint32";
967
1022
  readonly internalType: "uint32";
1023
+ }, {
1024
+ readonly name: "name";
1025
+ readonly type: "string";
1026
+ readonly internalType: "string";
968
1027
  }, {
969
1028
  readonly name: "description";
970
1029
  readonly type: "string";
@@ -1019,6 +1078,10 @@ declare const serviceMarketplaceAbi: readonly [{
1019
1078
  readonly name: "slaMinutes";
1020
1079
  readonly type: "uint32";
1021
1080
  readonly internalType: "uint32";
1081
+ }, {
1082
+ readonly name: "name";
1083
+ readonly type: "string";
1084
+ readonly internalType: "string";
1022
1085
  }, {
1023
1086
  readonly name: "description";
1024
1087
  readonly type: "string";
@@ -1059,6 +1122,10 @@ declare const serviceMarketplaceAbi: readonly [{
1059
1122
  readonly name: "slaMinutes";
1060
1123
  readonly type: "uint32";
1061
1124
  readonly internalType: "uint32";
1125
+ }, {
1126
+ readonly name: "name";
1127
+ readonly type: "string";
1128
+ readonly internalType: "string";
1062
1129
  }, {
1063
1130
  readonly name: "description";
1064
1131
  readonly type: "string";
@@ -1066,6 +1133,20 @@ declare const serviceMarketplaceAbi: readonly [{
1066
1133
  }];
1067
1134
  readonly outputs: readonly [];
1068
1135
  readonly stateMutability: "nonpayable";
1136
+ }, {
1137
+ readonly type: "function";
1138
+ readonly name: "updateOfferingSchema";
1139
+ readonly inputs: readonly [{
1140
+ readonly name: "offeringId";
1141
+ readonly type: "uint256";
1142
+ readonly internalType: "uint256";
1143
+ }, {
1144
+ readonly name: "requirementsSchemaURI";
1145
+ readonly type: "string";
1146
+ readonly internalType: "string";
1147
+ }];
1148
+ readonly outputs: readonly [];
1149
+ readonly stateMutability: "nonpayable";
1069
1150
  }, {
1070
1151
  readonly type: "event";
1071
1152
  readonly name: "OfferingActivated";
@@ -1111,6 +1192,21 @@ declare const serviceMarketplaceAbi: readonly [{
1111
1192
  readonly internalType: "uint256";
1112
1193
  }];
1113
1194
  readonly anonymous: false;
1195
+ }, {
1196
+ readonly type: "event";
1197
+ readonly name: "OfferingSchemaUpdated";
1198
+ readonly inputs: readonly [{
1199
+ readonly name: "offeringId";
1200
+ readonly type: "uint256";
1201
+ readonly indexed: true;
1202
+ readonly internalType: "uint256";
1203
+ }, {
1204
+ readonly name: "requirementsSchemaURI";
1205
+ readonly type: "string";
1206
+ readonly indexed: false;
1207
+ readonly internalType: "string";
1208
+ }];
1209
+ readonly anonymous: false;
1114
1210
  }, {
1115
1211
  readonly type: "event";
1116
1212
  readonly name: "OfferingUpdated";
@@ -1520,6 +1616,16 @@ declare const jobEngineAbi: readonly [{
1520
1616
  readonly internalType: "contract IServiceMarketplace";
1521
1617
  }];
1522
1618
  readonly stateMutability: "view";
1619
+ }, {
1620
+ readonly type: "function";
1621
+ readonly name: "setServiceMarketplace";
1622
+ readonly inputs: readonly [{
1623
+ readonly name: "newMarketplace";
1624
+ readonly type: "address";
1625
+ readonly internalType: "address";
1626
+ }];
1627
+ readonly outputs: readonly [];
1628
+ readonly stateMutability: "nonpayable";
1523
1629
  }, {
1524
1630
  readonly type: "function";
1525
1631
  readonly name: "settle";
@@ -1738,6 +1844,21 @@ declare const jobEngineAbi: readonly [{
1738
1844
  readonly internalType: "address";
1739
1845
  }];
1740
1846
  readonly anonymous: false;
1847
+ }, {
1848
+ readonly type: "event";
1849
+ readonly name: "ServiceMarketplaceUpdated";
1850
+ readonly inputs: readonly [{
1851
+ readonly name: "oldMarketplace";
1852
+ readonly type: "address";
1853
+ readonly indexed: true;
1854
+ readonly internalType: "address";
1855
+ }, {
1856
+ readonly name: "newMarketplace";
1857
+ readonly type: "address";
1858
+ readonly indexed: true;
1859
+ readonly internalType: "address";
1860
+ }];
1861
+ readonly anonymous: false;
1741
1862
  }, {
1742
1863
  readonly type: "event";
1743
1864
  readonly name: "Upgraded";
@@ -3629,4 +3750,4 @@ declare const masterAbi: readonly [{
3629
3750
  readonly anonymous: false;
3630
3751
  }];
3631
3752
 
3632
- export { ACCEPT_TIMEOUT, type AICallOptions, type AICallResult, type AIMessage, type AIProvider, type AgentCardParams, BPS_DENOMINATOR, type BuyerCallbacks, BuyerRuntime, type BuyerRuntimeOptions, type CreateJobParams, type CreatePresetPulseClientOptions, type CreatePulseClientOptions, DEFAULT_INDEXER_URLS, type DeliverableData, type DeliverableParams, EVALUATION_TIMEOUT, type ExecuteJobResult, FEE_BPS, HandlerProviderRuntime, type HandlerProviderRuntimeOptions, type IndexerAgent, IndexerClient, IndexerClientError, type IndexerClientOptions, type IndexerJob, type IndexerJobsFilter, type IndexerOffering, type IndexerOfferingsFilter, type IndexerWarrenLink, type IndexerWarrenLinks, type Job, type JobContext, type JobOffering, JobStatus, type JobTermsParams, type ListOfferingParams, MAINNET_ADDRESSES, MEMO_TYPES, type OfferingHandler, PLATFORM_BUYER_AGENT_ID, PULSE_DOMAIN, type PresetPulseClient, type ProviderCallbacks, ProviderRuntime, type ProviderRuntimeOptions, type PulseAddresses, type PulseAgentData, type PulseClient, RISK_POOL_BPS, type RequirementsData, type RequirementsParams, ServiceType, type SignMemoParams, type SiteModifierConfig, SiteModifierHandler, TESTNET_ADDRESSES, TREASURY_BPS, USDM_MAINNET, type ValidationResult, acceptJob, activateOffering, buyerRelayAbi, callAI, cancelJob, createAgentCard, createDeliverable, createJob, createJobTerms, createMainnetClient, createPulseClient, createRequirements, createTestnetClient, deactivateOffering, deployAgentCard, deployDeliverable, deployJobTerms, deployRequirements, deployWarrenMaster, deployWarrenPage, erc20Abi, erc8004IdentityAbi, erc8004ReputationAbi, evaluate, feeDistributorAbi, formatUsdm, getAgent, getJob, getJobCount, getOffering, getOfferingCount, initAgent, jobEngineAbi, listOffering, mainnetERC8004, masterAbi, megaethMainnet, megaethTestnet, pageAbi, parseUsdm, pulseExtensionAbi, readDeliverable, readRequirements, readWarrenMaster, readWarrenPage, registerAgent, rejectJob, resolveDispute, serviceMarketplaceAbi, setOperator, setWarrenContract, settle, signMemo, submitDeliverable, testnetERC8004, updateOffering, verifyContentHash };
3753
+ export { ACCEPT_TIMEOUT, type AICallOptions, type AICallResult, type AIMessage, type AIProvider, type AIUsage, type AgentCardParams, BPS_DENOMINATOR, type BuyerCallbacks, BuyerRuntime, type BuyerRuntimeOptions, type CreateJobParams, type CreatePresetPulseClientOptions, type CreatePulseClientOptions, DEFAULT_INDEXER_URLS, DEFAULT_SCHEMAS, type DeliverableData, type DeliverableParams, EVALUATION_TIMEOUT, type ExecuteJobResult, FEE_BPS, HandlerProviderRuntime, type HandlerProviderRuntimeOptions, type IndexerAgent, IndexerClient, IndexerClientError, type IndexerClientOptions, type IndexerJob, type IndexerJobsFilter, type IndexerOffering, type IndexerOfferingsFilter, type IndexerWarrenLink, type IndexerWarrenLinks, type Job, type JobContext, type JobOffering, JobStatus, type JobTermsParams, type JsonSchema, type ListOfferingParams, MAINNET_ADDRESSES, MEMO_TYPES, type OfferingHandler, type OfferingSchema, PLATFORM_BUYER_AGENT_ID, PULSE_DOMAIN, type PresetPulseClient, PromptHandler, type PromptHandlerConfig, type ProviderCallbacks, ProviderRuntime, type ProviderRuntimeOptions, type PulseAddresses, type PulseAgentData, type PulseClient, RISK_POOL_BPS, type RequirementsData, type RequirementsParams, ServiceType, type SignMemoParams, type SiteModifierConfig, SiteModifierHandler, TESTNET_ADDRESSES, TREASURY_BPS, USDM_MAINNET, type ValidationResult, acceptJob, activateOffering, buyerRelayAbi, callAI, cancelJob, createAgentCard, createDeliverable, createJob, createJobTerms, createMainnetClient, createPulseClient, createRequirements, createTestnetClient, deactivateOffering, deployAgentCard, deployDeliverable, deployJobTerms, deployRequirements, deployWarrenMaster, deployWarrenPage, erc20Abi, erc8004IdentityAbi, erc8004ReputationAbi, evaluate, feeDistributorAbi, formatUsdm, getAgent, getJob, getJobCount, getOffering, getOfferingCount, initAgent, jobEngineAbi, listOffering, mainnetERC8004, masterAbi, megaethMainnet, megaethTestnet, pageAbi, parseUsdm, pulseExtensionAbi, readDeliverable, readRequirements, readWarrenMaster, readWarrenPage, registerAgent, rejectJob, resolveDispute, serviceMarketplaceAbi, setOperator, setWarrenContract, settle, signMemo, submitDeliverable, testnetERC8004, updateOffering, updateOfferingSchema, validateAgainstSchema, verifyContentHash };