Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
332 changes: 332 additions & 0 deletions src/GameState/src/Main.mo

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/ShareService/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.mops
54 changes: 54 additions & 0 deletions src/ShareService/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ShareService
This canister serves as a Generative AI service to mAIners and thus has multiple LLM canisters attached.

## Reset a mAIner
```bash
NETWORK=prd
USER_ID=...
# Get the correct mAIner canister id, by running from funnAI folder:
scripts/get_mainers.sh --network $NETWORK --user $USER_ID

# Verify that the canister id is in the canister_ids.json in this folder.
# If it is not, do not edit it yourself, but run from funnAI folder:
scripts/get_mainers.sh --network $NETWORK

# Then, upgrade the mAIner from this folder (mAIner):
# Get the mainer_ctrlb_canister_## from the canister_ids.json and run:
MAINER=mainer_ctrlb_canister_##

# verify logs and make sure it is Ok to upgrade (nothing in the queue)
dfx canister --network $NETWORK logs $MAINER --follow
dfx canister --network $NETWORK call $MAINER getChallengeQueueAdmin --output json

# toggle maintenance flag
dfx canister --network $NETWORK call $MAINER getMaintenanceFlag
dfx canister --network $NETWORK call $MAINER toggleMaintenanceFlagAdmin # if needed

# stop & snapshot & start
dfx canister --network $NETWORK stop $MAINER
dfx canister --network $NETWORK snapshot create $MAINER
dfx canister --network $NETWORK start $MAINER

# Upgrade & start Timer & toggle maintenance flag
# IMPORTANT: make sure the correct branch is checked out !!!!!!!!!!!!!!
dfx deploy --network $NETWORK $MAINER --mode upgrade
dfx canister --network $NETWORK call $MAINER startTimerExecutionAdmin
dfx canister --network $NETWORK call $MAINER getMaintenanceFlag
dfx canister --network $NETWORK call $MAINER toggleMaintenanceFlagAdmin # if needed

# verify everything looks good (timer should have been restarted)
dfx canister --network $NETWORK logs $MAINER

# if it does not look good, restore the snapshot
dfx canister --network $NETWORK snapshot list $MAINER
dfx canister --network $NETWORK stop $MAINER
dfx canister --network $NETWORK snapshot load $MAINER <snapshot-id>
dfx canister --network $NETWORK start $MAINER
dfx canister --network $NETWORK call $MAINER startTimerExecutionAdmin
dfx canister --network $NETWORK call $MAINER getMaintenanceFlag
dfx canister --network $NETWORK call $MAINER toggleMaintenanceFlagAdmin # if needed

# if it looks good, delete the snapshot
dfx canister --network $NETWORK snapshot list $MAINER
dfx canister --network $NETWORK snapshot delete $MAINER <snapshot-id>
```
10 changes: 10 additions & 0 deletions src/ShareService/canister_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"mainer_service_canister": {
"development": "ecpt4-ayaaa-aaaad-qhk4a-cai",
"ic": "",
"local": "",
"testing": "vtebo-riaaa-aaaam-qdxgq-cai",
"demo": "4xoqq-waaaa-aaaaj-a2bvq-cai",
"prd": "rilmv-caaaa-aaaaa-qandq-cai"
}
}
52 changes: 52 additions & 0 deletions src/ShareService/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"version": 1,
"canisters": {
"mainer_service_canister": {
"main": "src/Main.mo"
}
},
"defaults": {
"build": {
"packtool": "mops sources"
}
},
"networks": {
"development": {
"providers": [
"https://icp0.io"
],
"type": "persistent"
},
"testing": {
"providers": [
"https://icp0.io"
],
"type": "persistent"
},
"prd": {
"providers": [
"https://icp0.io"
],
"type": "persistent"
},
"demo": {
"providers": [
"https://icp0.io"
],
"type": "persistent"
},
"ic": {
"providers": [
"https://icp0.io"
],
"type": "persistent"
},
"backup": {
"providers": [
"https://icp0.io"
],
"type": "persistent"
}
},
"output_env_file": ".env"
}
6 changes: 6 additions & 0 deletions src/ShareService/mops.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dependencies]
base = "0.13.5"
accountid = "https://github.com/aviate-labs/principal.mo#main"
hex = "https://github.com/letmejustputthishere/motoko-hex#master"
canistergeek = "https://github.com/usergeek/canistergeek-ic-motoko#v0.0.3"
uuid = "https://github.com/aviate-labs/uuid.mo#v0.2.0"
135 changes: 135 additions & 0 deletions src/ShareService/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash

