@lit-protocol/vincent-ability-sdk 0.0.12-mma → 2.0.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.0.1 (2025-09-03)
2
+
3
+ ### 🧱 Updated Dependencies
4
+
5
+ - Updated contracts-sdk to 1.1.0
6
+
1
7
  # 2.0.0 (2025-08-05)
2
8
 
3
9
  ### 🚀 Features
@@ -0,0 +1,70 @@
1
+ ## 2.0.1 (2025-09-03)
2
+
3
+ ### 🧱 Updated Dependencies
4
+
5
+ - Updated contracts-sdk to 1.1.0
6
+
7
+ # 2.0.0 (2025-08-05)
8
+
9
+ ### 🚀 Features
10
+
11
+ - Add descriptions on abilities and their api interface params ([0b8ff1e3](https://github.com/LIT-Protocol/Vincent/commit/0b8ff1e3))
12
+
13
+ ### 🩹 Fixes
14
+
15
+ - Making api version property in bundled things to ease its discovery and usage when validating its compatibility ([aa81d087](https://github.com/LIT-Protocol/Vincent/commit/aa81d087))
16
+ - ### Implement supported Vincent Ability API range ([14f0ece1](https://github.com/LIT-Protocol/Vincent/commit/14f0ece1))
17
+
18
+ Added basic Ability API handling to ensure abilities & policies are only used by compatible abilities and policies, and with the correct version of the vincentAbilityClient / app-sdk
19
+
20
+ - Added a new jsParam when VincentAbilityClient calls an ability, `vincentAbilityApiVersion`
21
+ - LIT action wrappers for abilities + policies compare `vincentAbilityApiVersion` to match the major semver range the handler was built with from the ability-sdk
22
+ - vincentAbilityHandler() is responsible for passing along the value when it evaluates supported policies
23
+
24
+ ### ⚠️ Breaking Changes
25
+
26
+ - Add support for vincent-contract-sdk using CBOR2 encoded policy parameters ([819fcd11](https://github.com/LIT-Protocol/Vincent/commit/819fcd11))
27
+ - ### `error` is now `runtimeError` and can only be set by `throw ...` ([04f1ca20](https://github.com/LIT-Protocol/Vincent/commit/04f1ca20))
28
+
29
+ - Previously, if you had not defined a `deny` or `fail` schema, you could call `deny()` or `fail()` with a string
30
+ - That string would end up in the ability/policy response as the `error` property instead of `result`
31
+ - This was problematic because there was no consistent way to identify _un-handled_ error vs. _explicitly returned fail/deny results_
32
+ - If you don't define a deny or fail schema, you can no longer call those methods with a string.
33
+ - `error` is now `runtimeError`, and is _only_ set if a lifecycle method `throw`s an Error - in that case it will be the `message` property of the error
34
+ - If you want to be able to return simple errors in your _result_, you can define a simple deny or fail schema like `z.object({ error: z.string() }`
35
+
36
+ - ### Add support for explicit `schemaValidationError` ([337a4bde](https://github.com/LIT-Protocol/Vincent/commit/337a4bde))
37
+
38
+ - Previously, a failure to validate either input or results of lifecycle method would result in `result: { zodError }` being returned
39
+ - Now, `result` will be `undefined` and there will be an explicit `schemaValidationError` in the result of the ability / policy
40
+
41
+ ```typescript
42
+ export interface SchemaValidationError {
43
+ zodError: ZodError<unknown>; // The result of `zod.safeParse().error`
44
+ phase: string; // Policies: `precheck`|`evaluate`|`commit` - Abilities: `precheck` | `execute`
45
+ stage: string; // `input` | `output`
46
+ }
47
+ ```
48
+
49
+ ### 🧱 Updated Dependencies
50
+
51
+ - Updated contracts-sdk to 2.0.0
52
+
53
+ ### ❤️ Thank You
54
+
55
+ - Daryl Collins
56
+ - FedericoAmura @FedericoAmura
57
+
58
+ ## 1.0.2 (2025-07-08)
59
+
60
+ ### 🩹 Fixes
61
+
62
+ - - Correct type of `PolicyEvaluationResultContext.deniedPolicy` so that `error` is a sibling of `result` ([edc609f5](https://github.com/LIT-Protocol/Vincent/commit/edc609f5))
63
+ - - Fixed a case where a deny response from a policy could be returned without being parsed by its deny result schema ([27a35240](https://github.com/LIT-Protocol/Vincent/commit/27a35240))
64
+ - - Fixed incorrect handling of failure results that resulted in `success: true` responses from abilities that returned fail results ([51087e71](https://github.com/LIT-Protocol/Vincent/commit/51087e71))
65
+ - - Fixed `undefined` being returned to caller instead of the correct `error` string in cases where no fail result schema was defined and an explicit string was passed to `fail()` ([e8f1316a](https://github.com/LIT-Protocol/Vincent/commit/e8f1316a))
66
+ - - Fixed ability result typeguard functions incorrectly returning `false` when they were provided outputs with no `result` (e.g. no return value schema is defined for the lifecycle method) ([cf542969](https://github.com/LIT-Protocol/Vincent/commit/cf542969))
67
+
68
+ ### ❤️ Thank You
69
+
70
+ - Daryl Collins
@@ -0,0 +1,123 @@
1
+ # Contributing to Vincent Ability SDK
2
+
3
+ This document provides guidelines for contributing to the Vincent Ability SDK project.
4
+
5
+ ## Overview
6
+
7
+ The Vincent Ability SDK is an SDK exposing utilities to develop Vincent abilities and policies. It provides a type-safe lifecycle system for defining and composing policies and abilities, with strong TypeScript inference support throughout.
8
+
9
+ ## Setup
10
+
11
+ 1. Follow the global setup instructions in the repository root [CONTRIBUTING.md](../../../CONTRIBUTING.md).
12
+ 2. Install dependencies:
13
+ ```bash
14
+ pnpm install
15
+ ```
16
+
17
+ ## Development Workflow
18
+
19
+ ### Building
20
+
21
+ Build the SDK:
22
+
23
+ ```bash
24
+ nx build ability-sdk
25
+ ```
26
+
27
+ ### Type Checking
28
+
29
+ Run type checking:
30
+
31
+ ```bash
32
+ pnpm typecheck
33
+ ```
34
+
35
+ ### Watch Mode for Type Checking
36
+
37
+ Run type checking in watch mode:
38
+
39
+ ```bash
40
+ pnpm watch:type-tests
41
+ ```
42
+
43
+ ## Project Structure
44
+
45
+ - `src/`: Source code
46
+ - `lib/`
47
+ - `type-inference-verification/`
48
+
49
+ ## SDK Development Guidelines
50
+
51
+ 1. Maintain strong TypeScript typing throughout the codebase
52
+ 2. Use Zod for schema validation
53
+ 3. Design APIs that are intuitive and easy to use
54
+ 4. Provide comprehensive documentation for all public APIs
55
+ 5. Write unit tests for all functionality
56
+ 6. Ensure backward compatibility when making changes
57
+
58
+ ## Core Concepts
59
+
60
+ The SDK is built around these core concepts:
61
+
62
+ - **Policies**: Encapsulate decision logic (precheck, evaluate, commit) and define their input/output schemas.
63
+ - **Abilities**: Orchestrate multiple policies and expose `precheck` and `execute` lifecycle methods.
64
+
65
+ ## Testing
66
+
67
+ Write unit tests for all functionality:
68
+
69
+ ```bash
70
+ pnpm test
71
+ ```
72
+
73
+ ## Documentation
74
+
75
+ - Document all public APIs with JSDoc comments
76
+ - Update README.md when adding new features
77
+ - Provide examples for common use cases
78
+
79
+ ## Pull Request Process
80
+
81
+ 1. Ensure your code follows the coding standards
82
+ 2. Update documentation if necessary
83
+ 3. Include tests for new functionality
84
+ 4. Link any related issues in your pull request description
85
+ 5. Request a review from a maintainer
86
+
87
+ ## For AI Editors and IDEs
88
+
89
+ When working with AI-powered editors like Cursor, GitHub Copilot, or other AI assistants in this project directory, please note:
90
+
91
+ ### Context Priority
92
+
93
+ 1. **Primary Context**: When working within the ability-sdk project directory, AI editors should prioritize this CONTRIBUTING.md file and the project's README.md for specific guidance on the Ability SDK.
94
+
95
+ 2. **Secondary Context**: The root-level CONTRIBUTING.md and README.md files provide important context about how this SDK fits into the broader Vincent ecosystem.
96
+
97
+ ### Key Files for Ability SDK Context
98
+
99
+ - `/packages/libs/ability-sdk/README.md`: Overview of the Ability SDK project
100
+ - `/packages/libs/ability-sdk/CONTRIBUTING.md`: This file, with Ability SDK-specific contribution guidelines
101
+ - `/packages/libs/ability-sdk/src/`: Source code for the Ability SDK
102
+
103
+ ### Related Projects
104
+
105
+ The Ability SDK is a core component that is used by:
106
+
107
+ - `ability-aave`: For implementing Aave abilities
108
+ - `ability-debridge`: For implementing Debridge abilities
109
+ - `ability-erc20-approval`: For implementing ERC20 approval abilities
110
+ - `ability-morpho`: For implementing Morpho abilities
111
+ - `ability-transaction-signer`: For implementing transaction signing abilities
112
+ - `ability-uniswap-swap`: For implementing Uniswap swap abilities
113
+ - `policy-contract-whitelist`: For implementing contract whitelist policies
114
+ - `policy-send-counter`: For implementing transaction counter policies
115
+ - `policy-spending-limit`: For implementing spending limit policies
116
+
117
+ When working on Ability SDK code, consider these consumers for context, and focus on maintaining backward compatibility and strong type safety.
118
+
119
+ ## Additional Resources
120
+
121
+ - [Vincent Documentation](https://docs.heyvincent.ai/)
122
+ - [TypeScript Documentation](https://www.typescriptlang.org/docs/)
123
+ - [Zod Documentation](https://zod.dev/)
package/dist/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # ability-sdk
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build ability-sdk` to build the library.
8
+
9
+ ## Usage
10
+
11
+ # Vincent Policy & Ability SDK
12
+
13
+ This library provides a type-safe lifecycle system for defining and composing **policies** and **abilities**, with strong TypeScript inference support throughout.
14
+
15
+ ## 🧩 Core Concepts
16
+
17
+ - **Policies** encapsulate decision logic (precheck, evaluate, commit) and define their input/output schemas.
18
+ - **Abilities** orchestrate multiple policies and expose `precheck` and `execute` lifecycle methods.
19
+ - **Context injection** provides `allow()` / `deny()` and `succeed()` / `fail()` methods, with schema-safe return typing.
20
+ - All inference is preserved automatically using `createVincentPolicy`, `createVincentAbilityPolicy`, and `createVincentAbility`.
21
+
22
+ ---
23
+
24
+ ### 🔁 Calling `commit()` on a Policy from within a Ability
25
+
26
+ Policies can define a `commit()` lifecycle method to finalize changes once an ability executes successfully. These `commit()` functions are injected automatically into the `allowedPolicies` object of the `AbilityContext`.
27
+
28
+ ### Example Policy (max daily spend)
29
+
30
+ ```ts
31
+ import { z } from 'zod';
32
+ import { createVincentPolicy } from '@lit-protocol/vincent-ability-sdk';
33
+
34
+ import { getAmountSpentToday, adjustDailySpendAmount } from '@my-org/spending-limit-client';
35
+
36
+ export const dailySpendPolicy = createVincentPolicy({
37
+ ipfsCid: 'policy-committable',
38
+ packageName: '@lit-protocol/max-spend-policy',
39
+
40
+ abilityParamsSchema: z.object({
41
+ buySomething: z.boolean(),
42
+ buyAmount: z.number(),
43
+ }),
44
+ userParamsSchema: z.object({
45
+ perBuyLimit: z.number(),
46
+ maxAmountPerDay: z.number(),
47
+ }),
48
+
49
+ evalAllowResultSchema: z.object({
50
+ ok: z.boolean(),
51
+ amountRemaining: z.number(),
52
+ amountToSpend: z.number(),
53
+ }),
54
+ evalDenyResultSchema: z.union([
55
+ z.object({
56
+ reason: z.literal('Buy amount request exceeds per-buy limit'),
57
+ buyAmount: z.number(),
58
+ }),
59
+ z.object({
60
+ reason: z.enum(['Buy amount request exceeds max amount per day']),
61
+ buyAmount: z.number(),
62
+ amountSpentToday: z.number(),
63
+ amountRemaining: z.number(),
64
+ }),
65
+ ]),
66
+
67
+ commitParamsSchema: z.object({ amountSpent: z.number() }),
68
+ commitAllowResultSchema: z.object({
69
+ transactionId: z.string(),
70
+ timestamp: z.number(),
71
+ }),
72
+ commitDenyResultSchema: z.object({
73
+ errorCode: z.number().optional(),
74
+ message: z.string(),
75
+ }),
76
+
77
+ evaluate: async ({ abilityParams, userParams }, context) => {
78
+ const { maxAmountPerDay, perBuyLimit } = userParams;
79
+ const { buyAmount } = abilityParams;
80
+
81
+ if (buyAmount > perBuyLimit) {
82
+ return context.deny({
83
+ reason: 'Buy amount request exceeds per-buy limit',
84
+ buyAmount,
85
+ });
86
+ }
87
+
88
+ const amountSpentToday = await getAmountSpentToday(context.delegation.delegator);
89
+ const amountRemaining = maxAmountPerDay - amountSpentToday;
90
+
91
+ if (buyAmount > amountRemaining) {
92
+ return context.deny({
93
+ reason: 'Buy amount request exceeds max amount per day',
94
+ amountSpentToday,
95
+ buyAmount,
96
+ amountRemaining,
97
+ });
98
+ }
99
+
100
+ return context.allow({
101
+ ok: true,
102
+ amountRemaining,
103
+ amountToSpend: buyAmount,
104
+ });
105
+ },
106
+
107
+ commit: async ({ amountSpent }, context) => {
108
+ try {
109
+ const spendCommitResult: { transactionId: string; timestamp: number } =
110
+ await adjustDailySpendAmount(context.delegation.delegator, amountSpent);
111
+
112
+ return context.allow(spendCommitResult);
113
+ } catch (e: unknown) {
114
+ if (e instanceof Error) {
115
+ if ('errorCode' in e) {
116
+ return context.deny({
117
+ errorCode: e.errorCode as number,
118
+ message: e.message,
119
+ });
120
+ } else {
121
+ return context.deny({ message: e.message });
122
+ }
123
+ }
124
+
125
+ return context.deny({ message: String(e) });
126
+ }
127
+ },
128
+ });
129
+ ```
130
+
131
+ ---
132
+
133
+ ### Example Ability - Uniswap
134
+
135
+ ```ts
136
+ import { z } from 'zod';
137
+
138
+ import {
139
+ createVincentAbilityPolicy,
140
+ createVincentAbility,
141
+ } from '@lit-protocol/vincent-ability-sdk';
142
+
143
+ import { dailySpendPolicy } from '@lit-protocol/max-spend-policy';
144
+
145
+ import uniswapV3Client from '@uniswap/v3-sdk';
146
+
147
+ const abilityParamsSchema = z.object({
148
+ buy: z.boolean(),
149
+ buyAmount: z.number(),
150
+ });
151
+
152
+ export const myTokenSwapAbility = createVincentAbility({
153
+ packageName: 'tokenswapability',
154
+ abilityDescription: 'Token Swap Ability',
155
+
156
+ abilityParamsSchema,
157
+
158
+ supportedPolicies: [
159
+ createVincentAbilityPolicy({
160
+ abilityParamsSchema,
161
+ PolicyConfig: dailySpendPolicy,
162
+ abilityParameterMappings: { buy: 'buyAmount' },
163
+ }),
164
+ ],
165
+ executeSuccessSchema: z.object({
166
+ message: z.string(),
167
+ amountSpent: z.number().optional(),
168
+ spendCommitResult: z
169
+ .object({
170
+ transactionId: z.string(),
171
+ timestamp: z.number(),
172
+ })
173
+ .optional(),
174
+ }),
175
+
176
+ executeFailSchema: z.object({ error: z.string(), message: z.string() }),
177
+
178
+ async execute(abilityParams, { succeed, fail, policiesContext }) {
179
+ const spendPolicyContext = policiesContext.allowedPolicies['@lit-protocol/max-spend-policy'];
180
+
181
+ const amountSpent: number = await uniswapV3Client.performSwap({});
182
+
183
+ if (spendPolicyContext) {
184
+ const spendCommitResult = await spendPolicyContext.commit({
185
+ amountSpent,
186
+ });
187
+
188
+ if (!spendCommitResult.allow) {
189
+ return fail({
190
+ error: `Policy commit denied with code ${spendCommitResult.result.errorCode}`,
191
+ message: 'Ability executed but policy commit denied',
192
+ });
193
+ }
194
+
195
+ if (spendCommitResult.allow) {
196
+ return succeed({
197
+ amountSpent,
198
+ spendCommitResult: spendCommitResult.result,
199
+ message: 'Ability executed and spending limit policy commit completed',
200
+ });
201
+ }
202
+ }
203
+
204
+ return succeed({
205
+ message: 'Ability executed for user without enabled spending limit',
206
+ });
207
+ },
208
+ });
209
+ ```
210
+
211
+ ## 🧠 Tip
212
+
213
+ Ability and policy authors should export the result of `createVincentPolicy()` / `createVincentAbility()`
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lit-protocol/vincent-ability-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lit-protocol/vincent-ability-sdk",
3
- "version": "0.0.12-mma",
3
+ "version": "2.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -9,7 +9,7 @@
9
9
  "semver": "^7.7.2",
10
10
  "tslib": "^2.8.1",
11
11
  "zod": "^3.25.64",
12
- "@lit-protocol/vincent-contracts-sdk": "0.0.12-mma"
12
+ "@lit-protocol/vincent-contracts-sdk": "1.1.0"
13
13
  },
14
14
  "main": "./dist/src/index.js",
15
15
  "types": "./dist/src/index.d.ts",