Skip to content
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

Add documentation #12

Merged
merged 66 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
12d425d
Update agent.ts
madschristensen99 Jan 7, 2025
b21e28d
Update agent.ts
madschristensen99 Jan 7, 2025
043230a
Update agent.ts
madschristensen99 Jan 7, 2025
b0313c8
Update get-tool-for-intent.ts
madschristensen99 Jan 7, 2025
e24db7c
Update get-tool-matching-prompt.ts
madschristensen99 Jan 7, 2025
a434c0e
Update parse-tool-parameters.ts
madschristensen99 Jan 7, 2025
d2161ad
Update add-delegatee.ts
madschristensen99 Jan 7, 2025
9e9201f
Update batch-add-delegatee.ts
madschristensen99 Jan 7, 2025
54d6148
Update batch-remove-delegatee.ts
madschristensen99 Jan 7, 2025
badc55f
Update get-delegatees.ts
madschristensen99 Jan 7, 2025
798b136
Update get-tool-policy.ts
madschristensen99 Jan 7, 2025
4415756
Update get-tools.ts
madschristensen99 Jan 7, 2025
69dc32c
Update is-delegatee.ts
madschristensen99 Jan 7, 2025
cd761e9
Update permit-tool.ts
madschristensen99 Jan 7, 2025
57aaaae
Update remove-delegatee.ts
madschristensen99 Jan 7, 2025
9865801
Update remove-tool-policy.ts
madschristensen99 Jan 7, 2025
c9f578f
Update remove-tool.ts
madschristensen99 Jan 7, 2025
0b208cd
Update set-tool-policy.ts
madschristensen99 Jan 7, 2025
4f1bbe9
Update execute-tool.ts
madschristensen99 Jan 7, 2025
67e9e49
Update get-delegated-pkps.ts
madschristensen99 Jan 7, 2025
344b7a6
Update get-registered-tools.ts
madschristensen99 Jan 7, 2025
d896ca4
Update get-tool-policy.ts
madschristensen99 Jan 7, 2025
070e618
Update batch-add-delegatee.ts
madschristensen99 Jan 7, 2025
b5d53b2
Update batch-remove-delegatee.ts
madschristensen99 Jan 7, 2025
d1b0a8f
Update delegatee-address.ts
madschristensen99 Jan 7, 2025
88cd1fa
Update init.ts
madschristensen99 Jan 7, 2025
18c20a8
Update insufficient-balance.ts
madschristensen99 Jan 7, 2025
7ad13a4
Update menu.ts
madschristensen99 Jan 7, 2025
8060b91
Update permit-tool.ts
madschristensen99 Jan 7, 2025
2e2820d
Update policy-details.ts
madschristensen99 Jan 7, 2025
e13b8c8
Update remove-delegatee.ts
madschristensen99 Jan 7, 2025
7b2ef78
Update remove-tool.ts
madschristensen99 Jan 7, 2025
2a1e132
Update init.ts
madschristensen99 Jan 7, 2025
17ac17b
Update insufficient-balance.ts
madschristensen99 Jan 7, 2025
80eadd8
Update menu.ts
madschristensen99 Jan 7, 2025
6cfbb70
Update select-pkp.ts
madschristensen99 Jan 7, 2025
d7364a0
Update select-tool.ts
madschristensen99 Jan 7, 2025
f7dcc19
Update tool-params.ts
madschristensen99 Jan 7, 2025
223abb0
Update select-lit-network.ts
madschristensen99 Jan 7, 2025
331f573
Update select-role.ts
madschristensen99 Jan 7, 2025
fe1beae
Update admin.ts
madschristensen99 Jan 7, 2025
6d5afc0
Update delegatee.ts
madschristensen99 Jan 7, 2025
d059a0b
Update admin.ts
madschristensen99 Jan 7, 2025
ff4fade
Update delegatee.ts
madschristensen99 Jan 7, 2025
970b80a
Update errors.ts
madschristensen99 Jan 7, 2025
9739e00
Update types.ts
madschristensen99 Jan 7, 2025
c8fa555
Update ipfs.ts
madschristensen99 Jan 7, 2025
b739e04
Update lit-action.ts
madschristensen99 Jan 7, 2025
6d931eb
Update policy.ts
madschristensen99 Jan 7, 2025
f5da59d
Update tool.ts
madschristensen99 Jan 7, 2025
d9cf03e
Update errors.ts
madschristensen99 Jan 7, 2025
cba86f5
Update registry.ts
madschristensen99 Jan 7, 2025
755a8dc
Update ipfs.ts
madschristensen99 Jan 7, 2025
282dafa
Update lit-action.ts
madschristensen99 Jan 7, 2025
8705114
Update policy.ts
madschristensen99 Jan 7, 2025
91aad5a
Update tool.ts
madschristensen99 Jan 7, 2025
ce6a5c5
Update ipfs.ts
madschristensen99 Jan 7, 2025
32ecf25
Update lit-action.ts
madschristensen99 Jan 7, 2025
b8a34af
Update networks.ts
madschristensen99 Jan 7, 2025
8c45ef5
Update policy.ts
madschristensen99 Jan 7, 2025
635d780
Update tool.ts
madschristensen99 Jan 7, 2025
b181cc8
Update tool.ts
madschristensen99 Jan 7, 2025
824908b
Update errors.ts
madschristensen99 Jan 7, 2025
0a40b96
Add files via upload
madschristensen99 Jan 7, 2025
8b7a126
Add files via upload
madschristensen99 Jan 7, 2025
95fe753
Merge branch 'main' into main
madschristensen99 Jan 8, 2025
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
Prev Previous commit
Next Next commit
Update permit-tool.ts
madschristensen99 authored Jan 7, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8060b9138d02cb8e169cb02328cb57ecb5ad8b70
37 changes: 35 additions & 2 deletions packages/fss-cli/src/lib/prompts/admin/permit-tool.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
// Import the prompts library for user interaction.
import prompts from 'prompts';

