///
The Quicksilver SDK empowers developers to define complex economic interactions using a fluent Domain-Specific Language (DSL). This page details the core builder classes: `ConditionBuilder` for defini
31 views
~31 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
The Quicksilver SDK empowers developers to define complex economic interactions using a fluent Domain-Specific Language (DSL). This page details the core builder classes: ConditionBuilder for defining conditional logic, ProductBuilder for creating programmable products, and Action / ActionBuilder for specifying actions to be taken. These builders are accessed via the main QuicksilverClient API Reference.
ConditionBuilderThe ConditionBuilder class provides a fluent interface for constructing conditional logic that dictates when and how transactions should proceed.
constructor()Initializes a new ConditionBuilder instance.
when(trigger: QuickSilverEvent | ((ctx: any) => boolean), predicate?: (ctx: any) => boolean): thisDefines a trigger for a set of actions. Can be a predefined event or a custom predicate function.
trigger: QuickSilverEvent | ((ctx: any) => boolean) - A predefined QuickSilverEvent enum value (e.g., QuickSilverEvent.MilestoneApproved) or a custom JavaScript function that evaluates context.predicate: ((ctx: any) => boolean) - An optional refining predicate function that must also return true for the condition to be met.then(...actions: (Action | ActionClass | ActionBuilder)[]): thisDefines the action(s) to take when the preceding when condition is met.
actions: (Action | ActionClass | ActionBuilder)[] - One or more Action or ActionBuilder instances to execute.otherwise(...actions: (Action | ActionClass | ActionBuilder)[]): thisDefines a fallback action if no when conditions are met.
actions: (Action | ActionClass | ActionBuilder)[] - One or more Action or ActionBuilder instances to execute as a fallback.toJSON(): objectSerializes the entire conditional logic defined by the builder into a JSON object suitable for API transmission.
getConditions(): Condition[]Condition[] // Returns the raw array of conditions configured by the builder.
getOtherwiseActions(): Action[]Action[] // Returns the raw array of 'otherwise' actions configured by the builder.
ProductBuilderThe ProductBuilder class allows you to define programmable products and services with detailed pricing, guarantees, and multi-agent workflows.
constructor(id: string)Initializes a new ProductBuilder instance.
id: string - A unique identifier for the product.id: stringstring // The unique identifier of the product.
guarantees: anyany // An object containing key-value pairs of guarantees for the product.
stages: any[]any[] // An array of workflow stages defined for the product.
conditions: any[]any[] // An array of conditions associated with the product.
actions: any[]any[] // An array of actions associated with the product.
metadata?: Record<string, any>Record<string, any> // Optional metadata for the product.
charge(rate: number, unit: string, currency?: Currency): thisDefines a unit-based pricing model for the product.
rate: number - The numerical rate for the product.unit: string - The unit of charge (e.g., 'per_word', 'per_transaction', 'monthly').currency: Currency - The currency of the charge (defaults to 'USD').stream(rate: number, unit: 'per_second' | 'per_minute', currency?: Currency): thisDefines a streaming pricing model for the product.
rate: number - The numerical rate for the stream.unit: 'per_second' | 'per_minute' - The unit of streaming rate.currency: Currency - The currency of the stream (defaults to 'USD').guarantee(guarantees: { [key: string]: any }): thisAdds one or more service level guarantees to the product.
guarantees: { [key: string]: any } - An object containing key-value pairs defining the guarantees (e.g., { accuracy: 0.98, turnaround: '5 minutes' }).stage(name: string, config: { delegateTo: string, charge: number }): thisDefines a stage in a multi-agent workflow, specifying the delegated agent and its charge.
name: string - The name of the workflow stage.config: { delegateTo: string, charge: number } - Configuration for the stage, including the ID of the delegated agent and the charge for this stage.getPricing(): anyany // Retrieves the pricing information set for the product.
getGuarantees(): anyany // Retrieves the guarantees set for the product.
getWorkflow(): any[]any[] // Retrieves the workflow stages defined for the product.
to(accountId: string): thisSets the destination account for transactions involving this product.
accountId: string - The ID of the recipient account.from(accountId: string): thisSets the source account for transactions involving this product.
accountId: string - The ID of the sender account.currency(code: string): thisSets the currency for the product's pricing.
code: string - The currency code (e.g., 'USD', 'EUR').withConditions(conditionBuilder: any): thisAdds conditional logic to the product using a ConditionBuilder instance.
conditionBuilder: any - An instance of ConditionBuilder or an object containing condition definitions.withActions(...actionBuilders: any[]): thisAdds actions that should be performed in conjunction with the product.
actionBuilders: any[] - One or more Action or ActionBuilder instances.meta(metadata: Record<string, any>): thisAdds or merges metadata to the product definition.
metadata: Record<string, any> - An object containing metadata key-value pairs.toJSON(): objectSerializes the product definition into a JSON object suitable for API transmission.
ActionThe Action class defines individual actions that can be part of conditional logic. It includes static factory methods for common action types.
constructor(type: string, data?: Record<string, any>)Initializes a new Action instance.
type: string - The type of the action (e.g., 'release', 'notify', 'hold').data: Record<string, any> - Additional data relevant to the action.static release(amount: number, currency?: Currency): ActionBuilderActionBuilder // Creates a payment action to release a specified amount of funds.
amount: number - The amount to release.currency: Currency - The currency of the amount (defaults to 'USD').static notify(account: any, message: string): ActionAction // Creates a notification action to send a message to a specific account.
account: any - The target account for the notification (e.g., an account ID or object).message: string - The notification message.static hold(message: string): ActionAction // Creates a hold action to pause transaction execution with a specific message.
message: string - The message associated with the hold.static custom(type: string, data: Record<string, any>): ActionAction // Creates a custom action with an arbitrary type and data.
type: string - The custom action type.data: Record<string, any> - Custom data for the action.toJSON(): objectSerializes the action into a JSON object for API transmission.
ActionBuilderThe ActionBuilder extends the concept of Action to provide a fluent interface for constructing more complex actions, especially those that require additional parameters or metadata.
constructor(type: string, data?: Record<string, any>)Initializes a new ActionBuilder instance.
type: string - The type of the action.data: Record<string, any> - Initial data for the action.params?: Record<string, any>Record<string, any> // Optional parameters specifically for the action, distinct from general data.
with(params: Record<string, any>): thisAdds additional parameters to the action.
params: Record<string, any> - An object containing parameters to add.to(account: any): thisSpecifies the target account for actions like release or transfer.
account: any - The target account (e.g., an account ID or object).withMeta(meta: Record<string, any>): thisAdds metadata to the action.
meta: Record<string, any> - An object containing metadata key-value pairs.toJSON(): objectSerializes the action, including its parameters and data, into a JSON object for API transmission.