rusticai-claude 1.0.0__tar.gz

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.
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: rusticai-claude
3
+ Version: 1.0.0
4
+ Summary: Claude Integration
5
+ License-Expression: Apache-2.0
6
+ Author: Dragonscale Industries Inc.
7
+ Author-email: dev@dragonscale.ai
8
+ Requires-Python: >=3.12,<3.13
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Provides-Extra: test
12
+ Requires-Dist: claude-agent-sdk (>=0.1.0,<0.2.0)
13
+ Requires-Dist: rusticai-core (>=1.0.0,<1.1.0)
14
+ Project-URL: Homepage, https://www.rustic.ai/
15
+ Project-URL: Repository, https://github.com/dragonscale-ai/rustic-ai
16
+ Project-URL: Rustic AI Core, https://pypi.org/project/rusticai-core/
17
+ Description-Content-Type: text/markdown
18
+
19
+ # claude
20
+
21
+ Claude Integration
22
+
23
+ ## Configure claude code to use vertex ai
24
+ Set the following environment variables:
25
+
26
+ ```bash
27
+ export CLAUDE_CODE_USE_VERTEX=1
28
+ export CLOUD_ML_REGION=global
29
+ export ANTHROPIC_VERTEX_PROJECT_ID=YOUR-PROJECT-ID
30
+ ```
31
+
32
+ refer docs for more info: https://code.claude.com/docs/en/google-vertex-ai
@@ -0,0 +1,14 @@
1
+ # claude
2
+
3
+ Claude Integration
4
+
5
+ ## Configure claude code to use vertex ai
6
+ Set the following environment variables:
7
+
8
+ ```bash
9
+ export CLAUDE_CODE_USE_VERTEX=1
10
+ export CLOUD_ML_REGION=global
11
+ export ANTHROPIC_VERTEX_PROJECT_ID=YOUR-PROJECT-ID
12
+ ```
13
+
14
+ refer docs for more info: https://code.claude.com/docs/en/google-vertex-ai
@@ -0,0 +1,75 @@
1
+ [build-system]
2
+ requires = ["poetry-core"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+
6
+ [project]
7
+ name = "rusticai-claude"
8
+ version = "1.0.0"
9
+ description = "Claude Integration"
10
+ authors = [{name = "Dragonscale Industries Inc.", email = "dev@dragonscale.ai"}]
11
+ license = "Apache-2.0"
12
+ readme = "README.md"
13
+ requires-python = ">=3.12,<3.13"
14
+ urls = { Homepage = "https://www.rustic.ai/", Repository = "https://github.com/dragonscale-ai/rustic-ai", "Rustic AI Core" = "https://pypi.org/project/rusticai-core/" }
15
+ dynamic = ["dependencies"]
16
+
17
+ [tool.poetry]
18
+ packages = [{ include = "rustic_ai", from = "src" }]
19
+
20
+ [tool.poetry.dependencies]
21
+ rusticai-core = { version = "1.0.0"}
22
+ claude-agent-sdk = "^0.1.0"
23
+
24
+ [tool.poetry-monorepo.deps]
25
+
26
+
27
+ [tool.poetry.group.dev]
28
+ optional = true
29
+
30
+ [tool.poetry.group.dev.dependencies]
31
+ pytest = "^8.3.4"
32
+ black = { version = "^24.2.0", extras = ["jupyter"] }
33
+ flake8 = "^7.1.2"
34
+ tox = "^4.24.1"
35
+ isort = "^6.0.0"
36
+ mypy = "^1.15.0"
37
+ flaky = "^3.8.1"
38
+ pytest-asyncio = "^0.26.0"
39
+ rusticai-testing = { version = "1.0.0"}
40
+
41
+ [tool.poetry.extras]
42
+ test = ["pytest"]
43
+
44
+ [tool.black]
45
+ line-length = 120
46
+ target-version = ['py312']
47
+ include = '\.pyi?$'
48
+ exclude = '''
49
+ /(
50
+ \.git
51
+ | \.mypy_cache
52
+ | \.tox
53
+ | \.venv
54
+ | _build
55
+ | buck-out
56
+ | build
57
+ | dist
58
+ )/
59
+ '''
60
+
61
+ [tool.mypy]
62
+ python_version = "3.12"
63
+ ignore_missing_imports = true
64
+ check_untyped_defs = true
65
+ plugins = "pydantic.mypy"
66
+ explicit_package_bases = true
67
+
68
+
69
+ [tool.isort]
70
+ profile = "black"
71
+ force_sort_within_sections = true # For the sorting order issues
72
+ lines_between_sections = 1 # For the newline issue
73
+ known_third_party = ["pydantic"]
74
+ known_first_party = ["rustic_ai.core"]
75
+
@@ -0,0 +1,3 @@
1
+ from .agent import ClaudeCodeAgent, ClaudeCodeAgentProps
2
+
3
+ __all__ = ["ClaudeCodeAgent", "ClaudeCodeAgentProps"]
@@ -0,0 +1,174 @@
1
+ from datetime import datetime
2
+ import os
3
+
4
+ from claude_agent_sdk import AssistantMessage as ClaudeAssistantMessage
5
+ from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient, TextBlock
6
+ from pydantic import BaseModel
7
+
8
+ from rustic_ai.core import Agent
9
+ from rustic_ai.core.agents.commons import ErrorMessage
10
+ from rustic_ai.core.guild import agent
11
+ from rustic_ai.core.guild.agent_ext.depends.llm.models import (
12
+ AssistantMessage,
13
+ ChatCompletionRequest,
14
+ ChatCompletionResponse,
15
+ Choice,
16
+ FinishReason,
17
+ )
18
+ from rustic_ai.core.guild.dsl import BaseAgentProps
19
+
20
+
21
+ class ClaudeCodeAgentProps(BaseAgentProps):
22
+ """Properties for the ClaudeCodeAgent."""
23
+
24
+ allowed_tools: list[str] = ["Edit", "Read", "Write", "Glob", "Grep", "Skill"]
25
+ permission_mode: str = "acceptEdits" # or "ask"
26
+ session_id: str = "default"
27
+ setting_sources: list[str] = ["project"]
28
+
29
+
30
+ class AddClaudeAgentRequest(BaseModel):
31
+ name: str
32
+ config: str
33
+
34
+
35
+ class AddClaudeSkillRequest(BaseModel):
36
+ name: str
37
+ skill: str
38
+
39
+
40
+ class ClaudeCodeAgent(Agent[ClaudeCodeAgentProps]):
41
+ """
42
+ Agent validation for Claude Code integration.
43
+
44
+ # The SDK will automatically detect subagents in .claude/agents/
45
+ # and skills in .claude/skills/ based on the configuration above (setting_source = 'project').
46
+ # You can now prompt Claude to use them.
47
+ """
48
+
49
+ def __init__(self):
50
+ self.options = ClaudeAgentOptions(
51
+ allowed_tools=self.config.allowed_tools,
52
+ permission_mode=self.config.permission_mode,
53
+ setting_sources=self.config.setting_sources,
54
+ )
55
+ self.claude_client = ClaudeSDKClient(options=self.options)
56
+ self._is_connected = False
57
+
58
+ async def _ensure_connected(self):
59
+ if not self._is_connected:
60
+ await self.claude_client.connect()
61
+ self._is_connected = True
62
+
63
+ async def refresh(self):
64
+ """
65
+ Refreshes the Claude SDK client to pick up new agents and skills.
66
+ """
67
+ if self._is_connected:
68
+ await self.claude_client.disconnect()
69
+ self._is_connected = False
70
+
71
+ # Re-initialize the client
72
+ self.claude_client = ClaudeSDKClient(options=self.options)
73
+
74
+ @agent.processor(AddClaudeAgentRequest)
75
+ def add_agent(self, ctx: agent.ProcessContext[AddClaudeAgentRequest]):
76
+ """
77
+ Adds a new agent configuration at runtime.
78
+
79
+ Args:
80
+ name: The name of the agent (file name without extension).
81
+ config: The content of the agent configuration (Markdown).
82
+ """
83
+
84
+ payload = ctx.payload
85
+ agents_dir = "./.claude/agents"
86
+ os.makedirs(agents_dir, exist_ok=True)
87
+
88
+ file_path = os.path.join(agents_dir, f"{payload.name}.md")
89
+ with open(file_path, "w") as f:
90
+ f.write(payload.config)
91
+
92
+ self.refresh()
93
+
94
+ @agent.processor(AddClaudeSkillRequest)
95
+ def add_skill(self, ctx: agent.ProcessContext[AddClaudeSkillRequest]):
96
+ """
97
+ Adds a new skill at runtime.
98
+
99
+ Args:
100
+ name: The name of the skill (file name without extension).
101
+ skill: The content of the skill (Markdown).
102
+ """
103
+ payload = ctx.payload
104
+ skills_dir = "./.claude/skills"
105
+ os.makedirs(skills_dir, exist_ok=True)
106
+
107
+ file_path = os.path.join(skills_dir, f"{payload.name}.md")
108
+ with open(file_path, "w") as f:
109
+ f.write(payload.skill)
110
+
111
+ self.refresh()
112
+
113
+ @agent.processor(ChatCompletionRequest)
114
+ async def on_message(self, ctx: agent.ProcessContext[ChatCompletionRequest]):
115
+ """
116
+ Handles incoming messages and forwards them to Claude.
117
+ """
118
+ try:
119
+ await self._ensure_connected()
120
+
121
+ # Extract text from message payload
122
+ prompt = ""
123
+ if ctx.payload.messages:
124
+ # Use the last message content as prompt (simplification)
125
+ # Ideally we should construct the full history if supported by SDK in this way
126
+ prompt = ctx.payload.messages[-1].content
127
+
128
+ if not prompt:
129
+ ctx.send_error(
130
+ payload=ErrorMessage(
131
+ agent_type="ClaudeCodeAgent",
132
+ error_type="InputError",
133
+ error_message="No prompt found in request",
134
+ )
135
+ )
136
+ return
137
+
138
+ # Send query to Claude
139
+ await self.claude_client.query(prompt, session_id=self.config.session_id)
140
+
141
+ # Stream response back
142
+ response_text = ""
143
+ async for message in self.claude_client.receive_response():
144
+ if isinstance(message, ClaudeAssistantMessage):
145
+ for block in message.content:
146
+ if isinstance(block, TextBlock):
147
+ response_text += block.text
148
+
149
+ # Create ChatCompletionResponse
150
+ response_id = f"chatcmpl-{ctx.message.id}"
151
+
152
+ ccr = ChatCompletionResponse(
153
+ id=response_id,
154
+ choices=[
155
+ Choice(index=0, message=AssistantMessage(content=response_text), finish_reason=FinishReason.stop)
156
+ ],
157
+ model="claude-code", # or derived from somewhere
158
+ created=int(datetime.now().timestamp()),
159
+ )
160
+
161
+ # Send result back
162
+ ctx.send(ccr)
163
+
164
+ except Exception as e:
165
+ self.logger.error(f"Error in ClaudeCodeAgent: {e}")
166
+ ctx.send_error(
167
+ payload=ErrorMessage(agent_type="ClaudeCodeAgent", error_type="ProcessingError", error_message=str(e))
168
+ )
169
+
170
+ async def shutdown(self):
171
+ """Cleanup connection."""
172
+ if self._is_connected:
173
+ await self.claude_client.disconnect()
174
+ self._is_connected = False