wowok_agent
Version:
Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.
599 lines • 101 kB
JavaScript
import { z } from "zod";
import { TokenTypeInfoSchema, QueryLocalMarkListResultSchema, QueryAccountListResultSchema, QueryLocalInfoListResultSchema, QueryLocalTokenListResultSchema, QueryAccountResultSchema } from "../local/index.js";
import { AccountOrMark_AddressSchema, BalanceTypeSchema, EntrypointSchema, GuardIdentifierSchema, GuardTableItemSchema, NameOrAddressSchema, ObjectBaseSchema, ObjectTypeSchema, QueryIdSchema, SupportedValueSchema, ValueTypeSchema, QueryReceivedResultSchema, LongNameSchema, DescriptionSchema } from "../common/index.js";
import { isValidPermissionIndex } from '../utils/permission-index-utils.js';
import { isValidGuardQueryId, isValidGuardQueryIdOrName } from '../utils/guard-query-utils.js';
import { isWitnessType, } from "wowok";
import { DiscountType as WDiscountType } from "wowok";
import { QueryEnvSchema } from "../common/index.js";
const MAX_MULTI_OPERANDS = 8;
const VALUE_TYPE_DESCRIPTION = "Value type: can be specified as a string name (e.g., 'U64', 'Address', 'String') or a number (0-18). Supported types: Bool=0/'Bool', Address=1/'Address', String=2/'String', U8=3/'U8', U16=4/'U16', U32=5/'U32', U64=6/'U64', U128=7/'U128', U256=8/'U256', VecBool=9/'VecBool', VecAddress=10/'VecAddress', VecString=11/'VecString', VecU8=12/'VecU8', VecU16=13/'VecU16', VecU32=14/'VecU32', VecU64=15/'VecU64', VecU128=16/'VecU128', VecU256=17/'VecU256', VecVecU8=18/'VecVecU8'. Note: Value=19 is an INTERNAL type for wowok system use only and should NOT be used directly by users. String format is recommended for better readability.";
export const AmountTypeSchema = z.enum(["GuardU64Identifier", "Fixed"]).describe("Amount type. GuardU64Identifier indicates the amount comes from U64 type data defined in Guard table (Identifier index), Fixed indicates using a fixed amount.");
export const GuardQuerySchema = z.object({
id: QueryIdSchema,
name: z.string().describe("Name of the query instruction."),
objectType: ObjectTypeSchema.describe("Type of the Object that the query instruction operates on."),
parameters: z.array(ValueTypeSchema).describe("List of parameter types for the query instruction."),
return: ValueTypeSchema.describe("Return value type of the query instruction."),
description: z.string().describe("Detailed description of the query instruction."),
parameters_description: z.array(z.string()).describe("Detailed descriptions of the query instruction parameters."),
});
export const GuardSubmissionSchema = z.object({
identifier: GuardIdentifierSchema.describe("Identifier"),
value_type: ValueTypeSchema.describe("Value type"),
value: SupportedValueSchema.describe("Value"),
}).describe("Guard submission");
export const RecipientSchema = z.union([
z.object({ GuardIdentifier: GuardIdentifierSchema }).describe("Guard verified recipient ID. Get recipient ID from specified data index in Guard table. The ID must be of address type."),
z.object({ Entity: AccountOrMark_AddressSchema }).describe("Determined ID"),
z.object({ Signer: z.literal("signer") }).describe("Current transaction signer ID"),
]).describe("Recipient ID");
export const RecordsInEntitySchema = z.object({
name: z.string().describe("Record name"),
value_type: ValueTypeSchema.describe("Value type"),
value: SupportedValueSchema.describe("Value"),
}).describe("Information record");
export const PermissionIndexTypeSchema = z.number().int().refine((value) => {
return isValidPermissionIndex(value);
}, {
message: "Permission index must be a valid BuiltinPermissionIndex value or user defined between 1000 and 65535"
}).describe("Permission index type");
export const VoteInEntityLinkerSchema = z.object({
address: z.string().describe("Account or object ID"),
like: z.boolean().optional().describe("Whether liked"),
dislike: z.boolean().optional().describe("Whether disliked"),
affiliation: z.boolean().optional().describe("Whether affiliated"),
time: z.number().describe("Time"),
}).describe("Follow record");
export const ObjectEntityRegistrarSchema = ObjectBaseSchema.extend({
entity_count: z.number().describe("Entity count. Number of entities registered in the entity registrar table. Use 'query_table' or 'query_table_item' to get 'EntityRegistrar' table items."),
}).describe("On-chain entity registrar");
export const ObjectEntityLinkerSchema = ObjectBaseSchema.extend({
entity_count: z.number().describe("Entity count. Number of entities registered in the entity linker table. Use 'query_table' or 'query_table_item' to get 'EntityLinker' table items."),
}).describe("On-chain entity linker");
export const ObjectResourceSchema = ObjectBaseSchema.extend({
entity_count: z.number().describe("Entity count. Number of entities registered in the address mark table. Use 'query_table' or 'query_table_item' to get 'AddressMark' table items."),
}).describe("On-chain address tag manager");
export const TableItem_EntityLinkerSchema = ObjectBaseSchema.extend({
address: z.string().describe("Followed ID"),
pos: z.number().describe("Current follow information position"),
count: z.number().describe("Follower count. Number of entities who have been followed others. Use 'query_table' or 'query_table_item' to get 'EntityLinker' table items."),
votes: z.array(VoteInEntityLinkerSchema).describe("Follow records"),
}).describe("On-chain followed object data");
export const TableItem_EntityRegistrarSchema = ObjectBaseSchema.extend({
address: z.string().describe("Entity ID"),
description: z.string().describe("Entity description"),
time: z.number().describe("On-chain registration time"),
referrer: z.union([z.string(), z.null()]).describe("Referrer"),
mark_object: z.union([z.string(), z.null()]).describe("Your on-chain address mark object by entity ID"),
records: z.array(RecordsInEntitySchema).describe("Information records"),
}).describe("On-chain entity data");
export const TableItem_AddressMarkSchema = ObjectBaseSchema.extend({
entity: z.string().describe("Entity ID"),
name: z.string().describe("Tag name"),
tags: z.array(z.string()).describe("Tag list"),
}).describe("On-chain ID mark data");
export const ServiceGuardSchema = z.object({
guard: z.string().describe("Service guard"),
service_identifier: z.union([GuardIdentifierSchema, z.null()]).optional().describe("Service identifier. Used to determine the service verified in Guard"),
}).describe("Service guard");
export const ObjectDemandSchema = ObjectBaseSchema.extend({
description: z.string().describe("Demand description"),
location: z.string().describe("Demand location"),
rewards: z.array(z.string()).describe("Reward list. Used to incentivize qualified Presenters to claim rewards"),
guards: z.array(ServiceGuardSchema).describe("Service Guard list"),
presenters_count: z.number().describe("Presenter count. Number of Presenters who have submitted their demand. Use 'query_table' or 'query_table_item' to get 'DemandPresenter' table items."),
um: z.union([z.string(), z.null()]).describe("Contact object"),
permission: z.string().describe("Permission"),
}).describe("Demand object");
export const ObjectMachineSchema = ObjectBaseSchema.extend({
description: z.string().describe("Machine description"),
node_count: z.number().describe("Node count. Nodes are used to determine each step and state of Machine operation. Use 'query_table' or 'query_table_item' to get 'MachineNode' table items."),
consensus_repositories: z.array(z.string()).describe("Consensus repository list. Used to determine consensus data storage during Machine operation."),
bPaused: z.boolean().describe("Whether paused"),
bPublished: z.boolean().describe("Whether published"),
um: z.union([z.string(), z.null()]).describe("Contact object"),
permission: z.string().describe("Permission object ID. Used to modify operation permission settings for Machine settings."),
}).describe("Machine object");
export const ServiceSaleSchema = z.object({
name: LongNameSchema.describe("Name of the product or service for sale"),
price: BalanceTypeSchema.describe("Price of the product or service"),
stock: BalanceTypeSchema.describe("Stock of the product or service"),
suspension: z.boolean().describe("Whether sale is suspended"),
wip: z.string().describe("HTTP URL of wip file"),
wip_hash: z.string().describe(`Hash of WIP. If EMPTY string, the hash within wip will be automatically used; else, the consistency of the hash within wip will be verified with the provided hash.`),
}).describe("Service sale");
export const PurchasedItemSchema = z.object({
name: LongNameSchema.describe("Name of the product or service"),
price: BalanceTypeSchema.describe("Service price"),
quantity: BalanceTypeSchema.describe("Service quantity"),
wip_hash: z.string().describe("WIP file hash of the item"),
});
export const ObjectOrderSchema = ObjectBaseSchema.extend({
items: z.array(PurchasedItemSchema).describe("Purchased service list"),
discount: z.union([z.string(), z.null()]).describe("Used discount object ID"),
progress: z.union([z.string(), z.null()]).describe("Order progress object ID"),
machine: z.union([z.string(), z.null()]).describe("Machine ID that progress belongs to"),
amount: BalanceTypeSchema.describe("Order amount"),
builder: z.string().describe("Purchaser ID"),
service: z.string().describe("Service ID"),
dispute: z.array(z.string()).describe("Dispute object ID list. When unsatisfied with order delivery, dispute objects can be created."),
agent: z.array(z.string()).describe("Agent ID list. Agents handle all order operations except payment collection."),
allocation: z.union([z.string(), z.null()]).describe("Order amount allocation object ID"),
claimed_by: z.union([z.string(), z.null()]).describe("Order dispute object ID that has claimed order arbitration amount."),
required_info: z.string().describe("Contact object ID (recipient) or WTS Proof object (delivery proof) that information has been delivered via Wowok Messenger."),
time: z.union([z.string(), z.number()]).describe("Order creation time"),
});
export const NamedOperatorSchema = z.object({
name: z.string().describe("Namespace name"),
operators: z.array(z.string()).describe("Operator ID list"),
}).describe("Namespace operator. Namespace is a permission identifier defined in Machine, allowing different Progress to bind different operators to exercise unified permission definitions.");
export const ProgressSessionHolderSchema = z.object({
forward: z.string().describe("An operation name"),
who: z.union([z.string(), z.null()]).describe("Operator ID"),
retained_submission: z.array(GuardSubmissionSchema).describe("Used to define submitted data after Guard verification"),
msg: z.string().describe("Information submitted to complete operation"),
accomplished: z.boolean().describe("Whether completed"),
time: z.number().describe("Session creation time"),
}).describe("An operation in Progress session");
export const ProgressSessionSchema = z.object({
next_node: z.string().describe("Next node ID"),
forwards: z.array(ProgressSessionHolderSchema).describe("Operation list in Progress session"),
weights: z.number().describe("Total operation weight"),
threshold: z.number().describe("Operation threshold. When total operation weight exceeds threshold, session is considered completed and Progress moves from current node to next node."),
}).describe("Progress session");
export const ObjectProgressSchema = ObjectBaseSchema.extend({
machine: z.string().describe("Machine ID that Progress object belongs to"),
context_repositories: z.array(z.string()).describe("Context repository list. Used to store context data during Progress operation."),
current: z.string().describe("Current node name"),
task: z.union([z.string(), z.null()]).describe("Target task ID executed by Progress (e.g., Order ID)"),
namedOperator: z.array(NamedOperatorSchema).describe("Namespace operator list. Each process can independently maintain operators for permissions represented by its namespace."),
session: z.array(ProgressSessionSchema).describe("Progress session list"),
history_count: z.number().describe("Number of historical sessions for completed nodes in Progress. Use 'query_table' or 'query_table_item' to get 'ProgressHistory' table items."),
current_time: z.number().describe("Current node entry timestamp"),
}).describe("Progress object");
export const AmountSchema = z.discriminatedUnion("type", [
z.object({
type: z.literal("GuardU64Identifier"),
value: GuardIdentifierSchema,
}).describe("Guard verified amount. Get amount value from specified data index in Guard table. The value type must be u64."),
z.object({
type: z.literal("Fixed"),
value: BalanceTypeSchema,
}).describe("Fixed amount"),
]).describe("Amount");
export const RewardGuardSchema = z.object({
guard: NameOrAddressSchema.describe("Guard object ID or name."),
recipient: RecipientSchema,
amount: AmountSchema.describe("Reward amount"),
expiration_time: z.number().optional().describe("Reward Guard expiration time. If set, the reward cannot be claimed by this guard after the expiration time. If not specified, Reward Guard is permanently valid."),
store_from_id: z.union([GuardIdentifierSchema, z.null()]).optional().describe("Guard table data index for record storage. The value at this index (address or number, including submitted values) will be stored in the record for Guard verification purposes, such as controlling operation frequency."),
}).describe("Reward Guard type");
export const ObjectRewardSchema = ObjectBaseSchema.extend({
description: z.string().describe("Reward object description"),
guards: z.array(RewardGuardSchema).describe("Reward Guard list. When one of the Guards is successfully verified in a transaction, the relevant recipient will receive the reward amount."),
balance: BalanceTypeSchema.describe("Current balance of reward object"),
guard_not_added_expiration_time: z.union([z.string(), z.number(), z.null()]).describe("Used to lock whether new Reward Guards can be added. If not specified, new Reward Guards can be added at any time; if expiration time is specified, new Reward Guards cannot be added before expiration."),
record_count: z.number().describe("Number of reward claimer records. Use 'query_table' or 'query_table_item' to get 'RewardRecord' table items."),
um: z.union([z.string(), z.null()]).describe("Contact object"),
permission: z.string().describe("Permission object ID"),
}).describe("Reward object");
export const AllocationModeSchema = z.enum(["Amount", "Rate", "Surplus"]).describe("Reward allocation mode. Amount indicates allocation by amount, Rate indicates allocation by proportion, Surplus indicates allocation by remaining amount. In a fund allocator, Amount will be allocated first, then remaining funds will be allocated by Rate (if no Surplus is defined, sum of all Rates must be 10000), and finally Surplus gets remaining amount (maximum one per fund allocator).");
export const AllocationSharingSchema = z.object({
who: RecipientSchema.describe("Recipient ID"),
sharing: BalanceTypeSchema.describe("Reward allocation value"),
mode: AllocationModeSchema.describe("Reward allocation mode"),
}).describe("Fund allocation item");
export const AllocatorSchema = z.object({
guard: NameOrAddressSchema.describe("Guard object ID. If Guard verification passes, fund allocation will start automatically."),
sharing: z.array(AllocationSharingSchema).describe("Fund allocation item list. Each item represents a recipient and their corresponding reward allocation value."),
fix: BalanceTypeSchema.optional().describe("Fixed allocation amount. If specified, all recipients will receive the fixed allocation amount."),
max: z.union([BalanceTypeSchema, z.null()]).optional().describe("Maximum allocation amount. If specified, allocation amount cannot exceed maximum allocation amount."),
}).describe("Fund allocator");
export const AllocatorsSchema = z.object({
description: DescriptionSchema.describe("Description of fund allocator list"),
threshold: BalanceTypeSchema.describe("Threshold. If defined, fund allocation will be triggered when amount in Allocation object reaches this threshold."),
allocators: z.array(AllocatorSchema).describe("Fund allocator list. Each fund allocator represents a fund allocation strategy."),
}).describe("Fund allocator list");
export const ObjectServiceSchema = ObjectBaseSchema.extend({
description: z.string().describe("Service object description"),
location: z.string().describe("Service object location"),
sales: z.array(ServiceSaleSchema).describe("Service sale list."),
repositories: z.array(z.string()).describe("Repository object list for service object's shared data"),
buy_guard: z.union([z.string(), z.null()]).describe("Purchase Guard object ID. If defined, service can only be purchased if Guard verification passes."),
machine: z.union([z.string(), z.null()]).describe("Machine object ID for each order's processing flow. The Machine must be in published state."),
bPublished: z.boolean().describe("Whether service is published. If service is published, customers can purchase it; and related settings like Machine, arbitrations, order_allocators will be immutable."),
bPaused: z.boolean().describe("Whether service purchase is paused"),
customer_required: z.array(z.string()).describe("Information required from customer. Such as phone, email, etc."),
arbitrations: z.array(z.string()).describe("List of Arbitration objects supported by service. When order user needs arbitration, they can apply for arbitration with any Arbitration object in the list."),
compensation_fund: BalanceTypeSchema.describe("Compensation fund pool for arbitration results. Order users can receive compensation from this fund based on arbitration results."),
paused_time: z.union([z.number(), z.null()]).describe("Service purchase pause time. If not paused, it is null."),
compensation_lock_duration: z.union([z.string(), z.number()]).describe("Lock duration for arbitration result compensation. After service is paused for longer than this duration, service manager can retrieve compensation_fund. Default is at least 30 days."),
order_allocators: z.union([AllocatorsSchema, z.null()]).describe("Order fund allocator list."),
rewards: z.array(z.string()).describe("Reward object list"),
um: z.union([z.string(), z.null()]).describe("Contact object"),
permission: z.string().describe("Permission object ID"),
}).describe("Service object");
export const ArbVotedSchema = z.object({
voter: z.string().describe("Voter ID"),
agrees: z.array(z.number().min(0).max(255)).describe("List of supported Proposition indices"),
weight: z.number().describe("Voting weight"),
time: z.number().describe("Voting time"),
}).describe("Voting record");
export const ArbPropositionSchema = z.object({
name: z.string().describe("Proposal name"),
votes: z.number().describe("Number of votes supporting this proposal"),
}).describe("Proposal");
export const ArbIndemnitySchema = z.object({
amount: BalanceTypeSchema.describe("Compensation amount"),
time: z.number().describe("Arbitration time"),
}).describe("Arbitration compensation");
export const ArbStatusSchema = z.enum([
"Principal_confirming",
"Arbitrator_confirming",
"Voting",
"Arbitrated",
"Objectionable",
"Finished",
"Withdrawn",
]).describe("Arb object status");
export const ObjectArbSchema = ObjectBaseSchema.extend({
description: z.string().describe("Arb object statement"),
arbitration: z.string().describe("Parent arbitration object ID"),
order: z.string().describe("Order object ID"),
voted: z.array(ArbVotedSchema).describe("Voting record list"),
proposition: z.array(ArbPropositionSchema).describe("Claim/proposal list"),
fee: BalanceTypeSchema.describe("Arbitration fee"),
feedback: z.string().describe("Arbitration feedback"),
indemnity: z.union([ArbIndemnitySchema, z.null()]).optional().describe("Arbitration compensation"),
voting_deadline: z.union([z.number(), z.string()]).optional().describe("Voting deadline"),
objection: z.string().describe("Arbitration objection"),
status: ArbStatusSchema,
compensation_time: z.union([z.number(), z.null()]).describe("Compensation claim time"),
time: z.number().describe("Arbitration time"),
}).describe("Arb object");
export const DiscountTypeSchema = z.union([
z.literal(WDiscountType.RATES).describe("Rate discount type"),
z.literal(WDiscountType.FIXED).describe("Fixed discount type")
]).describe("Discount type");
export const ObjectDiscountSchema = ObjectBaseSchema.extend({
name: z.string().describe("Discount name"),
discount_type: DiscountTypeSchema.describe("Discount type. If rate(0), discount is based on proportion of product amount (e.g., 1000 means 10% discount); if fixed(1), discount is based on fixed value of product amount (e.g., 100 means 100 yuan discount)."),
benchmark: z.union([BalanceTypeSchema, z.null()]).describe("Discount benchmark amount. If RATES, discount is based on proportion of this amount; if MINUS, discount is based on fixed value of this amount."),
off: BalanceTypeSchema.describe("Discount value. If RATES, discount is based on proportion of product amount (e.g., 1000 means 10% discount); if MINUS, discount is based on fixed value of product amount (e.g., 100 means maximum 100 yuan discount)."),
time_start: z.union([z.string(), z.number()]).describe("Discount effective start time"),
time_end: z.union([z.string(), z.number()]).describe("Discount effective end time"),
service: z.string().describe("Parent service object ID"),
transferable: z.boolean().describe("Whether discount is transferable to other users"),
}).describe("Discount object");
export const AmountFromDepositGuardSchema = z.object({
guard: z.string().describe("Guard object ID or name"),
identifier: z.union([GuardIdentifierSchema, z.null()]).optional().describe("Guard Table data index, whose corresponding value is the storable amount. If null, deposit amount is unlimited."),
store_from_id: z.union([GuardIdentifierSchema, z.null()]).optional().describe("Guard table data index for record storage. The value at this index (address or number, including submitted values) will be stored in the record for Guard verification purposes, such as controlling operation frequency."),
}).describe("Guard object that needs verification during deposit");
export const AmountFromWithdrawGuardSchema = z.object({
guard: z.string().describe("Guard object ID or name"),
identifier: z.number().describe("Guard Table data index, whose corresponding value is the withdrawable amount."),
store_from_id: z.union([GuardIdentifierSchema, z.null()]).optional().describe("Guard table data index for record storage. The value at this index (address or number, including submitted values) will be stored in the record for Guard verification purposes, such as controlling operation frequency."),
}).describe("Guard object that needs verification during withdrawal");
export const ObjectTreasurySchema = ObjectBaseSchema.extend({
description: z.string().describe("Treasury object description"),
balance: BalanceTypeSchema.describe("Current balance"),
history_count: z.number().describe("Transaction record count. Use 'query_table' or 'query_table_item' to get 'TreasuryRecord' table items."),
external_deposit_guard: z.array(AmountFromDepositGuardSchema).describe("Guard object list that can be verified for non-permissioned users during deposit"),
external_withdraw_guard: z.array(AmountFromWithdrawGuardSchema).describe("Guard object list that can be verified for non-permissioned users during withdrawal"),
inflow: BalanceTypeSchema.describe("Inflow amount"),
outflow: BalanceTypeSchema.describe("Outflow amount"),
um: z.union([z.string(), z.null()]).describe("Contact object"),
permission: z.string().describe("Permission object ID"),
}).describe("Treasury object");
export const TreasuryOpSchema = z.enum(["Withdraw", "Deposit", "Receive"]).describe("Treasury object operation type");
export const TreasuryRecordSchema = z.object({
op: TreasuryOpSchema.describe("Treasury object operation type"),
signer: z.string().describe("Operator user ID"),
external_guard: z.union([z.string(), z.null()]).describe("External Guard object ID. If null, operation was completed through Permission object permissions."),
amount: BalanceTypeSchema.describe("Operation amount"),
time: z.union([z.number(), z.string()]).describe("Operation time"),
store_from_id: z.union([z.string(), z.null()]).describe("Stored value from Guard table. This stores the value (address or number converted to address, including submitted values) from the Guard table at the specified index for Guard verification purposes."),
}).describe("Treasury object transaction record");
export const PolicyWriteGuardSchema = z.object({
guard: z.string().describe("Guard object ID"),
id_from_submission: GuardIdentifierSchema.optional().describe("Guard Table data index, whose corresponding value (or address) is the ID of the data to be written. If null, user must specify the ID separately."),
data_from_submission: GuardIdentifierSchema.optional().describe("Guard Table data index, whose corresponding value is the data to be written. If null, user must specify the data separately."),
}).describe("Guard object that needs verification when writing policy");
export const IdFromSchema = z.union([
z.literal(0).describe("None (0)"),
z.literal(1).describe("Clock (1)"),
z.literal(2).describe("Signer (2)"),
z.literal("None").describe("None"),
z.literal("Clock").describe("Clock"),
z.literal("Signer").describe("Signer"),
z.literal("none").describe("none"),
z.literal("clock").describe("clock"),
z.literal("signer").describe("signer"),
]).describe("Source of data ID when writing data. Can be specified as a string name (e.g., 'Clock', 'clock', 'Signer', 'signer') or a number (0-2). Supported values: None=0/'None'/'none', Clock=1/'Clock'/'clock', Signer=2/'Signer'/'signer'. If None, user must specify the ID separately; if Clock, data ID is current timestamp; if Signer, data ID is user ID.");
export const PolicyRuleSchema = z.object({
name: z.string().describe("Policy rule name"),
description: z.string().describe("Policy rule description"),
write_guard: z.array(PolicyWriteGuardSchema).describe("Guard object list that can be verified when writing data"),
quote_guard: z.union([z.string(), z.null()]).optional().describe("Guard object ID that needs verification when referencing this policy data on-chain (e.g., verifying if user has paid subscription). If null, no verification is needed for on-chain references. The Guard must have empty 'relies' field and 'rep' field true."),
id_from: IdFromSchema.describe("Source of data ID when writing data. If None, user must specify the ID separately; if Clock, data ID is current timestamp; if Signer, data ID is user ID."),
value_type: ValueTypeSchema.describe("Type of data value when writing data."),
});
export const TableItem_RepositoryDataSchema = ObjectBaseSchema.extend({
entity: z.string().describe("Object or user ID"),
name: z.string().describe("Data item name (Policy Name)"),
value: z.array(z.number()).describe("Raw data value (first byte is value type, remaining bytes are Bcs formatted value)"),
data: z.object({
value_type: ValueTypeSchema.describe("Type of data value."),
value: SupportedValueSchema.describe("Data value."),
}),
}).describe("Storage data item owned by Repository object");
export const TableItem_RewardRecordSchema = ObjectBaseSchema.extend({
recipient: z.string().describe("Reward recipient ID"),
guard: z.string().describe("Guard object ID"),
total: BalanceTypeSchema.describe("Total reward amount"),
record: z.array(z.object({
amount: BalanceTypeSchema.describe("Reward amount"),
time: z.number().describe("Reward time"),
store_from_id: z.union([z.string(), z.null()]).describe("Stored value from Guard table. This stores the value (address or number converted to address, including submitted values) from the Guard table at the specified index for Guard verification purposes."),
})).describe("Reward record list"),
}).describe("Reward object's reward record");
export const ObjectRepositorySchema = ObjectBaseSchema.extend({
description: z.string().describe("Repository object description"),
policies: z.array(PolicyRuleSchema).describe("Repository object policy rule list"),
data_count: z.number().describe("Number of data items stored in Repository object. Use 'query_table' or 'query_table_item' to get 'RepositoryData' table items."),
rewards: z.array(z.string()).describe("Reward object list"),
um: z.union([z.string(), z.null()]).describe("Contact object"),
permission: z.string().describe("Permission object ID"),
}).describe("Repository object");
export const ImSchema = z.object({
at: z.string().describe("Contact's account address for instant messaging"),
status: z.string().describe("Contact's current status message"),
join_time: z.number().describe("Timestamp when contact joined (milliseconds since epoch)"),
description: z.string().describe("Description or note about this contact"),
}).describe("Instant Messaging contact entry with address, status, and metadata");
export const ObjectContactSchema = ObjectBaseSchema.extend({
description: z.string().describe("Contact object description or public information"),
permission: z.string().describe("Permission object ID that controls who can modify this contact"),
location: z.string().describe("Physical or virtual location information for this contact"),
ims: z.array(ImSchema).describe("List of instant messaging contacts. Each entry contains an address for encrypted real-time communication via Wowok Messenger"),
}).describe("Contact object storing on-chain instant messaging addresses for real-time encrypted communication between object managers and users");
export const ObjectPersonalSchema = ObjectBaseSchema.extend({
address: z.string().describe("User's address"),
like: z.number().describe("User's like count"),
dislike: z.number().describe("User's dislike count"),
info: z.array(RecordsInEntitySchema).describe("User's personal information record list"),
description: z.string().describe("User's personal description"),
referrer: z.union([z.string(), z.null()]).describe("User's referrer ID"),
mark_object: z.union([z.string(), z.null()]).describe("On-chain address mark object ID"),
details: z.array(VoteInEntityLinkerSchema).describe("User's voting record list in EntityLinker"),
active_tx: z.union([z.string(), z.null()]).describe("User's recent active transaction ID"),
passive_tx: z.union([z.string(), z.null()]).describe("Recent transaction ID interacting with user"),
time: z.number().describe("User object creation time"),
}).describe("Personal object");
export const ObjectProofSchema = ObjectBaseSchema.extend({
description: z.string().describe("Proof description"),
proof: z.string().describe("Proof content. e.g., merkle tree root"),
server_pubkey: z.string().describe("Server public key"),
server_signature: z.string().describe("Server signature"),
proof_type: z.union([z.number(), z.string()]).describe("Proof type. 1: WTS proof; 1-100 reserved."),
item_count: z.union([z.number(), z.string(), z.null()]).describe("Item count. e.g., number of items in the merkle tree"),
about_address: z.union([z.string(), z.null()]).describe("About address. e.g., address of the entity being proved"),
signer: z.string().describe("Signer address"),
time: z.number().describe("Proof creation time"),
}).describe("Proof object");
export const WReceivedObjectSchema = ObjectBaseSchema.extend({
balance: BalanceTypeSchema.describe("Amount contained in object"),
payment: z.string().describe("Payment object ID"),
}).describe("Amount object received by on-chain object");
export const ObjectPermissionSchema = ObjectBaseSchema.extend({
builder: z.string().describe("Permission object owner ID (highest permission user)"),
admin: z.array(z.string()).describe("Admin user ID list"),
description: z.string().describe("Permission object description"),
entity_count: z.number().describe("Number of user IDs and Guard IDs granted permissions. Use 'query_table' or 'query_table_item' to get 'PermissionPerm' table items."),
perm_remark: z.array(z.object({
index: PermissionIndexTypeSchema,
remark: z.string().describe("Permission item remark"),
})).describe("Permission item remark list"),
um: z.union([z.string(), z.null()]).describe("Contact object"),
}).describe("Permission object");
export const WitnessTypeSchema = z.number()
.int()
.refine(isWitnessType, {
message: 'Invalid WitnessType value',
});
export const GuardQueryIdSchema = z.number().int().min(0).refine((id) => isValidGuardQueryId(id), { message: "Invalid guard query ID. ID not found in GUARDQUERY array." }).describe("ID of the data query instruction for the Object.");
export const GuardNodeSchema = z.lazy(() => z.discriminatedUnion('type', [
z.object({
type: z.literal('identifier'),
identifier: GuardIdentifierSchema,
}).strict().describe('Returns the constant value stored at the specified identifier in the Guard table.'),
z.object({
type: z.literal('query'),
query: z.union([
z.number().int().refine((id) => isValidGuardQueryId(id), { message: "Invalid guard query ID. ID not found in GUARDQUERY array." }),
z.string().refine((name) => isValidGuardQueryIdOrName(name), { message: "Invalid guard query name. Name not found in GUARDQUERY array (case-insensitive)." })
]).describe("ID or name of the wowok object data query instruction. Can be a numeric ID (e.g., 1001) or a name string (e.g., 'permission.description'). Name matching is case-insensitive."),
object: z.object({
identifier: GuardIdentifierSchema,
convert_witness: WitnessTypeSchema.optional().describe("Optional. When specified, the query retrieves data from the associated object instead of the object itself. For example, querying an order with convert_witness=TypeOrderProgress retrieves the associated Progress object data."),
}).strict().describe("The object to query from the Guard table."),
parameters: z.array(GuardNodeSchema).describe("Parameters required by the query (must match the query's expected parameters type)."),
}).strict().describe("Returns the result of executing a data query instruction on the specified object. The return type depends on the query being executed. SPECIAL NOTE for EntityLinker/EntityRegistrar queries: Use system addresses in the Guard table - ENTITY_LINKER_ADDRESS (0xaaa) for EntityLinker queries, ENTITY_REGISTRAR_ADDRESS (0xaab) for EntityRegistrar queries."),
z.object({
type: z.literal('logic_as_u256_greater_or_equal'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by comparing the first node value with all subsequent node values. Returns true if first >= all others, otherwise false.`),
z.object({
type: z.literal('logic_as_u256_lesser_or_equal'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by comparing the first node value with all subsequent node values. Returns true if first <= all others, otherwise false.`),
z.object({
type: z.literal('logic_as_u256_greater'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by comparing the first node value with all subsequent node values. Returns true if first > all others, otherwise false.`),
z.object({
type: z.literal('logic_as_u256_lesser'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by comparing the first node value with all subsequent node values. Returns true if first < all others, otherwise false.`),
z.object({
type: z.literal('logic_as_u256_equal'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by comparing the first node value with all subsequent node values. Returns true if first equals all others, otherwise false.`),
z.object({
type: z.literal('logic_equal'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} nodes of any type. Computed by comparing the first node with all subsequent nodes in both type and value. Returns true if type and value match for all, otherwise false.`),
z.object({
type: z.literal('logic_not'),
node: GuardNodeSchema,
}).strict().describe("Returns Bool. Computed by inverting the boolean value of the child node (true -> false, false -> true)."),
z.object({
type: z.literal('logic_and'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} boolean nodes. Computed by performing logical AND on all child node values. Returns true if ALL are true, otherwise false.`),
z.object({
type: z.literal('logic_or'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} boolean nodes. Computed by performing logical OR on all child node values. Returns true if ANY is true, otherwise false.`),
z.object({
type: z.literal('logic_string_contains'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} string nodes. The first node is the haystack, all subsequent nodes are needles. Returns true if all needles are substrings of the haystack, otherwise false. Case-sensitive.`),
z.object({
type: z.literal('logic_string_nocase_contains'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} string nodes. The first node is the haystack, all subsequent nodes are needles. Returns true if all needles are substrings of the haystack, otherwise false. Case-insensitive.`),
z.object({
type: z.literal('logic_string_nocase_equal'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} string nodes. Computed by comparing the first node with all subsequent nodes as strings, ignoring case. Returns true if all are equal, otherwise false.`),
z.object({
type: z.literal('calc_number_add'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns U256. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by adding the first node value with all subsequent node values in sequence (first + second + third + ...).`),
z.object({
type: z.literal('calc_number_multiply'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns U256. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by multiplying the first node value with all subsequent node values in sequence (first * second * third * ...).`),
z.object({
type: z.literal('calc_number_subtract'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns U256. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by subtracting the second node value from the first node value in sequence, then continuing with each subsequent node (first - second - third - ...).`),
z.object({
type: z.literal('calc_number_divide'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns U256. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by dividing the first node value by the second node value in sequence, then continuing with each subsequent node ((first / second) / third / ...). Throws exception if any divisor is zero.`),
z.object({
type: z.literal('calc_number_mod'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns U256. Requires 2-${MAX_MULTI_OPERANDS} numeric nodes (U8, U16, U32, U64, U128, U256). Computed by taking the remainder of dividing the first node value by the second node value in sequence, then continuing with each subsequent node ((first % second) % third % ...). Throws exception if any divisor is zero.`),
z.object({
type: z.literal('calc_string_length'),
node: GuardNodeSchema,
}).strict().describe("Returns U64. Computed by getting the length (number of UTF-8 bytes) of the child node value."),
z.object({
type: z.literal('calc_string_nocase_contains'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} string nodes. The first node is the haystack, all subsequent nodes are needles. Returns true if all needles are substrings of the haystack, otherwise false. Case-insensitive.`),
z.object({
type: z.literal('calc_string_nocase_equal'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} string nodes. Computed by comparing the first node with all subsequent nodes as strings, ignoring case. Returns true if all are equal, otherwise false.`),
z.object({
type: z.literal('calc_string_contains'),
nodes: z.array(GuardNodeSchema),
}).strict().describe(`Returns Bool. Requires 2-${MAX_MULTI_OPERANDS} string nodes. The first node is the haystack, all subsequent nodes are needles. Returns true if all needles are substrings of the haystack, otherwise false. Case-sensitive.`),
z.object({
type: z.literal('calc_string_indexof'),
nodeLeft: GuardNodeSchema,
nodeRight: GuardNodeSchema,
order: z.enum(['forward', 'backward']).describe("'forward' searches from start to end, 'backward' searches from end to start."),
}).strict().describe("Returns U64. Computed by searching for the second node (needle) in the first node (haystack). Returns index of first occurrence in the specified direction. If not found, returns u64::MAX (18446744073709551615)."),
z.object({
type: z.literal('calc_string_nocase_indexof'),
nodeLeft: GuardNodeSchema,
nodeRight: GuardNodeSchema,
order: z.enum(['forward', 'backward']).describe("'forward' searches from start to end, 'backward' searches from end to start."),
}).strict().describe("Returns U64. Computed by searching for the second node (needle) in the first node (haystack), ignoring case. Returns index of first occurrence in the specified direction. If not found, returns u64::MAX (18446744073709551615)."),
z.object({
type: z.literal('convert_number_address'),
node: GuardNodeSchema,
}).strict().describe("Returns Address. Computed by converting the child node value from number type to Address type."),
z.object({
type: z.literal('convert_address_number'),
node: GuardNodeSchema,
}).strict().describe("Returns U256. Computed by converting the child node value from Address type to number type."),
z.object({
type: z.literal('convert_number_string'),
node: GuardNodeSchema,
}).strict().describe("Returns String. Computed by converting the child node value from number type to string type."),
z.object({
type: z.literal('convert_string_number'),
node: GuardNodeSchema,
}).strict().describe("Returns U256. Computed by parsing the child node value as a number. Throws exception if the string is not a valid number."),
z.object({
type: z.literal('convert_safe_u8'),
node: GuardNodeSchema,
}).strict().describe("Returns U8. Computed by converting the child node value to U8. Throws exception if value is out of U8 range (0-255)."),
z.object({
type: z.literal('convert_safe_u16'),
node: GuardNodeSchema,
}).strict().describe("Returns U16. Computed by converting the child node value to U16. Throws exception if value is out of U16 range (0-65535)."),
z.object({
type: z.literal('convert_safe_u32'),
node: GuardNodeSchema,
}).strict().describe("Returns U32. Computed by converting the child node value to U32. Throws exception if value is out of U32 range."),
z.object({
type: z.literal('convert_safe_u64'),
node: GuardNodeSchema,
}).strict().describe("Returns U64. Computed by converting the child node value to U64. Throws exception if value is out of U64 range."),
z.object({
type: z.literal('convert_safe_u128'),
node: GuardNodeSchema,
}).strict().describe("Returns U128. Computed by converting the child node value to U128. Throws exception if value is out of U128 range."),
z.object({
type: z.literal('convert_safe_u256'),
node: GuardNodeSchema,
}).strict().describe("Returns U256. Computed by converting the child node value to U256."),
z.object({
type: z.literal('value_type'),
node: GuardNodeSchema,
}).strict().describe(`Returns U8. Computed by getting the type identifier (ValueType) of the child node value. ${VALUE_TYPE_DESCRIPTION}`),
z.object({
type: z.literal('vec_length'),
node: GuardNodeSchema,
}).strict().describe(`Returns U64. Computed by getting the length of the vector in the child node value. Child node must be one of Vec types: VecBool=9, VecAddress=10, VecString=11, VecU8=12, VecU16=13, VecU32=14, VecU64=15, VecU128=16, VecU256=17, VecVecU8=18, Value=19.`),
z.object({
type: z.literal('vec_contains_bool'),
nodes: z.array(GuardNodeSchema).describe(`2 to ${MAX_MULTI_OPERANDS} nodes required. First node must be VecBool (ValueType=9) or Value (ValueType=19), remaining nodes must be Bool (ValueType=0) or Value (ValueType=19).`),
}).strict().describe("Returns Bool. Computed by checking if the vector (first node) contains ALL boolean values (subsequent nodes)."),
z.object({
type: z.literal('vec_contains_address'),
nodes: z.array(GuardNodeSchema).describe(`2 to ${MAX_MULTI_OPERANDS} nodes required. First node must be VecAddress (ValueType=10) or Value (ValueType=19), remaining nodes must be Address (ValueType=1) or Value (ValueType=19).`),
}).strict().describe("Returns Bool. Computed by checking if the vector (first node) contains ALL address values (subsequent nodes)."),
z.object({
type: z.literal('vec_contains_string'),
nodes: z.array(GuardNodeSchema).describe(`2 to ${MAX_MULTI_OPERANDS} nodes required. First node must be VecString (ValueType=11) or Value (ValueType=19), remaining nodes must be String (ValueType=2) or Value (ValueType=19).`),
}).strict().describe("Returns Bool. Computed by checking if the vector (first node) contains ALL string values (subsequent nodes)."),
z.object({
type: z.literal('vec_contains_string_nocase'),
nodes: z.array(GuardNodeSchema).describe(`2 to ${MAX_MULTI_OPERANDS} nodes required. First node must be VecString (ValueType=11) or Value (ValueType=19), remaining nodes must be String (ValueType=2) or Value (ValueType=19).`),
}).strict().describe("Returns Bool. Computed by checking if the vector (first node) contains ALL string values (subsequent nodes), using case-insensitive comparison."),
z.object({
type: z.literal('vec_contains_number'),
nodes: z.array(GuardNodeSchema).describe(`2 to ${MAX_MULTI_OPERANDS} nodes required. First node must be VecU8 (12), VecU16 (13), VecU32 (14), VecU64 (15), VecU128 (16), VecU256 (17) or Value (ValueType=19), remaining nodes must be U8 (3), U16 (4), U32 (5), U64 (6), U128 (7), U256 (8) or Value (ValueType=19).`),
}).strict().describe("Returns Bool. Computed by checking if the vector (first node) contains ALL number values (subsequent nodes)."),
z.object({
type: z.literal('vec_indexof_bool'),
nodeLeft: GuardNodeSchema,
nodeRight: GuardNodeSchema,
order: z.enum(['forward', 'backward']).describe("'forward' searches from index 0, 'backward' searches from last index."),
}).strict().describe("Returns U64. Computed by searching for the second node value in the vector (first node). nodeLeft must be VecBool (ValueType=9) or Value (ValueType=19) type, nodeRight must be Bool (ValueType=0) or Value (ValueType=19) type. Returns index of first occurrence in the specified direction. If not found, returns u64::MAX (18446744073709551615)."),
z.object({
type: z.literal('vec_indexof_address'),
nodeLeft: GuardNodeSchema,
nodeRight: GuardNodeSchema,
order: z.enum(['forward', 'backward']).describe("'forward' searches from index 0, 'backward' searches from last index."),
}).strict().describe("Returns U64. Computed by searching for the second node value in the vector (first node). nodeLeft must be VecAddress (ValueType=10) or Value (ValueType=19) type, nodeRight must be Address (ValueType=1) or Value (ValueTyp