wowok_agent 2.1.40 → 2.2.0
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.js +1237 -1
- package/dist/schema/call/allocation.js +24 -1
- package/dist/schema/call/arbitration.js +92 -1
- package/dist/schema/call/base.js +134 -1
- package/dist/schema/call/contact.js +37 -1
- package/dist/schema/call/demand.js +47 -1
- package/dist/schema/call/guard.js +58 -1
- package/dist/schema/call/handler.js +171 -1
- package/dist/schema/call/index.js +18 -1
- package/dist/schema/call/machine.js +152 -1
- package/dist/schema/call/order.js +34 -1
- package/dist/schema/call/payment.js +17 -1
- package/dist/schema/call/permission.js +105 -1
- package/dist/schema/call/personal.js +68 -1
- package/dist/schema/call/progress.js +26 -1
- package/dist/schema/call/proof.js +27 -1
- package/dist/schema/call/repository.js +76 -1
- package/dist/schema/call/reward.js +42 -1
- package/dist/schema/call/service.js +82 -1
- package/dist/schema/call/treasury.js +71 -1
- package/dist/schema/common/index.js +345 -1
- package/dist/schema/index.js +7 -1
- package/dist/schema/local/index.js +855 -1
- package/dist/schema/local/wip.js +187 -1
- package/dist/schema/messenger/index.js +446 -1
- package/dist/schema/query/index.js +1265 -1
- package/dist/schema/utils/guard-parser.js +401 -1
- package/dist/schema/utils/guard-query-utils.js +22 -1
- package/dist/schema/utils/node-parser.js +353 -1
- package/dist/schema/utils/permission-index-utils.js +7 -1
- package/package.json +3 -6
|
@@ -1 +1,171 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ResponseData, LocalMark, enrichMoveError } from "wowok";
|
|
2
|
+
export function handleCallResult(result) {
|
|
3
|
+
if (result && "error" in result) {
|
|
4
|
+
const enrichedError = enrichMoveError(result.error);
|
|
5
|
+
const output = {
|
|
6
|
+
message: `Error: ${enrichedError}`,
|
|
7
|
+
result: { type: "error", error: enrichedError },
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
content: [{ type: "text", text: output.message }],
|
|
11
|
+
structuredContent: output,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (result && "digest" in result) {
|
|
15
|
+
const r = ResponseData(result);
|
|
16
|
+
const txStatus = result?.effects?.status?.status;
|
|
17
|
+
const txError = result?.effects?.status?.error;
|
|
18
|
+
const isSuccess = txStatus === "success";
|
|
19
|
+
if (!isSuccess) {
|
|
20
|
+
const enrichedError = enrichMoveError(txError || txStatus || "unknown error");
|
|
21
|
+
const output = {
|
|
22
|
+
message: `Transaction failed: ${enrichedError}`,
|
|
23
|
+
result: { type: "error", error: enrichedError },
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
content: [
|
|
27
|
+
{ type: "text", text: output.message },
|
|
28
|
+
{ type: "text", text: JSON.stringify(r) },
|
|
29
|
+
],
|
|
30
|
+
structuredContent: output,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const output = {
|
|
34
|
+
message: "Transaction completed successfully",
|
|
35
|
+
result: { type: "transaction", ...result },
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{ type: "text", text: output.message },
|
|
40
|
+
{ type: "text", text: JSON.stringify(r) },
|
|
41
|
+
],
|
|
42
|
+
structuredContent: output,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (result && "guard" in result && "submission" in result) {
|
|
46
|
+
const output = {
|
|
47
|
+
message: "Submission required for Guard verification",
|
|
48
|
+
result: { type: "submission", ...result },
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{ type: "text", text: output.message },
|
|
53
|
+
{ type: "text", text: JSON.stringify(result) },
|
|
54
|
+
],
|
|
55
|
+
structuredContent: output,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(result)) {
|
|
59
|
+
const output = {
|
|
60
|
+
message: "Operation completed",
|
|
61
|
+
result: { type: "data", data: result },
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{ type: "text", text: output.message },
|
|
66
|
+
{ type: "text", text: JSON.stringify(result) },
|
|
67
|
+
],
|
|
68
|
+
structuredContent: output,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (result === undefined || result === null) {
|
|
72
|
+
const output = {
|
|
73
|
+
message: "Operation completed",
|
|
74
|
+
result: { type: "null" },
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: "text", text: output.message }],
|
|
78
|
+
structuredContent: output,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const output = {
|
|
82
|
+
message: "Operation completed",
|
|
83
|
+
result: { type: "transaction", ...result },
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
content: [{ type: "text", text: output.message }],
|
|
87
|
+
structuredContent: output,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function createServerConfig(packageJson, description) {
|
|
91
|
+
return {
|
|
92
|
+
name: packageJson.name,
|
|
93
|
+
version: packageJson.version,
|
|
94
|
+
description: description || packageJson.description,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function createCapabilitiesConfig() {
|
|
98
|
+
return {
|
|
99
|
+
capabilities: {
|
|
100
|
+
prompts: {},
|
|
101
|
+
resources: {},
|
|
102
|
+
tools: { listChanged: true },
|
|
103
|
+
logging: {},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function createToolMeta(category, tags) {
|
|
108
|
+
return {
|
|
109
|
+
author: "WOWOK Team",
|
|
110
|
+
createdAt: "2026-02-01",
|
|
111
|
+
lastUpdated: "2026-02-01",
|
|
112
|
+
category,
|
|
113
|
+
tags,
|
|
114
|
+
requiresAuth: false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function createToolAnnotations(readOnlyHint = false, destructiveHint = false) {
|
|
118
|
+
return {
|
|
119
|
+
readOnlyHint,
|
|
120
|
+
destructiveHint,
|
|
121
|
+
idempotentHint: true,
|
|
122
|
+
openWorldHint: false,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export async function transformSubmission(submission) {
|
|
126
|
+
if (!submission)
|
|
127
|
+
return undefined;
|
|
128
|
+
const guardNames = (submission.guard || []).map((g) => g.object).filter(Boolean);
|
|
129
|
+
const submissionGuardNames = (submission.submission || []).map((s) => s.guard).filter(Boolean);
|
|
130
|
+
const allNames = [...new Set([...guardNames, ...submissionGuardNames])];
|
|
131
|
+
const resolvedAddresses = allNames.length > 0
|
|
132
|
+
? await LocalMark.Instance().get_many_address(allNames)
|
|
133
|
+
: [];
|
|
134
|
+
const nameToAddress = new Map();
|
|
135
|
+
allNames.forEach((name, index) => {
|
|
136
|
+
const addr = resolvedAddresses[index];
|
|
137
|
+
if (addr) {
|
|
138
|
+
nameToAddress.set(name, addr);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const getAddress = (name) => {
|
|
142
|
+
if (nameToAddress.has(name)) {
|
|
143
|
+
return nameToAddress.get(name);
|
|
144
|
+
}
|
|
145
|
+
for (const [n, addr] of nameToAddress.entries()) {
|
|
146
|
+
if (n === name)
|
|
147
|
+
return addr;
|
|
148
|
+
}
|
|
149
|
+
if (name.startsWith("0x") && name.length === 66) {
|
|
150
|
+
return name;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`Guard name or address not found: ${name}`);
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
type: "submission",
|
|
156
|
+
guard: (submission.guard || []).map((g) => ({
|
|
157
|
+
object: getAddress(g.object),
|
|
158
|
+
impack: g.impack || false,
|
|
159
|
+
})),
|
|
160
|
+
submission: (submission.submission || []).map((s) => ({
|
|
161
|
+
guard: getAddress(s.guard),
|
|
162
|
+
submission: s.submission || [],
|
|
163
|
+
})),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export function validateInput(data, schema) {
|
|
167
|
+
return schema.parse(data);
|
|
168
|
+
}
|
|
169
|
+
export function getEnvConfig(env) {
|
|
170
|
+
return env || {};
|
|
171
|
+
}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
export*from'./base.js';
|
|
1
|
+
export * from './base.js';
|
|
2
|
+
export * from './handler.js';
|
|
3
|
+
export * from './contact.js';
|
|
4
|
+
export * from './demand.js';
|
|
5
|
+
export * from './guard.js';
|
|
6
|
+
export * from './machine.js';
|
|
7
|
+
export * from './arbitration.js';
|
|
8
|
+
export * from './allocation.js';
|
|
9
|
+
export * from './order.js';
|
|
10
|
+
export * from './payment.js';
|
|
11
|
+
export * from './permission.js';
|
|
12
|
+
export * from './personal.js';
|
|
13
|
+
export * from './proof.js';
|
|
14
|
+
export * from './progress.js';
|
|
15
|
+
export * from './repository.js';
|
|
16
|
+
export * from './reward.js';
|
|
17
|
+
export * from './service.js';
|
|
18
|
+
export * from './treasury.js';
|
|
@@ -1 +1,152 @@
|
|
|
1
|
-
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\x20bound\x20to\x20the\x20Progress\x20object.\x20It\x20is\x20an\x20object\x20ID\x20or\x20name'),'repository':ObjectsSchema['optional']()['describe']('Set\x20repository\x20list\x20for\x20the\x20Progress\x20object.\x20Used\x20for\x20consensus\x20data\x20management.'),'progress_namedOperator':ProgressNamedOperatorSchema['optional']()['describe']('Add,\x20set,\x20and\x20remove\x20operators\x20for\x20the\x20permission\x20namespace\x20of\x20the\x20Progress\x20object.'),'namedNew':NamedObjectSchema['optional']()})['strict']();export const NodeAddForwardDataSchema=z['object']({'prior_node_name':NameSchema['describe']('Name\x20of\x20the\x20previous\x20node.'),'node_name':NameSchema['describe']('Name\x20of\x20the\x20next\x20node.'),'forward':z['array'](z['object']({'name':NameSchema['describe']('Name\x20of\x20the\x20operation'),'namedOperator':z['union']([NotEmptyNameSchema,z['null']()])['optional']()['describe']('One\x20of\x20the\x20operation\x20permissions:\x20use\x20operators\x20within\x20the\x20permission\x20space\x20name\x20in\x20the\x20Machine\x20object.\x20Each\x20Progress\x20object\x20can\x20manage\x20operators\x20independently.\x20Use\x20empty\x20string\x20\x22\x22\x20to\x20indicate\x20the\x20order\x20permission\x20(order\x20owner\x20and\x20agents\x20can\x20operate).\x20When\x20using\x20Order\x20object\x20to\x20operate\x20progress,\x20empty\x20string\x20namedOperator\x20allows\x20order\x20owner/agents\x20to\x20execute\x20the\x20forward\x20without\x20needing\x20other\x20permissions.'),'permissionIndex':z['union']([PermissionIndexTypeSchema,z['null']()])['optional']()['describe']('Second\x20operation\x20permission:\x20use\x20operators\x20specified\x20by\x20the\x20permission\x20index\x20of\x20the\x20Permission\x20object\x20in\x20the\x20Machine\x20object.\x20All\x20Progress\x20objects\x20share\x20the\x20same\x20operators.'),'weight':z['number']()['min'](0x0)['max'](0xffff)['int']()['describe']('Weight\x20of\x20the\x20operation')})['strict']())['describe']('List\x20of\x20operations\x20between\x20the\x20previous\x20and\x20next\x20nodes.'),'threshold':z['union']([z['number']()['int']()['min'](0x0),z['null']()])['optional']()['describe']('Threshold\x20of\x20operations\x20that\x20need\x20to\x20be\x20completed\x20to\x20migrate\x20from\x20the\x20previous\x20node\x20to\x20the\x20next\x20node.')})['strict']();export const NodeRemoveForwardDataSchema=z['object']({'prior_node_name':NameSchema['describe']('Name\x20of\x20the\x20previous\x20node.'),'node_name':NameSchema['describe']('Name\x20of\x20the\x20next\x20node.'),'forward_name':z['array'](NameSchema)['describe']('List\x20of\x20operation\x20names\x20to\x20delete.')})['strict']();export const NodeRemovePriorNodeDataSchema=z['object']({'prior_node_name':z['array'](NameSchema)['describe']('List\x20of\x20previous\x20node\x20names\x20to\x20delete.'),'node_name':NameSchema['describe']('Name\x20of\x20the\x20next\x20node.')})['strict']();export const NodeSchema=z['discriminatedUnion']('op',[z['object']({'op':z['literal']('add'),'nodes':z['array'](MachineNodeSchema)['describe']('List\x20of\x20nodes\x20to\x20add\x20or\x20set.'),'bReplace':z['boolean']()['optional']()['describe']('Whether\x20to\x20replace\x20existing\x20nodes.\x20If\x20true,\x20existing\x20nodes\x20will\x20be\x20replaced;\x20if\x20false,\x20nodes\x20will\x20be\x20added\x20by\x20merging.')})['strict']()['describe']('Add\x20nodes.'),z['object']({'op':z['literal']('set'),'nodes':z['array'](MachineNodeSchema)['describe']('List\x20of\x20nodes\x20to\x20add\x20or\x20set.'),'bReplace':z['boolean']()['optional']()['describe']('Whether\x20to\x20replace\x20existing\x20nodes.\x20If\x20true,\x20existing\x20nodes\x20will\x20be\x20replaced;\x20if\x20false,\x20nodes\x20will\x20be\x20added\x20by\x20merging.')})['strict']()['describe']('Set\x20nodes.'),z['object']({'op':z['literal']('remove'),'nodes':z['array'](NameSchema)['describe']('List\x20of\x20node\x20names\x20to\x20delete.')})['strict']()['describe']('Delete\x20nodes.'),z['object']({'op':z['literal']('clear')})['strict']()['describe']('Clear\x20all\x20nodes.'),z['object']({'op':z['literal']('exchange'),'node_one':NameSchema['describe']('Name\x20of\x20the\x20first\x20node.'),'node_other':NameSchema['describe']('Name\x20of\x20the\x20second\x20node.')})['strict']()['describe']('Exchange\x20the\x20positions\x20of\x20two\x20nodes.'),z['object']({'op':z['literal']('rename'),'node_name_old':NameSchema['describe']('Name\x20of\x20thenode.'),'node_name_new':NameSchema['describe']('New\x20name\x20of\x20the\x20node.')})['strict']()['describe']('Rename\x20node.'),z['object']({'op':z['literal']('remove\x20prior\x20node'),'pairs':z['array'](NodeRemovePriorNodeDataSchema)['describe']('List\x20of\x20previous-next\x20node\x20pairs\x20to\x20delete.')})['strict']()['describe']('Delete\x20previous-next\x20node\x20pairs.'),z['object']({'op':z['literal']('add\x20forward'),'data':z['array'](NodeAddForwardDataSchema)['describe']('List\x20of\x20operations\x20to\x20add.')})['strict']()['describe']('Add\x20operations.'),z['object']({'op':z['literal']('remove\x20forward'),'data':z['array'](NodeRemoveForwardDataSchema)['describe']('List\x20of\x20operations\x20to\x20delete.')})['strict']()['describe']('Delete\x20operations.')]);export const NodeJsonOrMarkdownFileSchema=z['object']({'json_or_markdown_file':z['string']()['describe']('Path\x20to\x20a\x20JSON\x20or\x20Markdown\x20file\x20containing\x20node\x20array\x20for\x20COMPLETE\x20REPLACEMENT\x20of\x20all\x20nodes.\x0a\x0a**File\x20Format\x20Requirements:**\x0a-\x20Must\x20contain\x20a\x20JSON\x20ARRAY\x20of\x20node\x20objects:\x20[{\x22name\x22:\x20\x22...\x22,\x20\x22pairs\x22:\x20[...]},\x20{...}]\x0a-\x20NOT\x20an\x20operation\x20object\x20with\x20\x22op\x22\x20field\x20(use\x20NodeSchema\x20for\x20operations)\x0a-\x20Supports\x20JSON\x20or\x20Markdown\x20(with\x20```json\x20code\x20blocks)\x0a\x0a**Node\x20Structure:**\x0aEach\x20node\x20is\x20a\x20directed\x20graph\x20element\x20representing\x20workflow\x20states\x20and\x20transitions:\x0a-\x20name:\x20Node\x20identifier\x0a-\x20pairs:\x20Array\x20of\x20{prior_node,\x20forwards,\x20threshold}\x20defining\x20connections\x0a-\x20forwards:\x20Operations\x20available\x20from\x20this\x20node\x0a-\x20threshold:\x20Required\x20weight\x20to\x20advance\x0a\x0a**Behavior:**\x0a-\x20COMPLETELY\x20REPLACES\x20all\x20existing\x20nodes\x20(equivalent\x20to\x20\x22set\x22\x20with\x20bReplace=true)\x0a-\x20Auto-detects\x20format\x20based\x20on\x20file\x20content\x0a-\x20If\x20parsing\x20fails,\x20error\x20includes\x20line\x20number\x20and\x20column\x20information')})['strict']();export const NodeFieldSchema=z['union']([NodeSchema,NodeJsonOrMarkdownFileSchema]);export const CallMachine_DataSchema=z['object']({'object':WithPermissionObjectSchema,'progress_new':ProgressNewSchema['optional']()['describe']('Generate\x20new\x20Progress\x20object.'),'description':z['string']()['optional']()['describe']('Description\x20of\x20the\x20object.'),'repository':ObjectsSchema['optional']()['describe']('Set\x20repository\x20list\x20for\x20the\x20object.\x20Used\x20for\x20consensus\x20data\x20management.'),'node':NodeFieldSchema['optional']()['describe']('CRITICAL:\x20Choose\x20ONE\x20of\x20two\x20mutually\x20exclusive\x20modes:\x0a\x0a**Mode\x201:\x20NodeSchema\x20(incremental\x20operations)**\x0aUse\x20for\x20partial\x20modifications:\x20add,\x20set,\x20remove,\x20clear,\x20exchange,\x20rename,\x20remove\x20prior\x20node,\x20add\x20forward,\x20remove\x20forward.\x0aFormat:\x20{\x20\x22op\x22:\x20\x22add\x22,\x20\x22nodes\x22:\x20[...],\x20\x22bReplace\x22:\x20false\x20}\x0aThis\x20mode\x20modifies\x20existing\x20nodes\x20incrementally.\x0a\x0a**Mode\x202:\x20NodeJsonOrMarkdownFileSchema\x20(complete\x20replacement)**\x0aUse\x20for\x20complete\x20node\x20redefinition\x20from\x20file.\x0aFormat:\x20{\x20\x22json_or_markdown_file\x22:\x20\x22/path/to/nodes.json\x22\x20}\x0aIMPORTANT:\x20This\x20COMPLETELY\x20REPLACES\x20all\x20existing\x20nodes.\x20File\x20must\x20contain\x20node\x20array\x20[{...},\x20{...}],\x20NOT\x20an\x20operation\x20object\x20with\x20\x22op\x22\x20field.\x0aSupported\x20formats:\x20JSON\x20array\x20or\x20Markdown\x20with\x20code\x20blocks.\x0aIf\x20parsing\x20fails,\x20error\x20includes\x20line\x20number\x20and\x20column\x20information.'),'pause':z['boolean']()['optional']()['describe']('Whether\x20to\x20pause\x20generating\x20new\x20Progress\x20objects.'),'publish':z['boolean']()['optional']()['describe']('Whether\x20to\x20publish\x20the\x20object.\x20After\x20the\x20object\x20is\x20published,\x20new\x20Progress\x20objects\x20can\x20be\x20generated;\x20and\x20node\x20settings\x20will\x20no\x20longer\x20be\x20changeable.'),'owner_receive':ReceivedObjectsOrRecentlySchema['optional']()['describe']('Unwrap\x20CoinWrapper\x20objects\x20and\x20other\x20objects\x20received\x20by\x20this\x20object\x20and\x20send\x20them\x20to\x20the\x20owner\x20of\x20its\x20Permission\x20object.'),'um':z['union']([z['string'](),z['null']()])['optional']()['describe']('Contact\x20object.')})['strict']()['describe']('On-chain\x20Machine\x20operations.\x20USAGE:\x20(1)\x20CREATE\x20NEW:\x20Set\x20\x27object\x27\x20field\x20with\x20OBJECT\x20format\x20{name,\x20permission,\x20...}\x20to\x20create\x20a\x20Machine.\x20NOTE:\x20\x27name\x27\x20goes\x20INSIDE\x20\x27object\x27,\x20NOT\x20at\x20the\x20data\x20root\x20level.\x20\x27permission\x27\x20can\x20be\x20a\x20new\x20Permission\x20object\x20or\x20reference\x20an\x20existing\x20one\x20-\x20check\x20\x27object\x27\x20field\x20description\x20for\x20details.\x20(2)\x20OPERATE\x20EXISTING:\x20Set\x20\x27object\x27\x20field\x20with\x20STRING\x20format\x20(object\x20ID\x20or\x20name).\x20The\x20\x27object\x27\x20field\x20is\x20CRITICAL\x20and\x20REQUIRED\x20in\x20both\x20cases.\x20STRING\x20for\x20existing,\x20OBJECT\x20for\x20new\x20creation.');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\x20object\x20ID\x20or\x20name\x20to\x20export'),'file_path':z['string']()['describe']('Output\x20file\x20path\x20(absolute\x20or\x20relative)'),'format':z['enum'](['json','markdown'])['optional']()['describe']('Output\x20format:\x20\x27json\x27\x20(default)\x20or\x20\x27markdown\x27'),'env':CallEnvSchema['optional']()})['strict']()['describe']('Query\x20a\x20Machine\x20object\x20from\x20the\x20blockchain\x20and\x20export\x20its\x20node\x20definition\x20to\x20a\x20JSON\x20or\x20Markdown\x20file.\x20The\x20exported\x20file\x20can\x20be\x20edited\x20and\x20used\x20to\x20create\x20new\x20Machine\x20objects.');export const MachineNode2File_OutputSchema=z['discriminatedUnion']('status',[z['object']({'status':z['literal']('success'),'data':z['object']({'file_path':z['string']()['describe']('Absolute\x20path\x20of\x20the\x20exported\x20file'),'format':z['enum'](['json','markdown'])['describe']('Export\x20format'),'machine_object':NameOrAddressSchema['describe']('Machine\x20object\x20ID'),'node_count':z['number']()['describe']('Number\x20of\x20nodes\x20exported')})['strict']()['describe']('Success\x20result\x20data')})['strict'](),z['object']({'status':z['literal']('error'),'error':z['string']()['describe']('Error\x20message')})['strict']()])['describe']('MachineNode2File\x20operation\x20output');export const MachineNode2File_OutputWrappedSchema=z['object']({'result':MachineNode2File_OutputSchema})['strict']()['describe']('MachineNode2File\x20operation\x20output\x20wrapped\x20schema');
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { WithPermissionObjectSchema, NamedObjectSchema, ObjectsSchema, CallEnvSchema, SubmissionCallSchema, } from './base.js';
|
|
3
|
+
import { MachineNodeSchema, PermissionIndexTypeSchema } from '../query/index.js';
|
|
4
|
+
import { ManyAccountOrMark_AddressSchema, NameOrAddressSchema, NameSchema, NotEmptyNameSchema, ReceivedObjectsOrRecentlySchema } from '../common/index.js';
|
|
5
|
+
export const ProgressNamedOperatorSchema = z.object({
|
|
6
|
+
op: z.union([z.literal('add'), z.literal('set'), z.literal('remove')]),
|
|
7
|
+
name: NotEmptyNameSchema,
|
|
8
|
+
operators: ManyAccountOrMark_AddressSchema,
|
|
9
|
+
}).strict();
|
|
10
|
+
export const ProgressNewSchema = z.object({
|
|
11
|
+
task: z.union([NameOrAddressSchema, z.null()]).optional().describe('Task bound to the Progress object. It is an object ID or name'),
|
|
12
|
+
repository: ObjectsSchema.optional().describe('Set repository list for the Progress object. Used for consensus data management.'),
|
|
13
|
+
progress_namedOperator: ProgressNamedOperatorSchema.optional().describe('Add, set, and remove operators for the permission namespace of the Progress object.'),
|
|
14
|
+
namedNew: NamedObjectSchema.optional(),
|
|
15
|
+
}).strict();
|
|
16
|
+
export const NodeAddForwardDataSchema = z.object({
|
|
17
|
+
prior_node_name: NameSchema.describe('Name of the previous node.'),
|
|
18
|
+
node_name: NameSchema.describe('Name of the next node.'),
|
|
19
|
+
forward: z.array(z.object({
|
|
20
|
+
name: NameSchema.describe('Name of the operation'),
|
|
21
|
+
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.'),
|
|
22
|
+
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.'),
|
|
23
|
+
weight: z.number().min(0).max(65535).int().describe('Weight of the operation'),
|
|
24
|
+
}).strict()).describe('List of operations between the previous and next nodes.'),
|
|
25
|
+
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.'),
|
|
26
|
+
}).strict();
|
|
27
|
+
export const NodeRemoveForwardDataSchema = z.object({
|
|
28
|
+
prior_node_name: NameSchema.describe('Name of the previous node.'),
|
|
29
|
+
node_name: NameSchema.describe('Name of the next node.'),
|
|
30
|
+
forward_name: z.array(NameSchema).describe('List of operation names to delete.'),
|
|
31
|
+
}).strict();
|
|
32
|
+
export const NodeRemovePriorNodeDataSchema = z.object({
|
|
33
|
+
prior_node_name: z.array(NameSchema).describe('List of previous node names to delete.'),
|
|
34
|
+
node_name: NameSchema.describe('Name of the next node.'),
|
|
35
|
+
}).strict();
|
|
36
|
+
export const NodeSchema = z.discriminatedUnion('op', [
|
|
37
|
+
z.object({
|
|
38
|
+
op: z.literal('add'),
|
|
39
|
+
nodes: z.array(MachineNodeSchema).describe('List of nodes to add or set.'),
|
|
40
|
+
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.'),
|
|
41
|
+
}).strict().describe('Add nodes.'),
|
|
42
|
+
z.object({
|
|
43
|
+
op: z.literal('set'),
|
|
44
|
+
nodes: z.array(MachineNodeSchema).describe('List of nodes to add or set.'),
|
|
45
|
+
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.'),
|
|
46
|
+
}).strict().describe('Set nodes.'),
|
|
47
|
+
z.object({
|
|
48
|
+
op: z.literal('remove'),
|
|
49
|
+
nodes: z.array(NameSchema).describe('List of node names to delete.'),
|
|
50
|
+
}).strict().describe('Delete nodes.'),
|
|
51
|
+
z.object({
|
|
52
|
+
op: z.literal('clear'),
|
|
53
|
+
}).strict().describe('Clear all nodes.'),
|
|
54
|
+
z.object({
|
|
55
|
+
op: z.literal('exchange'),
|
|
56
|
+
node_one: NameSchema.describe('Name of the first node.'),
|
|
57
|
+
node_other: NameSchema.describe('Name of the second node.'),
|
|
58
|
+
}).strict().describe('Exchange the positions of two nodes.'),
|
|
59
|
+
z.object({
|
|
60
|
+
op: z.literal('rename'),
|
|
61
|
+
node_name_old: NameSchema.describe('Name of thenode.'),
|
|
62
|
+
node_name_new: NameSchema.describe('New name of the node.'),
|
|
63
|
+
}).strict().describe('Rename node.'),
|
|
64
|
+
z.object({
|
|
65
|
+
op: z.literal('remove prior node'),
|
|
66
|
+
pairs: z.array(NodeRemovePriorNodeDataSchema).describe('List of previous-next node pairs to delete.'),
|
|
67
|
+
}).strict().describe('Delete previous-next node pairs.'),
|
|
68
|
+
z.object({
|
|
69
|
+
op: z.literal('add forward'),
|
|
70
|
+
data: z.array(NodeAddForwardDataSchema).describe('List of operations to add.'),
|
|
71
|
+
}).strict().describe('Add operations.'),
|
|
72
|
+
z.object({
|
|
73
|
+
op: z.literal('remove forward'),
|
|
74
|
+
data: z.array(NodeRemoveForwardDataSchema).describe('List of operations to delete.'),
|
|
75
|
+
}).strict().describe('Delete operations.'),
|
|
76
|
+
]);
|
|
77
|
+
export const NodeJsonOrMarkdownFileSchema = z.object({
|
|
78
|
+
json_or_markdown_file: z.string().describe(`Path to a JSON or Markdown file containing node array for COMPLETE REPLACEMENT of all nodes.
|
|
79
|
+
|
|
80
|
+
**File Format Requirements:**
|
|
81
|
+
- Must contain a JSON ARRAY of node objects: [{"name": "...", "pairs": [...]}, {...}]
|
|
82
|
+
- NOT an operation object with "op" field (use NodeSchema for operations)
|
|
83
|
+
- Supports JSON or Markdown (with \`\`\`json code blocks)
|
|
84
|
+
|
|
85
|
+
**Node Structure:**
|
|
86
|
+
Each node is a directed graph element representing workflow states and transitions:
|
|
87
|
+
- name: Node identifier
|
|
88
|
+
- pairs: Array of {prior_node, forwards, threshold} defining connections
|
|
89
|
+
- forwards: Operations available from this node
|
|
90
|
+
- threshold: Required weight to advance
|
|
91
|
+
|
|
92
|
+
**Behavior:**
|
|
93
|
+
- COMPLETELY REPLACES all existing nodes (equivalent to "set" with bReplace=true)
|
|
94
|
+
- Auto-detects format based on file content
|
|
95
|
+
- If parsing fails, error includes line number and column information`),
|
|
96
|
+
}).strict();
|
|
97
|
+
export const NodeFieldSchema = z.union([
|
|
98
|
+
NodeSchema,
|
|
99
|
+
NodeJsonOrMarkdownFileSchema,
|
|
100
|
+
]);
|
|
101
|
+
export const CallMachine_DataSchema = z.object({
|
|
102
|
+
object: WithPermissionObjectSchema,
|
|
103
|
+
progress_new: ProgressNewSchema.optional().describe('Generate new Progress object.'),
|
|
104
|
+
description: z.string().optional().describe('Description of the object.'),
|
|
105
|
+
repository: ObjectsSchema.optional().describe('Set repository list for the object. Used for consensus data management.'),
|
|
106
|
+
node: NodeFieldSchema.optional().describe(`CRITICAL: Choose ONE of two mutually exclusive modes:
|
|
107
|
+
|
|
108
|
+
**Mode 1: NodeSchema (incremental operations)**
|
|
109
|
+
Use for partial modifications: add, set, remove, clear, exchange, rename, remove prior node, add forward, remove forward.
|
|
110
|
+
Format: { "op": "add", "nodes": [...], "bReplace": false }
|
|
111
|
+
This mode modifies existing nodes incrementally.
|
|
112
|
+
|
|
113
|
+
**Mode 2: NodeJsonOrMarkdownFileSchema (complete replacement)**
|
|
114
|
+
Use for complete node redefinition from file.
|
|
115
|
+
Format: { "json_or_markdown_file": "/path/to/nodes.json" }
|
|
116
|
+
IMPORTANT: This COMPLETELY REPLACES all existing nodes. File must contain node array [{...}, {...}], NOT an operation object with "op" field.
|
|
117
|
+
Supported formats: JSON array or Markdown with code blocks.
|
|
118
|
+
If parsing fails, error includes line number and column information.`),
|
|
119
|
+
pause: z.boolean().optional().describe('Whether to pause generating new Progress objects.'),
|
|
120
|
+
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.'),
|
|
121
|
+
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.'),
|
|
122
|
+
um: z.union([z.string(), z.null()]).optional().describe('Contact object.'),
|
|
123
|
+
}).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.");
|
|
124
|
+
export const CallMachine_InputSchema = z.object({
|
|
125
|
+
data: CallMachine_DataSchema,
|
|
126
|
+
env: CallEnvSchema.optional(),
|
|
127
|
+
submission: SubmissionCallSchema.optional(),
|
|
128
|
+
}).strict();
|
|
129
|
+
export const MachineNode2File_InputSchema = z.object({
|
|
130
|
+
machine: NameOrAddressSchema.describe("Machine object ID or name to export"),
|
|
131
|
+
file_path: z.string().describe("Output file path (absolute or relative)"),
|
|
132
|
+
format: z.enum(["json", "markdown"]).optional().describe("Output format: 'json' (default) or 'markdown'"),
|
|
133
|
+
env: CallEnvSchema.optional(),
|
|
134
|
+
}).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.");
|
|
135
|
+
export const MachineNode2File_OutputSchema = z.discriminatedUnion("status", [
|
|
136
|
+
z.object({
|
|
137
|
+
status: z.literal("success"),
|
|
138
|
+
data: z.object({
|
|
139
|
+
file_path: z.string().describe("Absolute path of the exported file"),
|
|
140
|
+
format: z.enum(["json", "markdown"]).describe("Export format"),
|
|
141
|
+
machine_object: NameOrAddressSchema.describe("Machine object ID"),
|
|
142
|
+
node_count: z.number().describe("Number of nodes exported"),
|
|
143
|
+
}).strict().describe("Success result data"),
|
|
144
|
+
}).strict(),
|
|
145
|
+
z.object({
|
|
146
|
+
status: z.literal("error"),
|
|
147
|
+
error: z.string().describe("Error message"),
|
|
148
|
+
}).strict(),
|
|
149
|
+
]).describe("MachineNode2File operation output");
|
|
150
|
+
export const MachineNode2File_OutputWrappedSchema = z.object({
|
|
151
|
+
result: MachineNode2File_OutputSchema,
|
|
152
|
+
}).strict().describe("MachineNode2File operation output wrapped schema");
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CallEnvSchema, SubmissionCallSchema } from "./base.js";
|
|
3
|
+
import { OperateSchema } from "./progress.js";
|
|
4
|
+
import { AccountOrMark_AddressSchema, DescriptionSchema, LongNameSchema, ManyAccountOrMark_AddressSchema, NameOrAddressSchema } from "../common/index.js";
|
|
5
|
+
import { QueryReceivedResultSchema } from "../common/index.js";
|
|
6
|
+
export const ArbConfirmSchema = z.object({
|
|
7
|
+
arb: NameOrAddressSchema.describe("Arb object ID or name."),
|
|
8
|
+
confirm: z.boolean().describe("Whether to confirm that the submitted arbitration materials are valid for arbitration."),
|
|
9
|
+
description: DescriptionSchema.optional().describe("Message description for compensation application."),
|
|
10
|
+
proposition: z.array(LongNameSchema).optional().describe("Compensation claims.")
|
|
11
|
+
}).strict();
|
|
12
|
+
export const ArbObjectionSchema = z.object({
|
|
13
|
+
arb: NameOrAddressSchema.describe("Arb object ID or name."),
|
|
14
|
+
objection: DescriptionSchema.describe("Oppose and appeal the arbitration result, request re-arbitration"),
|
|
15
|
+
}).strict();
|
|
16
|
+
export const ArbClaimCompensationSchema = z.object({
|
|
17
|
+
arb: NameOrAddressSchema.describe("Arb object ID or name."),
|
|
18
|
+
}).strict();
|
|
19
|
+
export const CallOrder_DataSchema = z.object({
|
|
20
|
+
object: NameOrAddressSchema.describe("Order object ID or name."),
|
|
21
|
+
agents: ManyAccountOrMark_AddressSchema.optional().describe("Order agents. Agents can operate the order, such as canceling the order, modifying the order status, etc.; but cannot receive the funds received by the order."),
|
|
22
|
+
required_info: z.union([NameOrAddressSchema, z.null()]).optional().describe("Contact object ID (recipient) or WTS Proof object (delivery proof) that information has been delivered via Wowok Messenger."),
|
|
23
|
+
progress: OperateSchema.optional().describe("Advance order process"),
|
|
24
|
+
arb_confirm: ArbConfirmSchema.optional().describe("Submit compensation request and apply for arbitration"),
|
|
25
|
+
arb_objection: ArbObjectionSchema.optional().describe("Oppose and appeal the arbitration result, request re-arbitration."),
|
|
26
|
+
arb_claim_compensation: ArbClaimCompensationSchema.optional().describe("Specify the adjudicated Arb object to obtain order compensation."),
|
|
27
|
+
receive: QueryReceivedResultSchema.optional().describe("Unwrap CoinWrapper objects or other objects received by the order and transfer them to the order owner"),
|
|
28
|
+
transfer_to: AccountOrMark_AddressSchema.optional().describe("Set new owner of the order. Requires order owner permission to set."),
|
|
29
|
+
}).strict().describe("On-chain, operate on an Order object.");
|
|
30
|
+
export const CallOrder_InputSchema = z.object({
|
|
31
|
+
data: CallOrder_DataSchema,
|
|
32
|
+
env: CallEnvSchema.optional(),
|
|
33
|
+
submission: SubmissionCallSchema.optional(),
|
|
34
|
+
}).strict();
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PaymentInfoSchema } from "../query/index.js";
|
|
3
|
+
import { CoinParamSchema, CallEnvSchema, TypeNamedObjectSchema } from "./base.js";
|
|
4
|
+
import { AccountOrMark_AddressSchema } from "../common/index.js";
|
|
5
|
+
export const RevenueSchema = z.object({
|
|
6
|
+
recipient: AccountOrMark_AddressSchema,
|
|
7
|
+
amount: CoinParamSchema
|
|
8
|
+
}).strict().describe("Payment recipient and amount");
|
|
9
|
+
export const CallPayment_DataSchema = z.object({
|
|
10
|
+
object: TypeNamedObjectSchema,
|
|
11
|
+
revenue: z.array(RevenueSchema).describe("Array of payment recipients and amounts"),
|
|
12
|
+
info: PaymentInfoSchema
|
|
13
|
+
}).strict().describe("On-chain Payment creation. USAGE: Set 'object' field with {name, type, ...} to create a named Payment. NOTE: 'name' goes INSIDE 'object', NOT at the data root level. Payment is an immutable object - it can only be created, not modified. The 'object' field is CRITICAL and REQUIRED.");
|
|
14
|
+
export const CallPayment_InputSchema = z.object({
|
|
15
|
+
data: CallPayment_DataSchema,
|
|
16
|
+
env: CallEnvSchema.optional(),
|
|
17
|
+
}).strict();
|
|
@@ -1 +1,105 @@
|
|
|
1
|
-
import{z}from'zod';import{PermissionIndexTypeSchema}from'../query/index.js';import{CallEnvSchema,SubmissionCallSchema,NormalObjectSchema}from'./base.js';import{AccountOrMark_AddressSchema,DescriptionSchema,LongNameSchema,ManyAccountOrMark_AddressSchema,NameOrAddressSchema,ReceivedObjectsOrRecentlySchema}from'../common/index.js';export const RemarkSetSchema=z['object']({'op':z['literal']('set'),'index':PermissionIndexTypeSchema,'remark':LongNameSchema['describe']('Permission\x20remark.')})['strict']()['describe']('Set\x20remark\x20for\x20a\x20permission.');export const RemarkRemoveSchema=z['object']({'op':z['literal']('remove'),'index':PermissionIndexTypeSchema})['strict']()['describe']('Remove\x20remark\x20for\x20a\x20permission.');export const RemarkClearSchema=z['object']({'op':z['literal']('clear')})['strict']()['describe']('Clear\x20remarks\x20for\x20all\x20permissions.');export const RemarkSchema=z['discriminatedUnion']('op',[RemarkSetSchema,RemarkRemoveSchema,RemarkClearSchema])['describe']('Set\x20remarks\x20for\x20permissions.');export const TablePermByIndexSchema=z['discriminatedUnion']('op',[z['object']({'op':z['literal']('add\x20perm\x20by\x20index'),'index':PermissionIndexTypeSchema,'entity':ManyAccountOrMark_AddressSchema})['strict']()['describe']('Grant\x20a\x20specific\x20permission\x20to\x20multiple\x20entities\x20at\x20once.\x20USE\x20WHEN:\x20You\x20need\x20to\x20assign\x20the\x20SAME\x20permission\x20to\x20MULTIPLE\x20users/Guards.\x20Example:\x20Give\x20\x27create\x20service\x27\x20permission\x20to\x20Alice,\x20Bob,\x20and\x20Carol\x20simultaneously.'),z['object']({'op':z['literal']('set\x20perm\x20by\x20index'),'index':PermissionIndexTypeSchema,'entity':ManyAccountOrMark_AddressSchema})['strict']()['describe']('Replace\x20the\x20entity\x20list\x20for\x20a\x20specific\x20permission\x20with\x20a\x20new\x20set\x20of\x20entities.\x20USE\x20WHEN:\x20You\x20want\x20to\x20completely\x20redefine\x20WHO\x20has\x20this\x20permission.\x20WARNING:\x20This\x20overwrites\x20the\x20existing\x20entity\x20list\x20for\x20this\x20permission.'),z['object']({'op':z['literal']('remove\x20perm\x20by\x20index'),'index':PermissionIndexTypeSchema,'entity':ManyAccountOrMark_AddressSchema})['strict']()['describe']('Revoke\x20a\x20specific\x20permission\x20from\x20multiple\x20entities\x20at\x20once.\x20USE\x20WHEN:\x20You\x20need\x20to\x20remove\x20the\x20SAME\x20permission\x20from\x20MULTIPLE\x20users/Guards.\x20Example:\x20Remove\x20\x27create\x20service\x27\x20permission\x20from\x20Alice,\x20Bob,\x20and\x20Carol\x20simultaneously.')])['describe']('Permission-centric\x20operations:\x20Manage\x20WHO\x20has\x20a\x20specific\x20permission.\x20Best\x20for\x20batch-assigning\x20one\x20permission\x20to\x20many\x20users.\x20Structure:\x20{op:\x20\x27add|set|remove\x20perm\x20by\x20index\x27,\x20index:\x20permission_id,\x20entity:\x20[user1,\x20user2,\x20...]}');export const TablePermByEntitySchema=z['discriminatedUnion']('op',[z['object']({'op':z['literal']('add\x20perm\x20by\x20entity'),'entity':AccountOrMark_AddressSchema,'index':z['array'](PermissionIndexTypeSchema)})['strict']()['describe']('Grant\x20multiple\x20permissions\x20to\x20a\x20single\x20entity.\x20USE\x20WHEN:\x20You\x20need\x20to\x20give\x20ONE\x20user/Guard\x20MANY\x20permissions\x20at\x20once.\x20Example:\x20Give\x20Alice\x20all\x20Machine-related\x20permissions\x20(create,\x20edit,\x20publish,\x20pause,\x20etc.)\x20in\x20one\x20call.'),z['object']({'op':z['literal']('set\x20perm\x20by\x20entity'),'entity':AccountOrMark_AddressSchema,'index':z['array'](PermissionIndexTypeSchema)})['strict']()['describe']('Replace\x20all\x20permissions\x20of\x20a\x20single\x20entity\x20with\x20a\x20new\x20permission\x20set.\x20USE\x20WHEN:\x20You\x20want\x20to\x20completely\x20redefine\x20WHAT\x20permissions\x20a\x20user/Guard\x20has.\x20WARNING:\x20This\x20overwrites\x20all\x20existing\x20permissions\x20for\x20this\x20entity.'),z['object']({'op':z['literal']('remove\x20perm\x20by\x20entity'),'entity':AccountOrMark_AddressSchema,'index':z['array'](PermissionIndexTypeSchema)})['strict']()['describe']('Revoke\x20multiple\x20permissions\x20from\x20a\x20single\x20entity.\x20USE\x20WHEN:\x20You\x20need\x20to\x20remove\x20MANY\x20permissions\x20from\x20ONE\x20user/Guard\x20at\x20once.\x20Example:\x20Remove\x20all\x20Machine-related\x20permissions\x20from\x20Alice.')])['describe']('Entity-centric\x20operations:\x20Manage\x20WHAT\x20permissions\x20a\x20specific\x20user/Guard\x20has.\x20Best\x20for\x20assigning\x20many\x20permissions\x20to\x20one\x20user.\x20Structure:\x20{op:\x20\x27add|set|remove\x20perm\x20by\x20entity\x27,\x20entity:\x20user_id,\x20index:\x20[perm1,\x20perm2,\x20...]}');export const TableSchema=z['discriminatedUnion']('op',[...TablePermByIndexSchema['options'],...TablePermByEntitySchema['options']])['describe']('Manage\x20permission\x20assignments\x20using\x20two\x20complementary\x20approaches.\x20CHOOSE\x20THE\x20RIGHT\x20APPROACH:\x20(1)\x20\x27perm\x20by\x20index\x27\x20-\x20Use\x20when\x20granting\x20ONE\x20permission\x20to\x20MANY\x20users\x20(permission-centric).\x20Example:\x20Give\x20\x27create\x20service\x27\x20permission\x20to\x20Alice,\x20Bob,\x20and\x20Carol.\x20(2)\x20\x27perm\x20by\x20entity\x27\x20-\x20Use\x20when\x20granting\x20MANY\x20permissions\x20to\x20ONE\x20user\x20(entity-centric).\x20Example:\x20Give\x20Alice\x20all\x20Machine-related\x20permissions.\x20Both\x20approaches\x20support\x20add/set/remove\x20operations.\x20Requires\x20admin\x20permission.');export const EntitySwapReplaceCopySchema=z['discriminatedUnion']('op',[z['object']({'op':z['literal']('swap'),'entity1':AccountOrMark_AddressSchema,'entity2':AccountOrMark_AddressSchema})['strict']()['describe']('Swap\x20all\x20permission\x20indexes\x20between\x20two\x20entities.'),z['object']({'op':z['literal']('replace'),'entity1':AccountOrMark_AddressSchema,'entity2':AccountOrMark_AddressSchema})['strict']()['describe']('Remove\x20all\x20permission\x20indexes\x20from\x20entity1\x20and\x20add\x20them\x20to\x20entity2\x27s\x20permission\x20indexes.'),z['object']({'op':z['literal']('copy'),'entity1':AccountOrMark_AddressSchema,'entity2':AccountOrMark_AddressSchema})['strict']()['describe']('Add\x20all\x20permission\x20indexes\x20from\x20entity1\x20to\x20entity2\x27s\x20permission\x20indexes.')]);export const EntityDelSchema=z['object']({'op':z['literal']('del'),'entity':AccountOrMark_AddressSchema})['strict']()['describe']('Delete\x20all\x20permission\x20indexes\x20from\x20an\x20entity.');export const EntitySchema=z['discriminatedUnion']('op',[...EntitySwapReplaceCopySchema['options'],EntityDelSchema]);export const AdminSchema=z['object']({'op':z['enum'](['add','remove','set'])['describe']('Admin\x20operations:\x20add,\x20remove,\x20set.'),'addresses':ManyAccountOrMark_AddressSchema['describe']('List\x20of\x20admin\x20addresses.')})['strict']();export const CallPermission_DataSchema=z['object']({'object':NormalObjectSchema['optional'](),'description':DescriptionSchema['optional'](),'remark':RemarkSchema['optional'](),'table':TableSchema['optional']()['describe']('Manage\x20permission\x20assignments\x20using\x20two\x20approaches:\x20(1)\x20By\x20Permission\x20Index\x20-\x20add/set/remove\x20entity\x20IDs\x20for\x20a\x20specific\x20permission;\x20(2)\x20By\x20Entity\x20-\x20add/set/remove\x20permission\x20indexes\x20for\x20a\x20specific\x20entity.\x20Requires\x20admin\x20permission.'),'entity':EntitySchema['optional']()['describe']('Advanced\x20entity\x20permission\x20operations:\x20swap\x20permissions\x20between\x20two\x20entities,\x20replace\x20one\x20entity\x27s\x20permissions\x20with\x20another\x27s,\x20copy\x20permissions\x20from\x20one\x20entity\x20to\x20another,\x20or\x20delete\x20all\x20permissions\x20of\x20an\x20entity.\x20Entity\x20can\x20be\x20a\x20user\x20ID\x20or\x20Guard\x20object\x20ID.\x20Requires\x20admin\x20permission.'),'admin':AdminSchema['optional']()['describe']('Manage\x20Permission\x20object\x20admins:\x20add\x20new\x20admins,\x20remove\x20existing\x20admins,\x20or\x20set\x20the\x20complete\x20admin\x20list.\x20Only\x20the\x20Permission\x20object\x20owner\x20(builder)\x20can\x20perform\x20this\x20operation.\x20The\x20creator\x20automatically\x20becomes\x20an\x20admin\x20with\x20full\x20permissions.'),'apply':z['array'](NameOrAddressSchema)['optional']()['describe']('Array\x20of\x20object\x20IDs\x20or\x20names\x20to\x20operate\x20on,\x20apply\x20the\x20Permission\x20object\x20to\x20these\x20objects\x27\x20permission\x20control.\x20Note:\x20The\x20signer\x20must\x20be\x20the\x20owner\x20of\x20the\x20existing\x20Permission\x20objects\x20for\x20these\x20objects'),'builder':AccountOrMark_AddressSchema['optional']()['describe']('Set\x20or\x20transfer\x20ownership\x20of\x20the\x20Permission\x20object\x20to\x20the\x20specified\x20user\x20ID.\x20The\x20creator\x20automatically\x20becomes\x20the\x20builder;\x20only\x20the\x20builder\x20can\x20transfer\x20ownership\x20to\x20other\x20users.'),'owner_receive':ReceivedObjectsOrRecentlySchema['optional']()['describe']('Unwrap\x20CoinWrapper\x20objects\x20and\x20other\x20objects\x20received\x20by\x20this\x20object\x20and\x20send\x20them\x20to\x20the\x20builder(owner).'),'um':z['union']([NameOrAddressSchema,z['null']()])['optional']()['describe']('Contact\x20object.')})['strict']()['describe']('On-chain\x20Permission\x20operations.\x20USAGE:\x20(1)\x20CREATE\x20NEW:\x20Set\x20\x27object\x27\x20field\x20with\x20OBJECT\x20format\x20{name,\x20tags?,\x20...}\x20to\x20create\x20a\x20Permission.\x20NOTE:\x20\x27name\x27\x20goes\x20INSIDE\x20\x27object\x27,\x20NOT\x20at\x20the\x20data\x20root\x20level.\x20(2)\x20OPERATE\x20EXISTING:\x20Set\x20\x27object\x27\x20field\x20with\x20STRING\x20format\x20(object\x20ID\x20or\x20name).\x20The\x20\x27object\x27\x20field\x20is\x20CRITICAL\x20and\x20REQUIRED\x20in\x20both\x20cases.\x20STRING\x20for\x20existing,\x20OBJECT\x20for\x20new\x20creation.');export const CallPermission_InputSchema=z['object']({'data':CallPermission_DataSchema,'env':CallEnvSchema['optional'](),'submission':SubmissionCallSchema['optional']()})['strict']();
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PermissionIndexTypeSchema } from "../query/index.js";
|
|
3
|
+
import { CallEnvSchema, SubmissionCallSchema, NormalObjectSchema } from "./base.js";
|
|
4
|
+
import { AccountOrMark_AddressSchema, DescriptionSchema, LongNameSchema, ManyAccountOrMark_AddressSchema, NameOrAddressSchema, ReceivedObjectsOrRecentlySchema } from "../common/index.js";
|
|
5
|
+
export const RemarkSetSchema = z.object({
|
|
6
|
+
op: z.literal("set"),
|
|
7
|
+
index: PermissionIndexTypeSchema,
|
|
8
|
+
remark: LongNameSchema.describe("Permission remark.")
|
|
9
|
+
}).strict().describe("Set remark for a permission.");
|
|
10
|
+
export const RemarkRemoveSchema = z.object({
|
|
11
|
+
op: z.literal("remove"),
|
|
12
|
+
index: PermissionIndexTypeSchema
|
|
13
|
+
}).strict().describe("Remove remark for a permission.");
|
|
14
|
+
export const RemarkClearSchema = z.object({
|
|
15
|
+
op: z.literal("clear")
|
|
16
|
+
}).strict().describe("Clear remarks for all permissions.");
|
|
17
|
+
export const RemarkSchema = z.discriminatedUnion("op", [
|
|
18
|
+
RemarkSetSchema,
|
|
19
|
+
RemarkRemoveSchema,
|
|
20
|
+
RemarkClearSchema
|
|
21
|
+
]).describe("Set remarks for permissions.");
|
|
22
|
+
export const TablePermByIndexSchema = z.discriminatedUnion("op", [
|
|
23
|
+
z.object({
|
|
24
|
+
op: z.literal("add perm by index"),
|
|
25
|
+
index: PermissionIndexTypeSchema,
|
|
26
|
+
entity: ManyAccountOrMark_AddressSchema
|
|
27
|
+
}).strict().describe("Grant a specific permission to multiple entities at once. USE WHEN: You need to assign the SAME permission to MULTIPLE users/Guards. Example: Give 'create service' permission to Alice, Bob, and Carol simultaneously."),
|
|
28
|
+
z.object({
|
|
29
|
+
op: z.literal("set perm by index"),
|
|
30
|
+
index: PermissionIndexTypeSchema,
|
|
31
|
+
entity: ManyAccountOrMark_AddressSchema
|
|
32
|
+
}).strict().describe("Replace the entity list for a specific permission with a new set of entities. USE WHEN: You want to completely redefine WHO has this permission. WARNING: This overwrites the existing entity list for this permission."),
|
|
33
|
+
z.object({
|
|
34
|
+
op: z.literal("remove perm by index"),
|
|
35
|
+
index: PermissionIndexTypeSchema,
|
|
36
|
+
entity: ManyAccountOrMark_AddressSchema
|
|
37
|
+
}).strict().describe("Revoke a specific permission from multiple entities at once. USE WHEN: You need to remove the SAME permission from MULTIPLE users/Guards. Example: Remove 'create service' permission from Alice, Bob, and Carol simultaneously."),
|
|
38
|
+
]).describe("Permission-centric operations: Manage WHO has a specific permission. Best for batch-assigning one permission to many users. Structure: {op: 'add|set|remove perm by index', index: permission_id, entity: [user1, user2, ...]}");
|
|
39
|
+
export const TablePermByEntitySchema = z.discriminatedUnion("op", [
|
|
40
|
+
z.object({
|
|
41
|
+
op: z.literal("add perm by entity"),
|
|
42
|
+
entity: AccountOrMark_AddressSchema,
|
|
43
|
+
index: z.array(PermissionIndexTypeSchema)
|
|
44
|
+
}).strict().describe("Grant multiple permissions to a single entity. USE WHEN: You need to give ONE user/Guard MANY permissions at once. Example: Give Alice all Machine-related permissions (create, edit, publish, pause, etc.) in one call."),
|
|
45
|
+
z.object({
|
|
46
|
+
op: z.literal("set perm by entity"),
|
|
47
|
+
entity: AccountOrMark_AddressSchema,
|
|
48
|
+
index: z.array(PermissionIndexTypeSchema)
|
|
49
|
+
}).strict().describe("Replace all permissions of a single entity with a new permission set. USE WHEN: You want to completely redefine WHAT permissions a user/Guard has. WARNING: This overwrites all existing permissions for this entity."),
|
|
50
|
+
z.object({
|
|
51
|
+
op: z.literal("remove perm by entity"),
|
|
52
|
+
entity: AccountOrMark_AddressSchema,
|
|
53
|
+
index: z.array(PermissionIndexTypeSchema)
|
|
54
|
+
}).strict().describe("Revoke multiple permissions from a single entity. USE WHEN: You need to remove MANY permissions from ONE user/Guard at once. Example: Remove all Machine-related permissions from Alice."),
|
|
55
|
+
]).describe("Entity-centric operations: Manage WHAT permissions a specific user/Guard has. Best for assigning many permissions to one user. Structure: {op: 'add|set|remove perm by entity', entity: user_id, index: [perm1, perm2, ...]}");
|
|
56
|
+
export const TableSchema = z.discriminatedUnion("op", [
|
|
57
|
+
...TablePermByIndexSchema.options,
|
|
58
|
+
...TablePermByEntitySchema.options
|
|
59
|
+
]).describe("Manage permission assignments using two complementary approaches. CHOOSE THE RIGHT APPROACH: (1) 'perm by index' - Use when granting ONE permission to MANY users (permission-centric). Example: Give 'create service' permission to Alice, Bob, and Carol. (2) 'perm by entity' - Use when granting MANY permissions to ONE user (entity-centric). Example: Give Alice all Machine-related permissions. Both approaches support add/set/remove operations. Requires admin permission.");
|
|
60
|
+
export const EntitySwapReplaceCopySchema = z.discriminatedUnion("op", [
|
|
61
|
+
z.object({
|
|
62
|
+
op: z.literal("swap"),
|
|
63
|
+
entity1: AccountOrMark_AddressSchema,
|
|
64
|
+
entity2: AccountOrMark_AddressSchema
|
|
65
|
+
}).strict().describe("Swap all permission indexes between two entities."),
|
|
66
|
+
z.object({
|
|
67
|
+
op: z.literal("replace"),
|
|
68
|
+
entity1: AccountOrMark_AddressSchema,
|
|
69
|
+
entity2: AccountOrMark_AddressSchema
|
|
70
|
+
}).strict().describe("Remove all permission indexes from entity1 and add them to entity2's permission indexes."),
|
|
71
|
+
z.object({
|
|
72
|
+
op: z.literal("copy"),
|
|
73
|
+
entity1: AccountOrMark_AddressSchema,
|
|
74
|
+
entity2: AccountOrMark_AddressSchema
|
|
75
|
+
}).strict().describe("Add all permission indexes from entity1 to entity2's permission indexes."),
|
|
76
|
+
]);
|
|
77
|
+
export const EntityDelSchema = z.object({
|
|
78
|
+
op: z.literal("del"),
|
|
79
|
+
entity: AccountOrMark_AddressSchema
|
|
80
|
+
}).strict().describe("Delete all permission indexes from an entity.");
|
|
81
|
+
export const EntitySchema = z.discriminatedUnion("op", [
|
|
82
|
+
...EntitySwapReplaceCopySchema.options,
|
|
83
|
+
EntityDelSchema
|
|
84
|
+
]);
|
|
85
|
+
export const AdminSchema = z.object({
|
|
86
|
+
op: z.enum(["add", "remove", "set"]).describe("Admin operations: add, remove, set."),
|
|
87
|
+
addresses: ManyAccountOrMark_AddressSchema.describe("List of admin addresses.")
|
|
88
|
+
}).strict();
|
|
89
|
+
export const CallPermission_DataSchema = z.object({
|
|
90
|
+
object: NormalObjectSchema.optional(),
|
|
91
|
+
description: DescriptionSchema.optional(),
|
|
92
|
+
remark: RemarkSchema.optional(),
|
|
93
|
+
table: TableSchema.optional().describe("Manage permission assignments using two approaches: (1) By Permission Index - add/set/remove entity IDs for a specific permission; (2) By Entity - add/set/remove permission indexes for a specific entity. Requires admin permission."),
|
|
94
|
+
entity: EntitySchema.optional().describe("Advanced entity permission operations: swap permissions between two entities, replace one entity's permissions with another's, copy permissions from one entity to another, or delete all permissions of an entity. Entity can be a user ID or Guard object ID. Requires admin permission."),
|
|
95
|
+
admin: AdminSchema.optional().describe("Manage Permission object admins: add new admins, remove existing admins, or set the complete admin list. Only the Permission object owner (builder) can perform this operation. The creator automatically becomes an admin with full permissions."),
|
|
96
|
+
apply: z.array(NameOrAddressSchema).optional().describe("Array of object IDs or names to operate on, apply the Permission object to these objects' permission control. Note: The signer must be the owner of the existing Permission objects for these objects"),
|
|
97
|
+
builder: AccountOrMark_AddressSchema.optional().describe("Set or transfer ownership of the Permission object to the specified user ID. The creator automatically becomes the builder; only the builder can transfer ownership to other users."),
|
|
98
|
+
owner_receive: ReceivedObjectsOrRecentlySchema.optional().describe('Unwrap CoinWrapper objects and other objects received by this object and send them to the builder(owner).'),
|
|
99
|
+
um: z.union([NameOrAddressSchema, z.null()]).optional().describe("Contact object."),
|
|
100
|
+
}).strict().describe("On-chain Permission operations. USAGE: (1) CREATE NEW: Set 'object' field with OBJECT format {name, tags?, ...} to create a Permission. NOTE: 'name' goes INSIDE 'object', NOT at the data root level. (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.");
|
|
101
|
+
export const CallPermission_InputSchema = z.object({
|
|
102
|
+
data: CallPermission_DataSchema,
|
|
103
|
+
env: CallEnvSchema.optional(),
|
|
104
|
+
submission: SubmissionCallSchema.optional(),
|
|
105
|
+
}).strict();
|