-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Add guide for implementing typescript agent #452
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: 271ali <[email protected]>
|
||
|
||
export const check = async(action: ScAddr,keynodes: Record<string, ScAddr>) => { | ||
const checkTemplate = new ScTemplate(); | ||
checkTemplate.triple( // класс_действия | ||
keynodes["get_set_power_action"], // | | ||
ScType.EdgeAccessVarPosPerm, // \/ | ||
action, // действие | ||
); | ||
const checkResult = await client.templateSearch(checkTemplate); | ||
if (checkResult.length==0) | ||
{ | ||
return false; | ||
|
||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const check = async(action: ScAddr,keynodes: Record<string, ScAddr>) => { | |
const checkTemplate = new ScTemplate(); | |
checkTemplate.triple( // класс_действия | |
keynodes["get_set_power_action"], // | | |
ScType.EdgeAccessVarPosPerm, // \/ | |
action, // действие | |
); | |
const checkResult = await client.templateSearch(checkTemplate); | |
if (checkResult.length==0) | |
{ | |
return false; | |
} | |
return true; | |
} | |
export const check = async(action: ScAddr,keynodes: Record<string, ScAddr>) => { | |
const checkTemplate = new ScTemplate(); | |
checkTemplate.triple( // класс_действия | |
keynodes["get_set_power_action"], // | | |
ScType.EdgeAccessVarPosPerm, // \/ | |
action, // действие | |
); | |
const checkResult = await client.templateSearch(checkTemplate); | |
return checkResult.length === 0; | |
} |
const actionFinishedSuccessfully = 'action_finished_successfully'; | ||
const actionFinishedUnsuccessfully = 'action_finished_unsuccessfully'; | ||
const nrelResult = 'nrel_result'; | ||
const nrelSetPower="nrel_set_power"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const nrelSetPower="nrel_set_power"; | |
const nrelSetPower = "nrel_set_power"; |
{ id: actionInitiated, type: ScType.NodeConstClass }, | ||
]; | ||
const keynodes = await client.resolveKeynodes(baseKeynodes); //собрали все кейноды из БЗ | ||
if(await check(actionNode,keynodes)===false) //сделали проверку на класс действия |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(await check(actionNode,keynodes)===false) //сделали проверку на класс действия | |
if (await check(actionNode,keynodes) === false) // сделали проверку на класс действия |
{ id: action, type: ScType.NodeConstClass }, | ||
{ id: actionInitiated, type: ScType.NodeConstClass }, | ||
]; | ||
const keynodes = await client.resolveKeynodes(baseKeynodes); //собрали все кейноды из БЗ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const keynodes = await client.resolveKeynodes(baseKeynodes); //собрали все кейноды из БЗ | |
const keynodes = await client.resolveKeynodes(baseKeynodes); // собрали все кейноды из БЗ |
const setAlias = '_set'; //узел множества | ||
const elAlias = '_el'; //узел элемента множества |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const setAlias = '_set'; //узел множества | |
const elAlias = '_el'; //узел элемента множества | |
const setAlias = '_set'; // узел множества | |
const elAlias = '_el'; // узел элемента множества |
const powerSetConstruction = new ScConstruction(); //конструкция,где будет только множество и его мощность | ||
const setPowerLinkAlias="set_power_link"; //метки для всех будущих элементов | ||
const edgeCommonSetPowerAlias="edge_common_set_power"; | ||
const edgePosPermSetPowerAlias="edge_pos_perm_set_power"; | ||
const resultConstructionNodeAlias="result_construction_node"; | ||
const edgePosPermResultAlias="edge_pos_perm_result"; | ||
const edgeCommonResultAlias="edge_common_result"; | ||
powerSetConstruction.createLink(ScType.LinkConst,new ScLinkContent(power, ScLinkContentType.String),setPowerLinkAlias);//создаем ссылку с числом ссылка |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const powerSetConstruction = new ScConstruction(); //конструкция,где будет только множество и его мощность | |
const setPowerLinkAlias="set_power_link"; //метки для всех будущих элементов | |
const edgeCommonSetPowerAlias="edge_common_set_power"; | |
const edgePosPermSetPowerAlias="edge_pos_perm_set_power"; | |
const resultConstructionNodeAlias="result_construction_node"; | |
const edgePosPermResultAlias="edge_pos_perm_result"; | |
const edgeCommonResultAlias="edge_common_result"; | |
powerSetConstruction.createLink(ScType.LinkConst,new ScLinkContent(power, ScLinkContentType.String),setPowerLinkAlias);//создаем ссылку с числом ссылка | |
const powerSetConstruction = new ScConstruction(); // конструкция,где будет только множество и его мощность | |
const setPowerLinkAlias = "set_power_link"; // метки для всех будущих элементов | |
const edgeCommonSetPowerAlias = "edge_common_set_power"; | |
const edgePosPermSetPowerAlias = "edge_pos_perm_set_power"; | |
const resultConstructionNodeAlias = "result_construction_node"; | |
const edgePosPermResultAlias = "edge_pos_perm_result"; | |
const edgeCommonResultAlias = "edge_common_result"; | |
powerSetConstruction.createLink(ScType.LinkConst, new ScLinkContent(power, ScLinkContentType.String), setPowerLinkAlias); // создаем ссылку с числом ссылка |
powerSetConstruction.createEdge(ScType.EdgeDCommonConst,set,setPowerLinkAlias,edgeCommonSetPowerAlias); //соединяем ее с множеством дугой для отношений /\ | ||
powerSetConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[nrelSetPower],edgeCommonSetPowerAlias,edgePosPermSetPowerAlias); //соедиянемя nrel_set_power с предыдущей дугой ||<--nrel_set_power |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
powerSetConstruction.createEdge(ScType.EdgeDCommonConst,set,setPowerLinkAlias,edgeCommonSetPowerAlias); //соединяем ее с множеством дугой для отношений /\ | |
powerSetConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[nrelSetPower],edgeCommonSetPowerAlias,edgePosPermSetPowerAlias); //соедиянемя nrel_set_power с предыдущей дугой ||<--nrel_set_power | |
powerSetConstruction.createEdge(ScType.EdgeDCommonConst, set, setPowerLinkAlias, edgeCommonSetPowerAlias); // соединяем ее с множеством дугой для отношений /\ | |
powerSetConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[nrelSetPower],edgeCommonSetPowerAlias,edgePosPermSetPowerAlias); //соедиянемя nrel_set_power с предыдущей дугой ||<--nrel_set_power |
const resultConstruction = new ScConstruction(); //конструкция,где действие будет соединяться с предыдущей конструкцией отношением nrel_result | ||
resultConstruction.createNode(ScType.NodeConst,resultConstructionNodeAlias); //создаем узел-посредний | ||
resultConstruction.createEdge(ScType.EdgeDCommonConst,actionNode,resultConstructionNodeAlias,edgePosPermResultAlias);// соединяем с действием дугой для отношений | ||
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[nrelResult],edgePosPermResultAlias,edgeCommonResultAlias); //соедиянемя nrel_result с предыдущей дугой | ||
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,powerSetRes[powerSetConstruction.getIndex(setPowerLinkAlias)]);// соединяем узел-посредний со всеми элементами powerSetConstruction | ||
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,set); | ||
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,powerSetRes[powerSetConstruction.getIndex(edgeCommonSetPowerAlias)]); | ||
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,powerSetRes[powerSetConstruction.getIndex(edgePosPermSetPowerAlias)]); | ||
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,keynodes[nrelSetPower]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const resultConstruction = new ScConstruction(); //конструкция,где действие будет соединяться с предыдущей конструкцией отношением nrel_result | |
resultConstruction.createNode(ScType.NodeConst,resultConstructionNodeAlias); //создаем узел-посредний | |
resultConstruction.createEdge(ScType.EdgeDCommonConst,actionNode,resultConstructionNodeAlias,edgePosPermResultAlias);// соединяем с действием дугой для отношений | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[nrelResult],edgePosPermResultAlias,edgeCommonResultAlias); //соедиянемя nrel_result с предыдущей дугой | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,powerSetRes[powerSetConstruction.getIndex(setPowerLinkAlias)]);// соединяем узел-посредний со всеми элементами powerSetConstruction | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,set); | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,powerSetRes[powerSetConstruction.getIndex(edgeCommonSetPowerAlias)]); | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,powerSetRes[powerSetConstruction.getIndex(edgePosPermSetPowerAlias)]); | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm,resultConstructionNodeAlias,keynodes[nrelSetPower]); | |
const resultConstruction = new ScConstruction(); // конструкция,где действие будет соединяться с предыдущей конструкцией отношением nrel_result | |
resultConstruction.createNode(ScType.NodeConst, resultConstructionNodeAlias); // создаем узел-посредний | |
resultConstruction.createEdge(ScType.EdgeDCommonConst, actionNode, resultConstructionNodeAlias, edgePosPermResultAlias); // соединяем с действием дугой для отношений | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[nrelResult], edgePosPermResultAlias, edgeCommonResultAlias); // соедиянемя nrel_result с предыдущей дугой | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm, resultConstructionNodeAlias, powerSetRes[powerSetConstruction.getIndex(setPowerLinkAlias)]); // соединяем узел-посредний со всеми элементами powerSetConstruction | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm, resultConstructionNodeAlias, set); | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm, resultConstructionNodeAlias, powerSetRes[powerSetConstruction.getIndex(edgeCommonSetPowerAlias)]); | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm, resultConstructionNodeAlias, powerSetRes[powerSetConstruction.getIndex(edgePosPermSetPowerAlias)]); | |
resultConstruction.createEdge(ScType.EdgeAccessConstPosPerm, resultConstructionNodeAlias, keynodes[nrelSetPower]); |
const resultRes = await client.createElements(resultConstruction); | ||
if (resultRes && resultRes.length > 0) { | ||
const finalConstruction= new ScConstruction(); | ||
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinished], actionNode); | ||
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinishedSuccessfully], actionNode); | ||
await client.createElements(finalConstruction); | ||
return ; | ||
} | ||
const finalConstruction= new ScConstruction(); | ||
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinished], actionNode); | ||
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinishedUnsuccessfully], actionNode); | ||
await client.createElements(finalConstruction); | ||
return ; | ||
} | ||
const finalConstruction= new ScConstruction(); | ||
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinished], actionNode); | ||
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinishedUnsuccessfully], actionNode); | ||
await client.createElements(finalConstruction); | ||
return ; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const resultRes = await client.createElements(resultConstruction); | |
if (resultRes && resultRes.length > 0) { | |
const finalConstruction= new ScConstruction(); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinished], actionNode); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinishedSuccessfully], actionNode); | |
await client.createElements(finalConstruction); | |
return ; | |
} | |
const finalConstruction= new ScConstruction(); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinished], actionNode); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinishedUnsuccessfully], actionNode); | |
await client.createElements(finalConstruction); | |
return ; | |
} | |
const finalConstruction= new ScConstruction(); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinished], actionNode); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm,keynodes[actionFinishedUnsuccessfully], actionNode); | |
await client.createElements(finalConstruction); | |
return ; | |
}; | |
const resultRes = await client.createElements(resultConstruction); | |
if (resultRes && resultRes.length > 0) { | |
const finalConstruction = new ScConstruction(); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[actionFinished], actionNode); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[actionFinishedSuccessfully], actionNode); | |
await client.createElements(finalConstruction); | |
return; | |
} | |
const finalConstruction = new ScConstruction(); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[actionFinished], actionNode); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[actionFinishedUnsuccessfully], actionNode); | |
await client.createElements(finalConstruction); | |
return; | |
} | |
const finalConstruction = new ScConstruction(); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[actionFinished], actionNode); | |
finalConstruction.createEdge(ScType.EdgeAccessConstPosPerm, keynodes[actionFinishedUnsuccessfully], actionNode); | |
await client.createElements(finalConstruction); | |
return; | |
}; |
import { SC_URL } from '@constants'; | ||
import { ScClient,ScType,ScEventParams,ScEventType } from 'ts-sc-client'; | ||
import { getSetPowerAgent } from "@agents/agent" | ||
|
||
async function testAgent() { | ||
const actionInitiated = "action_initiated"; | ||
const keynodes = [ | ||
{ id: actionInitiated, type: ScType.NodeConstNoRole }, | ||
]; | ||
|
||
const keynodesAddrs = await client.resolveKeynodes(keynodes); | ||
|
||
const eventParams = new ScEventParams(keynodesAddrs[actionInitiated], ScEventType.AddOutgoingEdge, getSetPowerAgent); | ||
await client.eventsCreate([eventParams]); | ||
} | ||
|
||
export const client = new ScClient(SC_URL); | ||
testAgent(); | ||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { SC_URL } from '@constants'; | |
import { ScClient,ScType,ScEventParams,ScEventType } from 'ts-sc-client'; | |
import { getSetPowerAgent } from "@agents/agent" | |
async function testAgent() { | |
const actionInitiated = "action_initiated"; | |
const keynodes = [ | |
{ id: actionInitiated, type: ScType.NodeConstNoRole }, | |
]; | |
const keynodesAddrs = await client.resolveKeynodes(keynodes); | |
const eventParams = new ScEventParams(keynodesAddrs[actionInitiated], ScEventType.AddOutgoingEdge, getSetPowerAgent); | |
await client.eventsCreate([eventParams]); | |
} | |
export const client = new ScClient(SC_URL); | |
testAgent(); | |
import { SC_URL } from '@constants'; | |
import { ScClient, ScType, ScEventParams, ScEventType } from 'ts-sc-client'; | |
import { getSetPowerAgent } from "@agents/agent" | |
async function testAgent() { | |
const actionInitiated = "action_initiated"; | |
const keynodes = [ | |
{ id: actionInitiated, type: ScType.NodeConstNoRole }, | |
]; | |
const keynodesAddrs = await client.resolveKeynodes(keynodes); | |
const eventParams = new ScEventParams(keynodesAddrs[actionInitiated], ScEventType.AddOutgoingEdge, getSetPowerAgent); | |
await client.eventsCreate([eventParams]); | |
} | |
export const client = new ScClient(SC_URL); | |
testAgent(); | |
@ellipsis, review this PR, please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested. Reviewed everything up to 57bb8fb in 2 minutes and 13 seconds
More details
- Looked at
697
lines of code in4
files - Skipped
2
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. docs/examples/TypeScript/agent.ts:43
- Draft comment:
Use '===' instead of '==' for strict equality check.
if(await check(actionNode,keynodes) === false)
- Reason this comment was not posted:
Marked as duplicate.
2. docs/examples/TypeScript/client.ts:18
- Draft comment:
Consider renaming the function 'testAgent' to something more descriptive like 'registerAgent' to better reflect its purpose. - Reason this comment was not posted:
Confidence changes required:50%
The code uses '==' for comparison, which is not a best practice in JavaScript/TypeScript. '===' should be used instead for strict equality checks.
Workflow ID: wflow_dM6wAwde8VeybEiz
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
action, // действие | ||
); | ||
const checkResult = await client.templateSearch(checkTemplate); | ||
if (checkResult.length==0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use '===' instead of '==' for strict equality check.
if (checkResult.length==0) | |
if (checkResult.length === 0) |
elements.push(result[i].get(elAlias)); | ||
} | ||
const set = result[0].get(setAlias); // выбираем узел самого множества из первой найденной конструкции, потому что узел множества он и в Африке узел множества | ||
const power = elements.length.toString();; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra semicolon at the end of the line.
const power = elements.length.toString();; | |
const power = elements.length.toString(); |
@ellipsis, could you fix my comments? |
It seems that there are no specific comments visible in the provided context that need to be addressed. Could you please clarify or point out the specific comments or issues you would like me to address in this pull request? Responding to this comment by @NikitaZotov. For more information about Ellipsis, check the documentation. |
Added guide for implementing ts agent with corresponding example code.
Important
Add a detailed guide and example code for implementing TypeScript agents in the documentation.
ts_agent_guide.md
to provide a detailed guide for implementing TypeScript agents.index.md
to include a link to the new TypeScript agent guide.agent.ts
andclient.ts
indocs/examples/TypeScript/
to demonstrate TypeScript agent implementation.ScClient
, implementing agent logic, and registering the agent.This description was created by
for 57bb8fb. It will automatically update as commits are pushed.