wowok_agent
Version:
Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.
153 lines (147 loc) • 10.2 kB
JavaScript
import { z } from 'zod';
import { WithPermissionObjectSchema, NamedObjectSchema, ObjectsSchema, CallEnvSchema, SubmissionCallSchema, } from './base.js';
import { MachineNodeSchema, PermissionIndexTypeSchema } from '../query/index.js';
import { ManyAccountOrMark_AddressSchema, NameOrAddressSchema, NameSchema, NotEmptyNameSchema, ReceivedObjectsOrRecentlySchema } from '../common/index.js';
export const ProgressNamedOperatorSchema = z.object({
op: z.union([z.literal('add'), z.literal('set'), z.literal('remove')]),
name: NotEmptyNameSchema,
operators: ManyAccountOrMark_AddressSchema,
}).strict();
export const ProgressNewSchema = z.object({
task: z.union([NameOrAddressSchema, z.null()]).optional().describe('Task bound to the Progress object. It is an object ID or name'),
repository: ObjectsSchema.optional().describe('Set repository list for the Progress object. Used for consensus data management.'),
progress_namedOperator: ProgressNamedOperatorSchema.optional().describe('Add, set, and remove operators for the permission namespace of the Progress object.'),
namedNew: NamedObjectSchema.optional(),
}).strict();
export const NodeAddForwardDataSchema = z.object({
prior_node_name: NameSchema.describe('Name of the previous node.'),
node_name: NameSchema.describe('Name of the next node.'),
forward: z.array(z.object({
name: NameSchema.describe('Name of the operation'),
namedOperator: z.union([NotEmptyNameSchema, z.null()]).optional().describe('One of the operation permissions: use operators within the permission space name in the Machine object. Each Progress object can manage operators independently. Use empty string "" to indicate the order permission (order owner and agents can operate). When using Order object to operate progress, empty string namedOperator allows order owner/agents to execute the forward without needing other permissions.'),
permissionIndex: z.union([PermissionIndexTypeSchema, z.null()]).optional().describe('Second operation permission: use operators specified by the permission index of the Permission object in the Machine object. All Progress objects share the same operators.'),
weight: z.number().min(0).max(65535).int().describe('Weight of the operation'),
}).strict()).describe('List of operations between the previous and next nodes.'),
threshold: z.union([z.number().int().min(0), z.null()]).optional().describe('Threshold of operations that need to be completed to migrate from the previous node to the next node.'),
}).strict();
export const NodeRemoveForwardDataSchema = z.object({
prior_node_name: NameSchema.describe('Name of the previous node.'),
node_name: NameSchema.describe('Name of the next node.'),
forward_name: z.array(NameSchema).describe('List of operation names to delete.'),
}).strict();
export const NodeRemovePriorNodeDataSchema = z.object({
prior_node_name: z.array(NameSchema).describe('List of previous node names to delete.'),
node_name: NameSchema.describe('Name of the next node.'),
}).strict();
export const NodeSchema = z.discriminatedUnion('op', [
z.object({
op: z.literal('add'),
nodes: z.array(MachineNodeSchema).describe('List of nodes to add or set.'),
bReplace: z.boolean().optional().describe('Whether to replace existing nodes. If true, existing nodes will be replaced; if false, nodes will be added by merging.'),
}).strict().describe('Add nodes.'),
z.object({
op: z.literal('set'),
nodes: z.array(MachineNodeSchema).describe('List of nodes to add or set.'),
bReplace: z.boolean().optional().describe('Whether to replace existing nodes. If true, existing nodes will be replaced; if false, nodes will be added by merging.'),
}).strict().describe('Set nodes.'),
z.object({
op: z.literal('remove'),
nodes: z.array(NameSchema).describe('List of node names to delete.'),
}).strict().describe('Delete nodes.'),
z.object({
op: z.literal('clear'),
}).strict().describe('Clear all nodes.'),
z.object({
op: z.literal('exchange'),
node_one: NameSchema.describe('Name of the first node.'),
node_other: NameSchema.describe('Name of the second node.'),
}).strict().describe('Exchange the positions of two nodes.'),
z.object({
op: z.literal('rename'),
node_name_old: NameSchema.describe('Name of thenode.'),
node_name_new: NameSchema.describe('New name of the node.'),
}).strict().describe('Rename node.'),
z.object({
op: z.literal('remove prior node'),
pairs: z.array(NodeRemovePriorNodeDataSchema).describe('List of previous-next node pairs to delete.'),
}).strict().describe('Delete previous-next node pairs.'),
z.object({
op: z.literal('add forward'),
data: z.array(NodeAddForwardDataSchema).describe('List of operations to add.'),
}).strict().describe('Add operations.'),
z.object({
op: z.literal('remove forward'),
data: z.array(NodeRemoveForwardDataSchema).describe('List of operations to delete.'),
}).strict().describe('Delete operations.'),
]);
export const NodeJsonOrMarkdownFileSchema = z.object({
json_or_markdown_file: z.string().describe(`Path to a JSON or Markdown file containing node array for COMPLETE REPLACEMENT of all nodes.
**File Format Requirements:**
- Must contain a JSON ARRAY of node objects: [{"name": "...", "pairs": [...]}, {...}]
- NOT an operation object with "op" field (use NodeSchema for operations)
- Supports JSON or Markdown (with \`\`\`json code blocks)
**Node Structure:**
Each node is a directed graph element representing workflow states and transitions:
- name: Node identifier
- pairs: Array of {prior_node, forwards, threshold} defining connections
- forwards: Operations available from this node
- threshold: Required weight to advance
**Behavior:**
- COMPLETELY REPLACES all existing nodes (equivalent to "set" with bReplace=true)
- Auto-detects format based on file content
- If parsing fails, error includes line number and column information`),
}).strict();
export const NodeFieldSchema = z.union([
NodeSchema,
NodeJsonOrMarkdownFileSchema,
]);
export const CallMachine_DataSchema = z.object({
object: WithPermissionObjectSchema,
progress_new: ProgressNewSchema.optional().describe('Generate new Progress object.'),
description: z.string().optional().describe('Description of the object.'),
repository: ObjectsSchema.optional().describe('Set repository list for the object. Used for consensus data management.'),
node: NodeFieldSchema.optional().describe(`CRITICAL: Choose ONE of two mutually exclusive modes:
**Mode 1: NodeSchema (incremental operations)**
Use for partial modifications: add, set, remove, clear, exchange, rename, remove prior node, add forward, remove forward.
Format: { "op": "add", "nodes": [...], "bReplace": false }
This mode modifies existing nodes incrementally.
**Mode 2: NodeJsonOrMarkdownFileSchema (complete replacement)**
Use for complete node redefinition from file.
Format: { "json_or_markdown_file": "/path/to/nodes.json" }
IMPORTANT: This COMPLETELY REPLACES all existing nodes. File must contain node array [{...}, {...}], NOT an operation object with "op" field.
Supported formats: JSON array or Markdown with code blocks.
If parsing fails, error includes line number and column information.`),
pause: z.boolean().optional().describe('Whether to pause generating new Progress objects.'),
publish: z.boolean().optional().describe('Whether to publish the object. After the object is published, new Progress objects can be generated; and node settings will no longer be changeable.'),
owner_receive: ReceivedObjectsOrRecentlySchema.optional().describe('Unwrap CoinWrapper objects and other objects received by this object and send them to the owner of its Permission object.'),
um: z.union([z.string(), z.null()]).optional().describe('Contact object.'),
}).strict().describe("On-chain Machine operations. USAGE: (1) CREATE NEW: Set 'object' field with OBJECT format {name, permission, ...} to create a Machine. NOTE: 'name' goes INSIDE 'object', NOT at the data root level. 'permission' can be a new Permission object or reference an existing one - check 'object' field description for details. (2) OPERATE EXISTING: Set 'object' field with STRING format (object ID or name). The 'object' field is CRITICAL and REQUIRED in both cases. STRING for existing, OBJECT for new creation.");
export const CallMachine_InputSchema = z.object({
data: CallMachine_DataSchema,
env: CallEnvSchema.optional(),
submission: SubmissionCallSchema.optional(),
}).strict();
export const MachineNode2File_InputSchema = z.object({
machine: NameOrAddressSchema.describe("Machine object ID or name to export"),
file_path: z.string().describe("Output file path (absolute or relative)"),
format: z.enum(["json", "markdown"]).optional().describe("Output format: 'json' (default) or 'markdown'"),
env: CallEnvSchema.optional(),
}).strict().describe("Query a Machine object from the blockchain and export its node definition to a JSON or Markdown file. The exported file can be edited and used to create new Machine objects.");
export const MachineNode2File_OutputSchema = z.discriminatedUnion("status", [
z.object({
status: z.literal("success"),
data: z.object({
file_path: z.string().describe("Absolute path of the exported file"),
format: z.enum(["json", "markdown"]).describe("Export format"),
machine_object: NameOrAddressSchema.describe("Machine object ID"),
node_count: z.number().describe("Number of nodes exported"),
}).strict().describe("Success result data"),
}).strict(),
z.object({
status: z.literal("error"),
error: z.string().describe("Error message"),
}).strict(),
]).describe("MachineNode2File operation output");
export const MachineNode2File_OutputWrappedSchema = z.object({
result: MachineNode2File_OutputSchema,
}).strict().describe("MachineNode2File operation output wrapped schema");