openai-code-assistant 1.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/README.md +44 -0
- package/dist/agents/customer-triage-agent.d.ts +3 -0
- package/dist/agents/customer-triage-agent.d.ts.map +1 -0
- package/dist/agents/customer-triage-agent.js +26 -0
- package/dist/agents/customer-triage-agent.js.map +1 -0
- package/dist/agents/manager-agent.d.ts +4 -0
- package/dist/agents/manager-agent.d.ts.map +1 -0
- package/dist/agents/manager-agent.js +38 -0
- package/dist/agents/manager-agent.js.map +1 -0
- package/dist/agents/reviewer-agent.d.ts +4 -0
- package/dist/agents/reviewer-agent.d.ts.map +1 -0
- package/dist/agents/reviewer-agent.js +20 -0
- package/dist/agents/reviewer-agent.js.map +1 -0
- package/dist/agents/supervisor-agent.d.ts +3 -0
- package/dist/agents/supervisor-agent.d.ts.map +1 -0
- package/dist/agents/supervisor-agent.js +46 -0
- package/dist/agents/supervisor-agent.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -0
- package/dist/generate-output.d.ts +7 -0
- package/dist/generate-output.d.ts.map +1 -0
- package/dist/generate-output.js +15 -0
- package/dist/generate-output.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/dynamic-prompt.d.ts +20 -0
- package/dist/tools/dynamic-prompt.d.ts.map +1 -0
- package/dist/tools/dynamic-prompt.js +48 -0
- package/dist/tools/dynamic-prompt.js.map +1 -0
- package/dist/tools/index-workspace.d.ts +3 -0
- package/dist/tools/index-workspace.d.ts.map +1 -0
- package/dist/tools/index-workspace.js +42 -0
- package/dist/tools/index-workspace.js.map +1 -0
- package/dist/tools/read-workspace.d.ts +12 -0
- package/dist/tools/read-workspace.d.ts.map +1 -0
- package/dist/tools/read-workspace.js +62 -0
- package/dist/tools/read-workspace.js.map +1 -0
- package/dist/tools/write-workspace.d.ts +16 -0
- package/dist/tools/write-workspace.d.ts.map +1 -0
- package/dist/tools/write-workspace.js +70 -0
- package/dist/tools/write-workspace.js.map +1 -0
- package/dist/utils/cmd-operations.d.ts +8 -0
- package/dist/utils/cmd-operations.d.ts.map +1 -0
- package/dist/utils/cmd-operations.js +26 -0
- package/dist/utils/cmd-operations.js.map +1 -0
- package/dist/utils/files.d.ts +10 -0
- package/dist/utils/files.d.ts.map +1 -0
- package/dist/utils/files.js +75 -0
- package/dist/utils/files.js.map +1 -0
- package/dist/utils/generate-documentation.d.ts +2 -0
- package/dist/utils/generate-documentation.d.ts.map +1 -0
- package/dist/utils/generate-documentation.js +17 -0
- package/dist/utils/generate-documentation.js.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Spey Project
|
|
2
|
+
|
|
3
|
+
## Project Description
|
|
4
|
+
Spey is an advanced agent-based system designed to facilitate automated task management through specialized agents. These agents include Customer Triage, Manager, Reviewer, and Supervisor, each handling specific operational domains like customer inquiry triage, task management, review processes, and supervision. Spey leverages OpenAI models to enhance automation and intelligence in handling workflows.
|
|
5
|
+
|
|
6
|
+
## Setup Instructions
|
|
7
|
+
1. Clone the repository.
|
|
8
|
+
2. Install dependencies:
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
```
|
|
12
|
+
3. Environment Configuration:
|
|
13
|
+
- Create a `.env` file in the root directory (if not existing).
|
|
14
|
+
- Set the following environment variables:
|
|
15
|
+
- `OPENAI_MODEL_NAME`: (Optional) OpenAI model to use. Defaults to `gpt-3.5-turbo` if unspecified.
|
|
16
|
+
- `AGENT_WORKSPACE_ROOT`: (Optional) Path to the workspace root directory. Defaults to current working directory.
|
|
17
|
+
|
|
18
|
+
## Running Instructions
|
|
19
|
+
Run the system using:
|
|
20
|
+
```bash
|
|
21
|
+
npm start
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Development vs Production
|
|
25
|
+
- In development, you can run agents individually or in watch mode for rapid feedback (setup as needed).
|
|
26
|
+
- Production mode runs the integrated system with all agents collaborating.
|
|
27
|
+
|
|
28
|
+
## Typical Workflow Example with Agents
|
|
29
|
+
- Customer Triage Agent receives and categorizes incoming customer requests.
|
|
30
|
+
- Manager Agent allocates tasks and resources based on triage results.
|
|
31
|
+
- Reviewer Agent audits completed tasks for quality assurance.
|
|
32
|
+
- Supervisor Agent oversees overall system health and performance.
|
|
33
|
+
|
|
34
|
+
## Key Configuration Constants (src/config.ts)
|
|
35
|
+
- `OPENAI_MODEL_NAME`: Specifies the AI model name, defaults to "gpt-3.5-turbo" if not set.
|
|
36
|
+
- `WORKSPACE_ROOT`: Absolute path to the project workspace root, defaulting to the current working directory, configurable via `AGENT_WORKSPACE_ROOT`.
|
|
37
|
+
|
|
38
|
+
## Dependencies
|
|
39
|
+
Spey uses key dependencies including:
|
|
40
|
+
- `dotenv`: To load environment variables.
|
|
41
|
+
- `OpenAI API Client` (assumed, based on usage): For interacting with OpenAI models.
|
|
42
|
+
- Various utilities for file handling and workspace management.
|
|
43
|
+
|
|
44
|
+
Feel free to explore the source codes under `src/` folder to understand the implementation details of each component.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer-triage-agent.d.ts","sourceRoot":"","sources":["../../src/agents/customer-triage-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAqBvC,eAAO,MAAM,yBAAyB,wBAKpC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Agent } from "@openai/agents";
|
|
2
|
+
import { readWorkspaceFileTool } from "../tools/read-workspace.js";
|
|
3
|
+
import { indexWorkspaceFilesTool } from "../tools/index-workspace.js";
|
|
4
|
+
import { dynamicPromptTool } from "../tools/dynamic-prompt.js";
|
|
5
|
+
import { OPENAI_MODEL_NAME } from "../config.js";
|
|
6
|
+
const customerAgentInstruction = `You are the intake specialist. Your job is to translate messy user asks into a concise plan for downstream agents. Operate with the following guardrails:
|
|
7
|
+
|
|
8
|
+
1. First restate the user request in your own words and call \\"index_workspace_files\\" only if you need high-level project context. Never dump more than ~50 paths; prefer filtering by folder or extension.
|
|
9
|
+
2. Only call \\"read_workspace_file\\" for files that directly influence the request, and prefer partial reads (line ranges or snippets) over entire files.
|
|
10
|
+
3. If you need to synthesize a polished plan from intermediate notes, call \\"dynamic_prompt\\" with the raw observations and let the tool format the final JSON.
|
|
11
|
+
4. Summarize insights and produce structured output JSON:
|
|
12
|
+
{
|
|
13
|
+
"summary": "one paragraph",
|
|
14
|
+
"action_items": ["imperative step"],
|
|
15
|
+
"open_questions": ["clarification you need"]
|
|
16
|
+
}
|
|
17
|
+
5. Keep the final plan under 800 words and avoid copying large code blocks—describe them instead.
|
|
18
|
+
|
|
19
|
+
Return only that JSON string; do not attempt to fix code yourself.`;
|
|
20
|
+
export const customerFacingTriageAgent = new Agent({
|
|
21
|
+
name: "Customer-facing triage agent",
|
|
22
|
+
instructions: customerAgentInstruction,
|
|
23
|
+
tools: [dynamicPromptTool, indexWorkspaceFilesTool, readWorkspaceFileTool],
|
|
24
|
+
model: OPENAI_MODEL_NAME,
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=customer-triage-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer-triage-agent.js","sourceRoot":"","sources":["../../src/agents/customer-triage-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;mEAakC,CAAC;AAEpE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,KAAK,CAAC;IACjD,IAAI,EAAE,8BAA8B;IACpC,YAAY,EAAE,wBAAwB;IACtC,KAAK,EAAE,CAAC,iBAAiB,EAAE,uBAAuB,EAAE,qBAAqB,CAAC;IAC1E,KAAK,EAAE,iBAAiB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager-agent.d.ts","sourceRoot":"","sources":["../../src/agents/manager-agent.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAyBvC,eAAO,MAAM,YAAY,wBAcvB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { Agent } from "@openai/agents";
|
|
3
|
+
import { readWorkspaceFileTool } from "../tools/read-workspace.js";
|
|
4
|
+
import { writeWorkspaceFileTool } from "../tools/write-workspace.js";
|
|
5
|
+
import { indexWorkspaceFilesTool } from "../tools/index-workspace.js";
|
|
6
|
+
import { dynamicPromptTool } from "../tools/dynamic-prompt.js";
|
|
7
|
+
import { OPENAI_MODEL_NAME } from "../config.js";
|
|
8
|
+
const managerAgentInstruction = `You orchestrate implementation. Consume the triage plan, decide what has to change, and coordinate tool usage safely:
|
|
9
|
+
|
|
10
|
+
1. Parse the triage JSON and turn each action item into a concrete change list (files, rationale, acceptance criteria).
|
|
11
|
+
2. Before editing, inspect current state by calling \\"index_workspace_files\\" (with filters) and \\"read_workspace_file\\" for only the relevant snippets.
|
|
12
|
+
3. When code changes are needed, call the \\"code_assistant\\" tool with precise instructions (file path, target block, expected behavior). Review its response before applying anything.
|
|
13
|
+
4. Write modifications via \\"write_workspace_file\\" using minimal edits, then immediately re-read the affected section to verify the change.
|
|
14
|
+
5. Keep a running summary of what was updated so the reviewer can audit later. Never leave TODOs unresolved or partially applied.
|
|
15
|
+
6. If requirements are unclear or risky, return a clarification request instead of guessing.
|
|
16
|
+
|
|
17
|
+
Final output must recap the steps taken, files touched, and remaining follow-ups.`;
|
|
18
|
+
const codingAgent = new Agent({
|
|
19
|
+
name: "Code assistant",
|
|
20
|
+
instructions: "Generate code with best practices which must adhere requirements",
|
|
21
|
+
model: OPENAI_MODEL_NAME,
|
|
22
|
+
});
|
|
23
|
+
export const managerAgent = new Agent({
|
|
24
|
+
name: "Manager agent",
|
|
25
|
+
instructions: managerAgentInstruction,
|
|
26
|
+
tools: [
|
|
27
|
+
dynamicPromptTool,
|
|
28
|
+
readWorkspaceFileTool,
|
|
29
|
+
writeWorkspaceFileTool,
|
|
30
|
+
indexWorkspaceFilesTool,
|
|
31
|
+
codingAgent.asTool({
|
|
32
|
+
toolName: "code_assistant",
|
|
33
|
+
toolDescription: "Handles coding implementations",
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
model: OPENAI_MODEL_NAME,
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=manager-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager-agent.js","sourceRoot":"","sources":["../../src/agents/manager-agent.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,uBAAuB,GAAG;;;;;;;;;kFASkD,CAAC;AAEnF,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC;IAC5B,IAAI,EAAE,gBAAgB;IACtB,YAAY,EACV,kEAAkE;IACpE,KAAK,EAAE,iBAAiB;CACzB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC;IACpC,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,uBAAuB;IACrC,KAAK,EAAE;QACL,iBAAiB;QACjB,qBAAqB;QACrB,sBAAsB;QACtB,uBAAuB;QACvB,WAAW,CAAC,MAAM,CAAC;YACjB,QAAQ,EAAE,gBAAgB;YAC1B,eAAe,EAAE,gCAAgC;SAClD,CAAC;KACH;IACD,KAAK,EAAE,iBAAiB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewer-agent.d.ts","sourceRoot":"","sources":["../../src/agents/reviewer-agent.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAcvC,eAAO,MAAM,aAAa,wBAKxB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { Agent } from "@openai/agents";
|
|
3
|
+
import { readWorkspaceFileTool } from "../tools/read-workspace.js";
|
|
4
|
+
import { writeWorkspaceFileTool } from "../tools/write-workspace.js";
|
|
5
|
+
import { indexWorkspaceFilesTool } from "../tools/index-workspace.js";
|
|
6
|
+
import { dynamicPromptTool } from "../tools/dynamic-prompt.js";
|
|
7
|
+
import { OPENAI_MODEL_NAME } from "../config.js";
|
|
8
|
+
const reviewerAgentInstruction = `You are the QA reviewer. Audit the latest changes against the original user input. Operate in a read-only manner:
|
|
9
|
+
|
|
10
|
+
1. Use the triage plan plus manager summary to understand scope. Only call \\"read_workspace_file\\" for files cited in that scope.
|
|
11
|
+
2. For each file, check functional correctness, adherence to instructions, and risk (missing tests, regressions, formatting issues).
|
|
12
|
+
3. Respond with JSON: {"verdict":"Yes|No","findings":["issue or confirmation"],"follow_up":["next action"]}. Verdict "Yes" means requirements satisfied with no blockers.
|
|
13
|
+
4. Never modify files. If information is insufficient, ask for clarifications instead of guessing.`;
|
|
14
|
+
export const reviewerAgent = new Agent({
|
|
15
|
+
name: "Reviewer agent",
|
|
16
|
+
instructions: reviewerAgentInstruction,
|
|
17
|
+
tools: [dynamicPromptTool, readWorkspaceFileTool, indexWorkspaceFilesTool],
|
|
18
|
+
model: OPENAI_MODEL_NAME,
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=reviewer-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewer-agent.js","sourceRoot":"","sources":["../../src/agents/reviewer-agent.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,wBAAwB,GAAG;;;;;mGAKkE,CAAC;AAEpG,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC;IACrC,IAAI,EAAE,gBAAgB;IACtB,YAAY,EAAE,wBAAwB;IACtC,KAAK,EAAE,CAAC,iBAAiB,EAAE,qBAAqB,EAAE,uBAAuB,CAAC;IAC1E,KAAK,EAAE,iBAAiB;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-agent.d.ts","sourceRoot":"","sources":["../../src/agents/supervisor-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAuCvC,eAAO,MAAM,eAAe,wBAa1B,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Agent } from "@openai/agents";
|
|
2
|
+
import { customerFacingTriageAgent } from "./customer-triage-agent.js";
|
|
3
|
+
import { managerAgent } from "./manager-agent.js";
|
|
4
|
+
import { reviewerAgent } from "./reviewer-agent.js";
|
|
5
|
+
import { readWorkspaceFileTool } from "../tools/read-workspace.js";
|
|
6
|
+
import { writeWorkspaceFileTool } from "../tools/write-workspace.js";
|
|
7
|
+
import { indexWorkspaceFilesTool } from "../tools/index-workspace.js";
|
|
8
|
+
import { dynamicPromptTool } from "../tools/dynamic-prompt.js";
|
|
9
|
+
import { OPENAI_MODEL_NAME } from "../config.js";
|
|
10
|
+
const triageTool = customerFacingTriageAgent.asTool({
|
|
11
|
+
toolName: "triage_specialist",
|
|
12
|
+
toolDescription: "Pre-processes user intent, reviews context selectively, and outputs structured JSON with summary/action items/open questions.",
|
|
13
|
+
});
|
|
14
|
+
const managerTool = managerAgent.asTool({
|
|
15
|
+
toolName: "implementation_manager",
|
|
16
|
+
toolDescription: "Turns triage output into concrete code changes by coordinating workspace tools and the coding assistant.",
|
|
17
|
+
});
|
|
18
|
+
const reviewerTool = reviewerAgent.asTool({
|
|
19
|
+
toolName: "qa_reviewer",
|
|
20
|
+
toolDescription: "Audits the implemented changes against the requirements and returns a verdict JSON with findings.",
|
|
21
|
+
});
|
|
22
|
+
const supervisorInstructions = `You are the supervisor responsible for delivering complete user solutions.
|
|
23
|
+
|
|
24
|
+
Workflow:
|
|
25
|
+
1. Call triage_specialist with the raw user request to obtain the structured plan JSON.
|
|
26
|
+
2. Feed that plan to implementation_manager so it performs the necessary workspace edits (it will call coding and file tools).
|
|
27
|
+
3. Once implementation is done, call qa_reviewer with the original request plus the manager summary to confirm compliance.
|
|
28
|
+
4. If qa_reviewer returns "No", summarize the findings and either re-run implementation_manager or escalate.
|
|
29
|
+
5. Keep responses concise (under 400 words) and include a final section detailing files touched and outstanding questions.
|
|
30
|
+
|
|
31
|
+
You may directly use workspace tools for quick spot checks, but prefer the specialized agents whenever possible.`;
|
|
32
|
+
export const supervisorAgent = new Agent({
|
|
33
|
+
name: "Supervisor agent",
|
|
34
|
+
instructions: supervisorInstructions,
|
|
35
|
+
tools: [
|
|
36
|
+
triageTool,
|
|
37
|
+
managerTool,
|
|
38
|
+
reviewerTool,
|
|
39
|
+
dynamicPromptTool,
|
|
40
|
+
readWorkspaceFileTool,
|
|
41
|
+
writeWorkspaceFileTool,
|
|
42
|
+
indexWorkspaceFilesTool,
|
|
43
|
+
],
|
|
44
|
+
model: OPENAI_MODEL_NAME,
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=supervisor-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-agent.js","sourceRoot":"","sources":["../../src/agents/supervisor-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,UAAU,GAAG,yBAAyB,CAAC,MAAM,CAAC;IAClD,QAAQ,EAAE,mBAAmB;IAC7B,eAAe,EACb,+HAA+H;CAClI,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC;IACtC,QAAQ,EAAE,wBAAwB;IAClC,eAAe,EACb,0GAA0G;CAC7G,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC;IACxC,QAAQ,EAAE,aAAa;IACvB,eAAe,EACb,mGAAmG;CACtG,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG;;;;;;;;;iHASkF,CAAC;AAElH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,KAAK,CAAC;IACvC,IAAI,EAAE,kBAAkB;IACxB,YAAY,EAAE,sBAAsB;IACpC,KAAK,EAAE;QACL,UAAU;QACV,WAAW;QACX,YAAY;QACZ,iBAAiB;QACjB,qBAAqB;QACrB,sBAAsB;QACtB,uBAAuB;KACxB;IACD,KAAK,EAAE,iBAAiB;CACzB,CAAC,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAGvB,eAAO,MAAM,iBAAiB,QACoB,CAAC;AAEnD,eAAO,MAAM,cAAc,QAEV,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export const OPENAI_MODEL_NAME = process.env.OPENAI_MODEL_NAME || "gpt-3.5-turbo";
|
|
4
|
+
export const WORKSPACE_ROOT = process.env.AGENT_WORKSPACE_ROOT
|
|
5
|
+
? path.resolve(process.env.AGENT_WORKSPACE_ROOT)
|
|
6
|
+
: process.cwd();
|
|
7
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,MAAM,iBAAiB,GAC5B,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,eAAe,CAAC;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB;IAC5D,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAChD,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-output.d.ts","sourceRoot":"","sources":["../src/generate-output.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAMvB,eAAO,MAAM,cAAc,GAAU,oCAIlC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;CACpC,KAAG,OAAO,CAAC,MAAM,CAWjB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { run } from "@openai/agents";
|
|
3
|
+
import { supervisorAgent } from "./agents/supervisor-agent.js";
|
|
4
|
+
import { marked } from "marked";
|
|
5
|
+
import { logOutputIteratively } from "./utils/cmd-operations.js";
|
|
6
|
+
export const generateOutput = async ({ input, conversationId, signal, }) => {
|
|
7
|
+
const logIntervalId = logOutputIteratively("thinking");
|
|
8
|
+
const result = await run(supervisorAgent, input, {
|
|
9
|
+
conversationId,
|
|
10
|
+
...(signal ? { signal } : undefined),
|
|
11
|
+
});
|
|
12
|
+
clearInterval(logIntervalId);
|
|
13
|
+
return result.finalOutput;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=generate-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-output.js","sourceRoot":"","sources":["../src/generate-output.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,EACnC,KAAK,EACL,cAAc,EACd,MAAM,GAKP,EAAmB,EAAE;IACpB,MAAM,aAAa,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,eAAe,EAAE,KAAK,EAAE;QAC/C,cAAc;QACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;KACrC,CAAC,CAAC;IAEH,aAAa,CAAC,aAAa,CAAC,CAAC;IAE7B,OAAO,MAAM,CAAC,WAAqB,CAAC;AACtC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import OpenAI from "openai";
|
|
4
|
+
import { marked } from "marked";
|
|
5
|
+
import { markedTerminal } from "marked-terminal";
|
|
6
|
+
import { generateOutput } from "./generate-output.js";
|
|
7
|
+
marked.use(markedTerminal({}));
|
|
8
|
+
const client = new OpenAI();
|
|
9
|
+
const { id: conversationId } = await client.conversations.create({});
|
|
10
|
+
// conversation history
|
|
11
|
+
const abortController = new AbortController();
|
|
12
|
+
let isProcessingRequest = false;
|
|
13
|
+
console.log("Hello! How I can assist you today? Is there something specific you need help with?");
|
|
14
|
+
console.log(marked("__Input prompt:__"));
|
|
15
|
+
process.stdin.on("data", (chunk) => {
|
|
16
|
+
const input = chunk.toString();
|
|
17
|
+
if (isProcessingRequest) {
|
|
18
|
+
console.log(marked("interrupted"));
|
|
19
|
+
abortController.abort();
|
|
20
|
+
}
|
|
21
|
+
if (input.trim()) {
|
|
22
|
+
console.log(marked("**received:** " + chunk.toString()));
|
|
23
|
+
generateOutput({
|
|
24
|
+
input,
|
|
25
|
+
conversationId,
|
|
26
|
+
signal: abortController.signal,
|
|
27
|
+
})
|
|
28
|
+
.then((result) => {
|
|
29
|
+
console.log(`\r${marked(result)}`);
|
|
30
|
+
})
|
|
31
|
+
.finally(() => {
|
|
32
|
+
isProcessingRequest = false;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(marked("__Input prompt:__"));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,CAAC;AACvB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAQ,CAAC,CAAC;AAEtC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAC5B,MAAM,EAAE,EAAE,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAErE,uBAAuB;AAEvB,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAC9C,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,OAAO,CAAC,GAAG,CACT,oFAAoF,CACrF,CAAC;AACF,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAEzC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAE/B,IAAI,mBAAmB,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;QACnC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAEzD,cAAc,CAAC;YACb,KAAK;YACL,cAAc;YACd,MAAM,EAAE,eAAe,CAAC,MAAM;SAC/B,CAAC;aACC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,OAAO,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,mBAAmB,GAAG,KAAK,CAAC;QAC9B,CAAC,CAAC,CAAC;IACP,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const dynamicPromptTool: import("@openai/agents").FunctionTool<unknown, {
|
|
2
|
+
type: "object";
|
|
3
|
+
properties: {
|
|
4
|
+
objective: {
|
|
5
|
+
type: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
workspaceSummary: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
constraints: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
required: string[];
|
|
18
|
+
additionalProperties: false;
|
|
19
|
+
}, string>;
|
|
20
|
+
//# sourceMappingURL=dynamic-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-prompt.d.ts","sourceRoot":"","sources":["../../src/tools/dynamic-prompt.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;UAgD5B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { tool } from "@openai/agents";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
export const dynamicPromptTool = tool({
|
|
4
|
+
name: "dynamic_prompt_generation",
|
|
5
|
+
description: "Generates efficient prompt for AI other tools for specific tasks",
|
|
6
|
+
parameters: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
objective: {
|
|
10
|
+
type: "string",
|
|
11
|
+
description: "Short sentence describing the current goal",
|
|
12
|
+
},
|
|
13
|
+
workspaceSummary: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "Relevant context pulled from files or tests",
|
|
16
|
+
},
|
|
17
|
+
constraints: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Hard requirements (APIs, formatting, testing, etc.)",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ["objective", "workspaceSummary", "constraints"],
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
},
|
|
25
|
+
strict: true,
|
|
26
|
+
needsApproval: async (_ctx) => false,
|
|
27
|
+
async execute({ objective, workspaceSummary, constraints }) {
|
|
28
|
+
const constraintList = constraints.length > 0
|
|
29
|
+
? constraints
|
|
30
|
+
.map((c, idx) => `${idx + 1}. ${c}`)
|
|
31
|
+
.join("\n")
|
|
32
|
+
: "None provided";
|
|
33
|
+
const prompt = [
|
|
34
|
+
"You are an expert coding copilot embedded in an orchestrated toolchain.",
|
|
35
|
+
`Primary objective: ${objective}`,
|
|
36
|
+
workspaceSummary ? `Context:\n${workspaceSummary}` : null,
|
|
37
|
+
`Constraints:\n${constraintList}`,
|
|
38
|
+
"Output expectations:",
|
|
39
|
+
"- Provide concise reasoning before sharing code.",
|
|
40
|
+
"- Prefer TypeScript, include imports, and ensure lint/tests pass.",
|
|
41
|
+
"- Flag uncertainties or missing data explicitly.",
|
|
42
|
+
]
|
|
43
|
+
.filter(Boolean)
|
|
44
|
+
.join("\n\n");
|
|
45
|
+
return { prompt };
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=dynamic-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-prompt.js","sourceRoot":"","sources":["../../src/tools/dynamic-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;IACpC,IAAI,EAAE,2BAA2B;IACjC,WAAW,EACT,kEAAkE;IACpE,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,4CAA4C;aAC1D;YACD,gBAAgB,EAAE;gBAChB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,6CAA6C;aAC3D;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,qDAAqD;aACnE;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,EAAE,kBAAkB,EAAE,aAAa,CAAC;QAC1D,oBAAoB,EAAE,KAAK;KAC5B;IACD,MAAM,EAAE,IAAI;IACZ,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK;IACpC,KAAK,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAO;QAC7D,MAAM,cAAc,GAClB,WAAW,CAAC,MAAM,GAAG,CAAC;YACpB,CAAC,CAAC,WAAW;iBACR,GAAG,CAAC,CAAC,CAAS,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;iBACnD,IAAI,CAAC,IAAI,CAAC;YACf,CAAC,CAAC,eAAe,CAAC;QAEtB,MAAM,MAAM,GAAG;YACb,yEAAyE;YACzE,sBAAsB,SAAS,EAAE;YACjC,gBAAgB,CAAC,CAAC,CAAC,aAAa,gBAAgB,EAAE,CAAC,CAAC,CAAC,IAAI;YACzD,iBAAiB,cAAc,EAAE;YACjC,sBAAsB;YACtB,kDAAkD;YAClD,mEAAmE;YACnE,kDAAkD;SACnD;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,MAAM,CAAC,CAAC;QAEhB,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-workspace.d.ts","sourceRoot":"","sources":["../../src/tools/index-workspace.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,KAAK,CAAC;AAKpB,eAAO,MAAM,uBAAuB,0FAkBlC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { tool } from "@openai/agents";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
import { WORKSPACE_ROOT } from "../config.js";
|
|
6
|
+
const workspaceRoot = WORKSPACE_ROOT;
|
|
7
|
+
export const indexWorkspaceFilesTool = tool({
|
|
8
|
+
name: "index_workspace_files",
|
|
9
|
+
description: "Index all existing files under the workspace root and return relative paths.",
|
|
10
|
+
parameters: z.object({}),
|
|
11
|
+
// {
|
|
12
|
+
// type: "object",
|
|
13
|
+
// properties: {},
|
|
14
|
+
// additionalProperties: false,
|
|
15
|
+
// required: [],
|
|
16
|
+
// },
|
|
17
|
+
strict: true,
|
|
18
|
+
needsApproval: async (_ctx) => false,
|
|
19
|
+
async execute() {
|
|
20
|
+
const files = [];
|
|
21
|
+
await traverse(workspaceRoot, files);
|
|
22
|
+
return JSON.stringify({ files });
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const defaultExclusions = ["node_modules"];
|
|
26
|
+
async function traverse(dir, files, exclusions = []) {
|
|
27
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
28
|
+
const allExclusions = [...exclusions, ...defaultExclusions];
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (allExclusions.some((exclusion) => exclusion.includes(entry.name))) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const fullPath = path.join(dir, entry.name);
|
|
34
|
+
if (entry.isDirectory()) {
|
|
35
|
+
await traverse(fullPath, files, exclusions);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
files.push(path.relative(workspaceRoot, fullPath));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index-workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-workspace.js","sourceRoot":"","sources":["../../src/tools/index-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;IAC1C,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EACT,8EAA8E;IAChF,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACxB,MAAM;IACN,sBAAsB;IAC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+1,12 @@
|
|
|
1
|
+
export declare const readWorkspaceFileTool: import("@openai/agents").FunctionTool<unknown, {
|
|
2
|
+
type: "object";
|
|
3
|
+
properties: {
|
|
4
|
+
relativePath: {
|
|
5
|
+
type: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
required: string[];
|
|
10
|
+
additionalProperties: false;
|
|
11
|
+
}, string>;
|
|
12
|
+
//# sourceMappingURL=read-workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-workspace.d.ts","sourceRoot":"","sources":["../../src/tools/read-workspace.ts"],"names":[],"mappings":"AAgDA,eAAO,MAAM,qBAAqB;;;;;;;;;;UAsBhC,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// import path from "node:path";
|
|
2
|
+
// import fs from "node:fs/promises";
|
|
3
|
+
// const workspaceRoot = new URL("../", import.meta.url).pathname;
|
|
4
|
+
// export const readWorkspaceFileTool = {
|
|
5
|
+
// type: "function",
|
|
6
|
+
// name: "read_workspace_file",
|
|
7
|
+
// description: "Return UTF-8 contents of a project file for inspection.",
|
|
8
|
+
// parameters: {
|
|
9
|
+
// type: "object",
|
|
10
|
+
// properties: {
|
|
11
|
+
// relativePath: {
|
|
12
|
+
// type: "string",
|
|
13
|
+
// description: "Path relative to the workspace root, e.g. src/index.ts",
|
|
14
|
+
// },
|
|
15
|
+
// },
|
|
16
|
+
// required: ["relativePath"],
|
|
17
|
+
// },
|
|
18
|
+
// execute: async ({ relativePath }: { relativePath: string }) => {
|
|
19
|
+
// const candidate = path.join(workspaceRoot, relativePath);
|
|
20
|
+
// if (!candidate.startsWith(workspaceRoot)) {
|
|
21
|
+
// throw new Error("Path outside workspace.");
|
|
22
|
+
// }
|
|
23
|
+
// const text = await fs.readFile(candidate, "utf8");
|
|
24
|
+
// return { content: text };
|
|
25
|
+
// },
|
|
26
|
+
// };
|
|
27
|
+
import path from "node:path";
|
|
28
|
+
import fs from "node:fs/promises";
|
|
29
|
+
import { tool } from "@openai/agents";
|
|
30
|
+
import { WORKSPACE_ROOT } from "../config.js";
|
|
31
|
+
const workspaceRoot = WORKSPACE_ROOT;
|
|
32
|
+
const resolveWorkspacePath = (relativePath) => {
|
|
33
|
+
const candidate = path.resolve(workspaceRoot, relativePath);
|
|
34
|
+
if (!candidate.startsWith(workspaceRoot)) {
|
|
35
|
+
throw new Error("Path outside workspace.");
|
|
36
|
+
}
|
|
37
|
+
return candidate;
|
|
38
|
+
};
|
|
39
|
+
export const readWorkspaceFileTool = tool({
|
|
40
|
+
name: "read_workspace_file",
|
|
41
|
+
description: "Return UTF-8 contents of a project file for inspection.",
|
|
42
|
+
parameters: {
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: {
|
|
45
|
+
relativePath: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "Path relative to the workspace root, e.g. src/index.ts",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["relativePath"],
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
},
|
|
53
|
+
strict: true,
|
|
54
|
+
needsApproval: async () => false,
|
|
55
|
+
async execute(input) {
|
|
56
|
+
const { relativePath } = input;
|
|
57
|
+
const filePath = resolveWorkspacePath(relativePath);
|
|
58
|
+
const text = await fs.readFile(filePath, "utf8");
|
|
59
|
+
return { content: text };
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=read-workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-workspace.js","sourceRoot":"","sources":["../../src/tools/read-workspace.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,qCAAqC;AAErC,kEAAkE;AAElE,yCAAyC;AACzC,sBAAsB;AACtB,iCAAiC;AACjC,4EAA4E;AAC5E,kBAAkB;AAClB,sBAAsB;AACtB,oBAAoB;AACpB,wBAAwB;AACxB,0BAA0B;AAC1B,iFAAiF;AACjF,WAAW;AACX,SAAS;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QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACjD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const writeWorkspaceFileTool: import("@openai/agents").FunctionTool<unknown, {
|
|
2
|
+
type: "object";
|
|
3
|
+
properties: {
|
|
4
|
+
relativePath: {
|
|
5
|
+
type: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
content: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
required: string[];
|
|
14
|
+
additionalProperties: false;
|
|
15
|
+
}, string>;
|
|
16
|
+
//# sourceMappingURL=write-workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-workspace.d.ts","sourceRoot":"","sources":["../../src/tools/write-workspace.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;UAwDjC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { tool } from "@openai/agents";
|
|
4
|
+
import { WORKSPACE_ROOT } from "../config.js";
|
|
5
|
+
const workspaceRoot = WORKSPACE_ROOT;
|
|
6
|
+
const resolveWorkspacePath = (relativePath) => {
|
|
7
|
+
const candidate = path.resolve(workspaceRoot, relativePath);
|
|
8
|
+
if (!candidate.startsWith(workspaceRoot)) {
|
|
9
|
+
throw new Error("Path outside workspace.");
|
|
10
|
+
}
|
|
11
|
+
return candidate;
|
|
12
|
+
};
|
|
13
|
+
export const writeWorkspaceFileTool = tool({
|
|
14
|
+
name: "write_workspace_file",
|
|
15
|
+
description: "Write UTF-8 content project file.",
|
|
16
|
+
parameters: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
relativePath: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Path relative to the workspace root, e.g. src/index.ts",
|
|
22
|
+
},
|
|
23
|
+
content: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: `Content of project file to write/store. It will create file if file doesn't exist
|
|
26
|
+
|
|
27
|
+
e.g.:
|
|
28
|
+
import fs from "fs";
|
|
29
|
+
import path from "path";
|
|
30
|
+
|
|
31
|
+
export function indexFiles(directory: string, fileExtensions: string[] = []) {
|
|
32
|
+
const files: string[] = [];
|
|
33
|
+
|
|
34
|
+
function traverse(dir: string) {
|
|
35
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
36
|
+
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
const fullPath = path.join(dir, entry.name);
|
|
39
|
+
|
|
40
|
+
if (entry.isDirectory()) {
|
|
41
|
+
traverse(fullPath);
|
|
42
|
+
} else if (
|
|
43
|
+
fileExtensions.length === 0 || // If no extensions are specified, include all files
|
|
44
|
+
fileExtensions.includes(path.extname(entry.name))
|
|
45
|
+
) {
|
|
46
|
+
files.push(fullPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
traverse(directory);
|
|
52
|
+
return files;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
`,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["relativePath", "content"],
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
},
|
|
61
|
+
strict: true,
|
|
62
|
+
needsApproval: async () => false,
|
|
63
|
+
async execute(input) {
|
|
64
|
+
const { relativePath, content } = input;
|
|
65
|
+
const candidate = resolveWorkspacePath(relativePath);
|
|
66
|
+
await fs.writeFile(candidate, content, "utf8");
|
|
67
|
+
return { content: "OK", isSaved: true };
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=write-workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-workspace.js","s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M,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const logOutputIteratively: (input: string) => NodeJS.Timeout;
|
|
2
|
+
type Option = {
|
|
3
|
+
value: string;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function selectOption(options: Option[]): Promise<any>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=cmd-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmd-operations.d.ts","sourceRoot":"","sources":["../../src/utils/cmd-operations.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,mBAcjD,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,gBAWnD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
export const logOutputIteratively = (input) => {
|
|
3
|
+
let index = 1;
|
|
4
|
+
const intervalTimeout = setInterval(() => {
|
|
5
|
+
process.stdout.write("\r");
|
|
6
|
+
process.stdout.write(" ".repeat(40));
|
|
7
|
+
process.stdout.write(`\r${input}${".".repeat(index)}`);
|
|
8
|
+
index++;
|
|
9
|
+
if (index > 3) {
|
|
10
|
+
index = 1;
|
|
11
|
+
}
|
|
12
|
+
}, 500);
|
|
13
|
+
return intervalTimeout;
|
|
14
|
+
};
|
|
15
|
+
export async function selectOption(options) {
|
|
16
|
+
const { choice } = await inquirer.prompt([
|
|
17
|
+
{
|
|
18
|
+
type: "list",
|
|
19
|
+
name: "choice",
|
|
20
|
+
message: "Pick an action:",
|
|
21
|
+
choices: options,
|
|
22
|
+
},
|
|
23
|
+
]);
|
|
24
|
+
return choice;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=cmd-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmd-operations.js","sourceRoot":"","sources":["../../src/utils/cmd-operations.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAE,EAAE;IACpD,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE;QACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvD,KAAK,EAAE,CAAC;QACR,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC;IACH,CAAC,EAAE,GAAG,CAAC,CAAC;IAER,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAMF,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAiB;IAClD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;QACvC;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,iBAAiB;YAC1B,OAAO,EAAE,OAAO;SACjB;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function traverse({ dir, files, workspaceRoot, }: {
|
|
2
|
+
dir: string;
|
|
3
|
+
files: string[];
|
|
4
|
+
workspaceRoot: string;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
export declare function indexFiles(directory: string, fileExtensions?: string[]): Promise<string[]>;
|
|
7
|
+
export declare function buildSearchableIndex(directory: string, fileExtensions?: string[]): Record<string, string>;
|
|
8
|
+
export declare function readFileContent(filePath: string): string | null;
|
|
9
|
+
export declare function getFileContentWithCache(fileCache: Record<string, string>, filePath: string): string | null;
|
|
10
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/utils/files.ts"],"names":[],"mappings":"AAIA,wBAAsB,QAAQ,CAAC,EAC7B,GAAG,EACH,KAAK,EACL,aAAa,GACd,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB,iBAUA;AAED,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,cAAc,GAAE,MAAM,EAAO,qBAuB9B;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,cAAc,GAAE,MAAM,EAAO,0BA0B9B;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,iBAQ/C;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,QAAQ,EAAE,MAAM,iBAWjB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import fsPromise from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export async function traverse({ dir, files, workspaceRoot, }) {
|
|
5
|
+
const entries = await fsPromise.readdir(dir, { withFileTypes: true });
|
|
6
|
+
for (const entry of entries) {
|
|
7
|
+
const fullPath = path.join(dir, entry.name);
|
|
8
|
+
if (entry.isDirectory()) {
|
|
9
|
+
await traverse({ dir: fullPath, files, workspaceRoot });
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
files.push(path.relative(workspaceRoot, fullPath));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function indexFiles(directory, fileExtensions = []) {
|
|
17
|
+
const files = [];
|
|
18
|
+
async function traverse(dir) {
|
|
19
|
+
const entries = await fsPromise.readdir(dir, { withFileTypes: true });
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
const fullPath = path.join(dir, entry.name);
|
|
22
|
+
if (entry.isDirectory()) {
|
|
23
|
+
traverse(fullPath);
|
|
24
|
+
}
|
|
25
|
+
else if (fileExtensions.length === 0 || // If no extensions are specified, include all files
|
|
26
|
+
fileExtensions.includes(path.extname(entry.name))) {
|
|
27
|
+
files.push(fullPath);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await traverse(directory);
|
|
32
|
+
return files;
|
|
33
|
+
}
|
|
34
|
+
export function buildSearchableIndex(directory, fileExtensions = []) {
|
|
35
|
+
const index = {};
|
|
36
|
+
function traverse(dir) {
|
|
37
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
const fullPath = path.join(dir, entry.name);
|
|
40
|
+
if (entry.isDirectory()) {
|
|
41
|
+
traverse(fullPath);
|
|
42
|
+
}
|
|
43
|
+
else if (fileExtensions.length === 0 || // If no extensions are specified, include all files
|
|
44
|
+
fileExtensions.includes(path.extname(entry.name))) {
|
|
45
|
+
const content = readFileContent(fullPath);
|
|
46
|
+
if (content) {
|
|
47
|
+
index[fullPath] = content;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
traverse(directory);
|
|
53
|
+
return index;
|
|
54
|
+
}
|
|
55
|
+
export function readFileContent(filePath) {
|
|
56
|
+
try {
|
|
57
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
58
|
+
return content;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(`Error reading file ${filePath}:`, error.message);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function getFileContentWithCache(fileCache, filePath) {
|
|
66
|
+
if (fileCache[filePath]) {
|
|
67
|
+
return fileCache[filePath];
|
|
68
|
+
}
|
|
69
|
+
const content = readFileContent(filePath);
|
|
70
|
+
if (content) {
|
|
71
|
+
fileCache[filePath] = content;
|
|
72
|
+
}
|
|
73
|
+
return content;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/utils/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,EAC7B,GAAG,EACH,KAAK,EACL,aAAa,GAKd;IACC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,MAAM,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;QACrD,CAAC;IACH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ot":"","sources":["../../src/utils/generate-documentation.ts"],"names":[],"mappings":"AAMA,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,+BAc3D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { readFileContent } from "./files.js";
|
|
3
|
+
const MODEL = "gpt-3.5-turbo";
|
|
4
|
+
const openai = new OpenAI();
|
|
5
|
+
export async function generateDocumentation(filePath) {
|
|
6
|
+
const fileContent = readFileContent(filePath);
|
|
7
|
+
if (!fileContent) {
|
|
8
|
+
return "Error: Unable to read file content.";
|
|
9
|
+
}
|
|
10
|
+
const response = await openai.completions.create({
|
|
11
|
+
model: MODEL,
|
|
12
|
+
prompt: `Generate documentation for the following code:\n\n${fileContent}`,
|
|
13
|
+
max_tokens: 300,
|
|
14
|
+
});
|
|
15
|
+
return response.choices[0]?.text;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=generate-documentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-documentation.js","sourceRoot":"","sources":["../../src/utils/generate-documentation.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,KAAK,GAAG,eAAe,CAAC;AAC9B,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAgB;IAC1D,MAAM,WAAW,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAE9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,qCAAqC,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;QAC/C,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,qDAAqD,WAAW,EAAE;QAC1E,UAAU,EAAE,GAAG;KAChB,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;AACnC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openai-code-assistant",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
6
|
+
"start": "node dist/index.js",
|
|
7
|
+
"dev": "tsx src/index.ts",
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
9
|
+
"build": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"openai-code-assistant": "dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"description": "",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.3.3",
|
|
20
|
+
"ts-node": "^10.9.2",
|
|
21
|
+
"ts-node-dev": "^2.0.0",
|
|
22
|
+
"tsx": "^4.21.0",
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@openai/agents": "^0.5.3",
|
|
27
|
+
"@types/inquirer": "^9.0.9",
|
|
28
|
+
"@types/marked-terminal": "^6.1.1",
|
|
29
|
+
"dotenv": "^17.3.1",
|
|
30
|
+
"inquirer": "^13.3.0",
|
|
31
|
+
"marked": "^15.0.12",
|
|
32
|
+
"marked-terminal": "^7.3.0",
|
|
33
|
+
"openai": "^6.25.0",
|
|
34
|
+
"zod": "^4.3.6"
|
|
35
|
+
}
|
|
36
|
+
}
|