#######################################################################
# run from parent folder as:
# scripts/deploy.sh --network [local|ic]
#######################################################################

# Default network type is local
NETWORK_TYPE="local"
DEPLOY_MODE="install"

NUM_MAINERS_DEPLOYED=3
MAINER_CANISTER_TYPES=("ShareAgent" "ShareAgent" "Own" )

# When deploying to IC, we deploy to a specific subnet
# none will not use subnet parameter in deploy to ic
# SUBNET="none"
SUBNET="qdvhd-os4o2-zzrdw-xrcv4-gljou-eztdp-bj326-e6jgr-tkhuc-ql6v2-yqe"

# Parse command line arguments for network type
while [ $# -gt 0 ]; do
case "$1" in
--network)
shift
if [ "$1" = "local" ] || [ "$1" = "ic" ] || [ "$1" = "testing" ] || [ "$1" = "development" ] || [ "$1" = "demo" ] || [ "$1" = "prd" ]; then
NETWORK_TYPE=$1
else
echo "Invalid network type: $1. Use 'local' or 'ic' or 'testing."
exit 1
fi
shift
;;
--mode)
shift
if [ "$1" = "install" ] || [ "$1" = "reinstall" ] || [ "$1" = "upgrade" ]; then
DEPLOY_MODE=$1
else
echo "Invalid mode: $1. Use 'install', 'reinstall' or 'upgrade'."
exit 1
fi
shift
;;
*)
echo "Unknown argument: $1"
echo "Usage: $0 --network [local|ic|testing|development|demo|prd]"
exit 1
;;
esac
done

echo "Using network type: $NETWORK_TYPE"

#######################################################################
echo " "
echo "==================================================="
MAINER="mainer_service_canister"
echo "Deploying the protocol's $MAINER"
if [ "$NETWORK_TYPE" = "ic" ] || [ "$NETWORK_TYPE" = "testing" ] || [ "$NETWORK_TYPE" = "development" ] || [ "$NETWORK_TYPE" = "demo" ] || [ "$NETWORK_TYPE" = "prd" ]; then
if [ "$SUBNET" = "none" ]; then
dfx deploy $MAINER --mode $DEPLOY_MODE --yes --network $NETWORK_TYPE
else
dfx deploy $MAINER --mode $DEPLOY_MODE --yes --network $NETWORK_TYPE --subnet $SUBNET
fi
else
dfx deploy $MAINER --mode $DEPLOY_MODE --yes --network $NETWORK_TYPE
fi

echo " "
echo "--------------------------------------------------"
dfx canister call $MAINER setMainerCanisterType '(variant {ShareService} )' --network $NETWORK_TYPE
echo "verify getMainerCanisterType: "
dfx canister call $MAINER getMainerCanisterType --network $NETWORK_TYPE

echo " "
echo "--------------------------------------------------"
echo "Checking health endpoint"
output=$(dfx canister call $MAINER health --network $NETWORK_TYPE)

if [ "$output" != "(variant { Ok = record { status_code = 200 : nat16 } })" ]; then
echo "$MAINER is not healthy. Exiting."
exit 1
else
echo "$MAINER is healthy."
fi

#######################################################################
echo " "
echo "==================================================="
echo "Deploying $NUM_MAINERS_DEPLOYED mainer Agents"
mainer_id_start=0
mainer_id_end=$((NUM_MAINERS_DEPLOYED - 1))

for m in $(seq $mainer_id_start $mainer_id_end)
do

MAINER="mainer_ctrlb_canister_$m"

echo " "
echo "--------------------------------------------------"
echo "Deploying $MAINER"