// Import types and utilities from the '@lit-protocol/full-self-signing' package.
import {
listToolsByNetwork,
type FssTool,
type LitNetwork,
type PermittedTools,
} from '@lit-protocol/full-self-signing';

// Import the logger utility for logging messages.
import { logger } from '../../utils/logger';

// Import custom error types and utilities.
import { FssCliError, FssCliErrorType } from '../../errors';

/**
* Prompts the user to select a tool to permit, filtering out already permitted tools.
* This function retrieves the list of available tools for the specified Lit network,
* filters out tools that are already permitted, and prompts the user to select a tool.
*
* @param litNetwork - The Lit network for which to retrieve available tools.
* @param alreadyPermittedTools - An object containing tools that are already permitted.
* @returns The selected tool to permit.
* @throws FssCliError - If no unpermitted tools are found or the user cancels the selection.
*/
export const promptSelectToolToPermit = async (
litNetwork: LitNetwork,
alreadyPermittedTools: PermittedTools | null
) => {
// Retrieve the list of available tools for the specified Lit network.
const availableTools = listToolsByNetwork(litNetwork);

// Create a set of already permitted IPFS CIDs for efficient lookup
// Create a set of IPFS CIDs for already permitted tools for efficient lookup.
const permittedCids = new Set([
...(alreadyPermittedTools?.toolsWithPolicies.map(
(tool: FssTool<any, any>) => tool.ipfsCid
@@ -25,18 +42,20 @@ export const promptSelectToolToPermit = async (
) || []),
]);

// Filter out already permitted tools
// Filter out tools that are already permitted.
const unpermittedTools = availableTools.filter(
(tool: FssTool<any, any>) => !permittedCids.has(tool.ipfsCid)
);

// If no unpermitted tools are found, throw an error.
if (unpermittedTools.length === 0) {
throw new FssCliError(
FssCliErrorType.ADMIN_PERMIT_TOOL_NO_UNPERMITTED_TOOLS,
'No unpermitted tools found.'
);
}

// Prompt the user to select a tool to permit.
const { tool } = await prompts({
type: 'select',
name: 'tool',
@@ -48,36 +67,50 @@ export const promptSelectToolToPermit = async (
})),
});

// If the user cancels the selection, throw an error.
if (!tool) {
throw new FssCliError(
FssCliErrorType.ADMIN_PERMIT_TOOL_CANCELLED,
'Tool permitting cancelled.'
);
}

// Return the selected tool.
return tool as FssTool<any, any>;
};

/**
* Prompts the user to confirm the tool permitting action.
* This function displays details of the selected tool and asks the user to confirm the action.
*
* @param tool - The tool to permit.
* @returns A boolean indicating whether the user confirmed the action.
* @throws FssCliError - If the user cancels the confirmation.
*/
export const promptConfirmPermit = async (tool: FssTool) => {
// Display details of the selected tool.
logger.log('');
logger.log(`Name: ${tool.name}`);
logger.log(`Description: ${tool.description}`);
logger.log(`IPFS CID: ${tool.ipfsCid}`);
logger.log('');

// Prompt the user to confirm the tool permitting action.
const { confirmed } = await prompts({
type: 'confirm',
name: 'confirmed',
message: 'Are you sure you want to permit this tool?',
initial: true,
});

// If the user does not confirm, throw an error.
if (!confirmed) {
throw new FssCliError(
FssCliErrorType.ADMIN_PERMIT_TOOL_CANCELLED,
'Tool permitting cancelled.'
);
}

// Return the confirmation status.
return confirmed;
};