intentkit 0.6.2.dev1__py3-none-any.whl → 0.6.2.dev2__py3-none-any.whl

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.

Potentially problematic release.


This version of intentkit might be problematic. Click here for more details.

intentkit/__init__.py CHANGED
@@ -3,7 +3,7 @@
3
3
  A powerful platform for building AI agents with blockchain and cryptocurrency capabilities.
4
4
  """
5
5
 
6
- __version__ = "0.6.2-dev1"
6
+ __version__ = "0.6.2-dev2"
7
7
  __author__ = "hyacinthus"
8
8
  __email__ = "hyacinthus@gmail.com"
9
9
 
@@ -3,9 +3,12 @@ import os
3
3
  import tempfile
4
4
  from datetime import datetime, timedelta, timezone
5
5
  from typing import Any, Dict, List, NotRequired, Optional, TypedDict
6
+ from urllib.parse import urlencode
6
7
 
7
8
  import httpx
8
9
  from pydantic import BaseModel, Field
10
+ from requests.auth import HTTPBasicAuth
11
+ from requests_oauthlib import OAuth2Session
9
12
  from tweepy.asynchronous import AsyncClient
10
13
 
11
14
  from intentkit.abstracts.skill import SkillStoreABC
@@ -443,3 +446,58 @@ async def unlink_twitter(agent_id: str) -> AgentData:
443
446
  "twitter_refresh_token": None,
444
447
  },
445
448
  )
449
+
450
+
451
+ # this class is forked from:
452
+ # https://github.com/tweepy/tweepy/blob/main/tweepy/auth.py
453
+ # it is not maintained by the original author, bug need to be fixed
454
+ class OAuth2UserHandler(OAuth2Session):
455
+ """OAuth 2.0 Authorization Code Flow with PKCE (User Context)
456
+ authentication handler
457
+ """
458
+
459
+ def __init__(self, *, client_id, redirect_uri, scope, client_secret=None):
460
+ super().__init__(client_id, redirect_uri=redirect_uri, scope=scope)
461
+ if client_secret is not None:
462
+ self.auth = HTTPBasicAuth(client_id, client_secret)
463
+ else:
464
+ self.auth = None
465
+ self.code_challenge = self._client.create_code_challenge(
466
+ self._client.create_code_verifier(128), "S256"
467
+ )
468
+
469
+ def get_authorization_url(self, agent_id: str, redirect_uri: str):
470
+ """Get the authorization URL to redirect the user to
471
+
472
+ Args:
473
+ agent_id: ID of the agent to authenticate
474
+ redirect_uri: URI to redirect to after authorization
475
+ """
476
+ state_params = {"agent_id": agent_id, "redirect_uri": redirect_uri}
477
+ authorization_url, _ = self.authorization_url(
478
+ "https://x.com/i/oauth2/authorize",
479
+ state=urlencode(state_params),
480
+ code_challenge=self.code_challenge,
481
+ code_challenge_method="S256",
482
+ )
483
+ return authorization_url
484
+
485
+ def get_token(self, authorization_response):
486
+ """After user has authorized the app, fetch access token with
487
+ authorization response URL
488
+ """
489
+ return super().fetch_token(
490
+ "https://api.x.com/2/oauth2/token",
491
+ authorization_response=authorization_response,
492
+ auth=self.auth,
493
+ include_client_id=True,
494
+ code_verifier=self._client.code_verifier,
495
+ )
496
+
497
+ def refresh(self, refresh_token: str):
498
+ """Refresh token"""
499
+ return super().refresh_token(
500
+ "https://api.x.com/2/oauth2/token",
501
+ refresh_token=refresh_token,
502
+ include_client_id=True,
503
+ )
intentkit/core/credit.py CHANGED
@@ -10,6 +10,7 @@ from sqlalchemy import desc, select
10
10
  from sqlalchemy.ext.asyncio import AsyncSession
11
11
 
12
12
  from intentkit.models.agent import Agent
13
+ from intentkit.models.agent_data import AgentData
13
14
  from intentkit.models.app_setting import AppSetting
14
15
  from intentkit.models.credit import (
15
16
  DEFAULT_PLATFORM_ACCOUNT_ADJUSTMENT,
@@ -150,6 +151,7 @@ async def recharge(
150
151
  permanent_amount=amount, # Set permanent_amount since this is a permanent credit
151
152
  free_amount=Decimal("0"), # No free credits involved
152
153
  reward_amount=Decimal("0"), # No reward credits involved
154
+ agent_wallet_address=None, # No agent involved in recharge
153
155
  note=note,
154
156
  )
155
157
  session.add(event)
@@ -258,6 +260,7 @@ async def reward(
258
260
  reward_amount=amount, # Set reward_amount since this is a reward credit
259
261
  free_amount=Decimal("0"), # No free credits involved
260
262
  permanent_amount=Decimal("0"), # No permanent credits involved
263
+ agent_wallet_address=None, # No agent involved in reward
261
264
  note=note,
262
265
  )
263
266
  session.add(event)
@@ -412,6 +415,7 @@ async def adjustment(
412
415
  free_amount=free_amount,
413
416
  reward_amount=reward_amount,
414
417
  permanent_amount=permanent_amount,
418
+ agent_wallet_address=None, # No agent involved in adjustment
415
419
  note=note,
416
420
  )
417
421
  session.add(event)
@@ -892,6 +896,10 @@ async def expense_message(
892
896
  fee_agent_amount - fee_agent_free_amount - fee_agent_reward_amount
893
897
  ).quantize(FOURPLACES, rounding=ROUND_HALF_UP)
894
898
 
899
+ # Get agent wallet address
900
+ agent_data = await AgentData.get(agent.id)
901
+ agent_wallet_address = agent_data.evm_wallet_address if agent_data else None
902
+
895
903
  event = CreditEventTable(
896
904
  id=event_id,
897
905
  account_id=user_account.id,
@@ -925,6 +933,7 @@ async def expense_message(
925
933
  free_amount=free_amount,
926
934
  reward_amount=reward_amount,
927
935
  permanent_amount=permanent_amount,
936
+ agent_wallet_address=agent_wallet_address,
928
937
  )
929
938
  session.add(event)
930
939
  await session.flush()
@@ -1268,6 +1277,10 @@ async def expense_skill(
1268
1277
  skill_cost_info.fee_dev_amount - fee_dev_free_amount - fee_dev_reward_amount
1269
1278
  ).quantize(FOURPLACES, rounding=ROUND_HALF_UP)
1270
1279
 
1280
+ # Get agent wallet address
1281
+ agent_data = await AgentData.get(agent.id)
1282
+ agent_wallet_address = agent_data.evm_wallet_address if agent_data else None
1283
+
1271
1284
  event = CreditEventTable(
1272
1285
  id=event_id,
1273
1286
  account_id=user_account.id,
@@ -1309,6 +1322,7 @@ async def expense_skill(
1309
1322
  free_amount=free_amount,
1310
1323
  reward_amount=reward_amount,
1311
1324
  permanent_amount=permanent_amount,
1325
+ agent_wallet_address=agent_wallet_address,
1312
1326
  )
1313
1327
  session.add(event)
1314
1328
  await session.flush()
@@ -1452,6 +1466,7 @@ async def refill_free_credits_for_account(
1452
1466
  free_amount=amount_to_add, # Set free_amount since this is a free credit refill
1453
1467
  reward_amount=Decimal("0"), # No reward credits involved
1454
1468
  permanent_amount=Decimal("0"), # No permanent credits involved
1469
+ agent_wallet_address=None, # No agent involved in refill
1455
1470
  note=f"Hourly free credits refill of {amount_to_add}",
1456
1471
  )
1457
1472
  session.add(event)
@@ -1675,6 +1690,10 @@ async def expense_summarize(
1675
1690
  fee_agent_amount - fee_agent_free_amount - fee_agent_reward_amount
1676
1691
  ).quantize(FOURPLACES, rounding=ROUND_HALF_UP)
1677
1692
 
1693
+ # Get agent wallet address
1694
+ agent_data = await AgentData.get(agent.id)
1695
+ agent_wallet_address = agent_data.evm_wallet_address if agent_data else None
1696
+
1678
1697
  event = CreditEventTable(
1679
1698
  id=event_id,
1680
1699
  account_id=user_account.id,
@@ -1707,6 +1726,7 @@ async def expense_summarize(
1707
1726
  free_amount=free_amount,
1708
1727
  reward_amount=reward_amount,
1709
1728
  permanent_amount=permanent_amount,
1729
+ agent_wallet_address=agent_wallet_address,
1710
1730
  )
1711
1731
  session.add(event)
1712
1732
 
@@ -508,6 +508,7 @@ class CreditAccount(BaseModel):
508
508
  free_amount=free_quota, # Set free_amount since this is a free credit refill
509
509
  reward_amount=Decimal("0"), # No reward credits involved
510
510
  permanent_amount=Decimal("0"), # No permanent credits involved
511
+ agent_wallet_address=None, # No agent involved in initial refill
511
512
  note="Initial refill",
512
513
  )
513
514
  session.add(event)
@@ -712,6 +713,10 @@ class CreditEventTable(Base):
712
713
  String,
713
714
  nullable=True,
714
715
  )
716
+ agent_wallet_address = Column(
717
+ String,
718
+ nullable=True,
719
+ )
715
720
  start_message_id = Column(
716
721
  String,
717
722
  nullable=True,
@@ -896,6 +901,10 @@ class CreditEvent(BaseModel):
896
901
  agent_id: Annotated[
897
902
  Optional[str], Field(None, description="ID of the agent if applicable")
898
903
  ]
904
+ agent_wallet_address: Annotated[
905
+ Optional[str],
906
+ Field(None, description="Wallet address of the agent if applicable"),
907
+ ]
899
908
  start_message_id: Annotated[
900
909
  Optional[str],
901
910
  Field(None, description="ID of the starting message if applicable"),
@@ -32,7 +32,7 @@ class ReadAgentApiKey(SystemBaseTool):
32
32
  "Make sure to tell the user the base URL and endpoint. "
33
33
  "Tell user in OpenAI sdk or Desktop client like Cherry Studio, input the base URL and API key. "
34
34
  "Always use markdown code block to wrap the API keys, base URL, and endpoint. "
35
- "Tell user to check more doc in https://github.com/crestalnetwork/intentkit/blob/main/docs/skills/agent_api_key.md "
35
+ "Tell user to check more doc in https://github.com/crestalnetwork/intentkit/blob/main/docs/agent_api.md "
36
36
  )
37
37
  args_schema = ReadAgentApiKeyInput
38
38
 
@@ -34,7 +34,7 @@ class RegenerateAgentApiKey(SystemBaseTool):
34
34
  "Make sure to tell the user the base URL and endpoint. "
35
35
  "Tell user in OpenAI sdk or Desktop client like Cherry Studio, input the base URL and API key. "
36
36
  "Always use markdown code block to wrap the API keys, base URL, and endpoint. "
37
- "Tell user to check more doc in https://github.com/crestalnetwork/intentkit/blob/main/docs/skills/agent_api_key.md "
37
+ "Tell user to check more doc in https://github.com/crestalnetwork/intentkit/blob/main/docs/agent_api.md "
38
38
  )
39
39
  args_schema = RegenerateAgentApiKeyInput
40
40
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: intentkit
3
- Version: 0.6.2.dev1
3
+ Version: 0.6.2.dev2
4
4
  Summary: Intent-based AI Agent Platform - Core Package
5
5
  Project-URL: Homepage, https://github.com/crestal-network/intentkit
6
6
  Project-URL: Repository, https://github.com/crestal-network/intentkit
@@ -1,4 +1,4 @@
1
- intentkit/__init__.py,sha256=HBNDaJ4-iLgVtxsc42X7svB_Cpb5ZvDz_6CDzQuVI5Y,383
1
+ intentkit/__init__.py,sha256=E1dn4BImBle0LKPwKBz0OvEYCyAHMnLGo6m4GxSLwM0,383
2
2
  intentkit/abstracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  intentkit/abstracts/agent.py,sha256=108gb5W8Q1Sy4G55F2_ZFv2-_CnY76qrBtpIr0Oxxqk,1489
4
4
  intentkit/abstracts/api.py,sha256=ZUc24vaQvQVbbjznx7bV0lbbQxdQPfEV8ZxM2R6wZWo,166
@@ -9,14 +9,14 @@ intentkit/abstracts/skill.py,sha256=WS8G_XP0Ukw1eUB-dhbx6FrJUbvV4tqzRnkWa2dt9ck,
9
9
  intentkit/abstracts/twitter.py,sha256=cEtP7ygR_b-pHdc9i8kBuyooz1cPoGUGwsBHDpowJyY,1262
10
10
  intentkit/clients/__init__.py,sha256=sQ_6_bRC2MPWLPH-skQ3qsEe8ce-dUGL7i8VJOautHg,298
11
11
  intentkit/clients/cdp.py,sha256=_CkvnBkzdq7-sFMGct4lz85FpaOoHxOGstWubhClzrA,5921
12
- intentkit/clients/twitter.py,sha256=JAc-skIhZZjAFcwzLSTiOPOonteGjrl_JwXoA8IVBmI,16934
12
+ intentkit/clients/twitter.py,sha256=gT7lXYAeRACZGYrTOPjoGoVNWAC1-qn9gkASVTeDL4M,19106
13
13
  intentkit/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  intentkit/config/config.py,sha256=6RreVvQH1xuHVOnIJ3AcaRYzdMw1RLo0vYYtvPKvTds,7453
15
15
  intentkit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  intentkit/core/agent.py,sha256=PTHsFV_EbsfPUcTI0ErkebWurjxVykP9ISbNUsqV44Q,7764
17
17
  intentkit/core/api.py,sha256=3GIMJpwduLUSbVPNW6mQVxZncYHH3OlLwdiqFtYtEAE,1208
18
18
  intentkit/core/client.py,sha256=rIwtJVVm-7piXtFNDbeykt9vWdNTecgjW0aA3N-lHnM,1495
19
- intentkit/core/credit.py,sha256=fpRe8BRNGGaumAvJFgce1T2zkclExSFWQdoUVnl6k5g,60789
19
+ intentkit/core/credit.py,sha256=vLT47NlLrGyvSU1OP8dkVXV5_VHqRNSeAK5t1FqSSYs,61742
20
20
  intentkit/core/engine.py,sha256=ZoMk8fBUg1fqbELT8Pi8vB667ytFqAT4mQfUNt5g_H0,41192
21
21
  intentkit/core/node.py,sha256=RqAdcR1Fcpgw4k7q9l1Sry8LgcuZWdNxSjOHDcoavCI,9108
22
22
  intentkit/core/prompt.py,sha256=RfLhlUktkB2kCr3wfldqq6ZP2l8heZIMc8jVp31KIyQ,3631
@@ -28,7 +28,7 @@ intentkit/models/app_setting.py,sha256=WgW-9t0EbiVemRLrVaC6evdfRU5QFSDK0elsnUU5n
28
28
  intentkit/models/base.py,sha256=o-zRjVrak-f5Jokdvj8BjLm8gcC3yYiYMCTLegwT2lA,185
29
29
  intentkit/models/chat.py,sha256=2P9dPWEti9f7XbO6L6Kp89lcYuyymSwqzxhL4GfBmBc,18019
30
30
  intentkit/models/conversation.py,sha256=nrbDIw-3GK5BYi_xkI15FLdx4a6SNrFK8wfAGLCsrqk,9032
31
- intentkit/models/credit.py,sha256=tHydPpGk8c8p9TLyIb7kvII4vo2WiXvI_i6xzv9PwaQ,42091
31
+ intentkit/models/credit.py,sha256=95buGlZwIuoSPasZcqYEKvdrnUiUe2RzJCR3a2rvQvU,42397
32
32
  intentkit/models/db.py,sha256=2OpdTjQWUM9FkDP8Ni0mGLeVJ5q9ah3bGlGe9-IzDp0,3999
33
33
  intentkit/models/db_mig.py,sha256=vT6Tanm-BHC2T7dTztuB1UG494EFBAlHADKsNzR6xaQ,3577
34
34
  intentkit/models/generator.py,sha256=lyZu9U9rZUGkqd_QT5SAhay9DY358JJY8EhDSpN8I1M,10298
@@ -292,8 +292,8 @@ intentkit/skills/supabase/update_data.py,sha256=Hbwsoa52GZNTPIhWdR9vj9VlcPRUn_vC
292
292
  intentkit/skills/supabase/upsert_data.py,sha256=JgKLFPcQkUwnQhqTZojT4Ae53hYULeGEkQ1gxZJEe-c,2538
293
293
  intentkit/skills/system/__init__.py,sha256=y5sBakdOL1vtXV8DNn-g_MN11CrJ8QrOceoJjD5MzXs,2402
294
294
  intentkit/skills/system/base.py,sha256=Sm4lSNgbxwGK5YimnBfwi3Hc8E1EwSMZIXsCJbIPiLM,700
295
- intentkit/skills/system/read_agent_api_key.py,sha256=r7IfD9LCtYocqZsgSpSp7jt-fF00NuvoUwdAhZU-3Fs,3528
296
- intentkit/skills/system/regenerate_agent_api_key.py,sha256=55Jz5A6TnbSXc2FG3e7wkIxzkIIfDX0hWOENBTNkFi4,3188
295
+ intentkit/skills/system/read_agent_api_key.py,sha256=PmTi4dJ1yDsowPHk4iT0bR-g9Il_UOg895a8aWvCrUQ,3517
296
+ intentkit/skills/system/regenerate_agent_api_key.py,sha256=BaF9l3zDyzJNLoVT8ZAaZTmpXaDwumLW8VO8RLVjLyI,3177
297
297
  intentkit/skills/system/schema.json,sha256=4lv144DEDz9m1NYQdTgke3nDyCrVsGm82QiIoLbIRww,1462
298
298
  intentkit/skills/system/system.svg,sha256=PVbC6r6rOhvht0lB1fcxDNTcbMUa7haHAkJ8rxp7gm0,3740
299
299
  intentkit/skills/tavily/README.md,sha256=VagMkuHrS_ge2Sir9M9CoeqmWc_rysKhTO9-LGICQsA,2840
@@ -389,7 +389,7 @@ intentkit/utils/random.py,sha256=DymMxu9g0kuQLgJUqalvgksnIeLdS-v0aRk5nQU0mLI,452
389
389
  intentkit/utils/s3.py,sha256=9trQNkKQ5VgxWsewVsV8Y0q_pXzGRvsCYP8xauyUYkg,8549
390
390
  intentkit/utils/slack_alert.py,sha256=s7UpRgyzLW7Pbmt8cKzTJgMA9bm4EP-1rQ5KXayHu6E,2264
391
391
  intentkit/utils/tx.py,sha256=2yLLGuhvfBEY5n_GJ8wmIWLCzn0FsYKv5kRNzw_sLUI,1454
392
- intentkit-0.6.2.dev1.dist-info/METADATA,sha256=e6r6BKXz70Dh3FRE0JWsACI7_gAP7Rx5C43HmwOMFhI,7285
393
- intentkit-0.6.2.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
394
- intentkit-0.6.2.dev1.dist-info/licenses/LICENSE,sha256=Bln6DhK-LtcO4aXy-PBcdZv2f24MlJFm_qn222biJtE,1071
395
- intentkit-0.6.2.dev1.dist-info/RECORD,,
392
+ intentkit-0.6.2.dev2.dist-info/METADATA,sha256=-Gjx0m4aqm8UNe8yd_V-udLAowAwgNrp7Qb8aMgL11c,7285
393
+ intentkit-0.6.2.dev2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
394
+ intentkit-0.6.2.dev2.dist-info/licenses/LICENSE,sha256=Bln6DhK-LtcO4aXy-PBcdZv2f24MlJFm_qn222biJtE,1071
395
+ intentkit-0.6.2.dev2.dist-info/RECORD,,