if [ "$NETWORK_TYPE" = "ic" ] || [ "$NETWORK_TYPE" = "testing" ] || [ "$NETWORK_TYPE" = "development" ] || [ "$NETWORK_TYPE" = "demo" ] || [ "$NETWORK_TYPE" = "prd" ]; then
if [ "$SUBNET" = "none" ]; then
dfx deploy $MAINER --mode $DEPLOY_MODE --yes --network $NETWORK_TYPE
else
dfx deploy $MAINER --mode $DEPLOY_MODE --yes --network $NETWORK_TYPE --subnet $SUBNET
fi
else
dfx deploy $MAINER --mode $DEPLOY_MODE --yes --network $NETWORK_TYPE
fi

echo " "
echo "--------------------------------------------------"
echo "setMainerCanisterType to ${MAINER_CANISTER_TYPES[$m]}"
dfx canister call $MAINER setMainerCanisterType "(variant {${MAINER_CANISTER_TYPES[$m]}} )" --network $NETWORK_TYPE
echo "verify getMainerCanisterType: "
dfx canister call $MAINER getMainerCanisterType --network $NETWORK_TYPE

echo " "
echo "--------------------------------------------------"
echo "Checking health endpoint"
output=$(dfx canister call $MAINER health --network $NETWORK_TYPE)

if [ "$output" != "(variant { Ok = record { status_code = 200 : nat16 } })" ]; then
echo "$MAINER is not healthy. Exiting."
exit 1
else
echo "$MAINER is healthy."
fi
done

echo " "
echo "--------------------------------------------------"
echo "Generating bindings for a frontend"
dfx generate
69 changes: 69 additions & 0 deletions src/ShareService/scripts/register-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

#######################################################################
# run from parent folder as:
# scripts/register-check.sh --network [local|ic]
#######################################################################

# Default network type is local
NETWORK_TYPE="local"
NUM_MAINERS_DEPLOYED=3
MAINER_CANISTER_TYPES=("ShareAgent" "ShareAgent" "Own" )

# Parse command line arguments for network type
while [ $# -gt 0 ]; do
case "$1" in
--network)
shift
if [ "$1" = "local" ] || [ "$1" = "ic" ] || [ "$1" = "testing" ] || [ "$1" = "development" ] || [ "$1" = "demo" ] || [ "$1" = "prd" ]; then
NETWORK_TYPE=$1
else
echo "Invalid network type: $1. Use 'local' or 'ic' or 'testing' or 'development' or 'demo' or 'prd'."
exit 1
fi
shift
;;
*)
echo "Unknown argument: $1"
echo "Usage: $0 --network [local|ic]"
exit 1
;;
esac
done

echo "Using network type: $NETWORK_TYPE"

############################################################################
MAINER="mainer_service_canister"
echo " "
echo "Checking if $MAINER is a controller of its registered LLM canisters"
output=$(dfx canister call $MAINER checkAccessToLLMs --network $NETWORK_TYPE)

if [ "$output" != "(variant { Ok = record { status_code = 200 : nat16 } })" ]; then
echo "ERROR: $MAINER is not a controller of all its LLMs. Make sure to update the LLMs."
exit 1
else
echo "$MAINER is a controller of all its LLMs."
fi


mainer_id_start=0
mainer_id_end=$((NUM_MAINERS_DEPLOYED - 1))

for m in $(seq $mainer_id_start $mainer_id_end)
do
MAINER="mainer_ctrlb_canister_$m"
MAINER_CANISTER_TYPE=${MAINER_CANISTER_TYPES[$m]}
if ($MAINER_CANISTER_TYPE == "Own"); then
echo " "
echo "Checking if $MAINER is a controller of its registered LLM canisters"
output=$(dfx canister call $MAINER checkAccessToLLMs --network $NETWORK_TYPE)

if [ "$output" != "(variant { Ok = record { status_code = 200 : nat16 } })" ]; then
echo "ERROR: $MAINER is not a controller of all its LLMs. Make sure to update the LLMs."
exit 1
else
echo "$MAINER is a controller of all its LLMs."
fi
fi
done
Loading