@clinebot/agents 0.0.0

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.
Files changed (90) hide show
  1. package/README.md +145 -0
  2. package/dist/agent-input.d.ts +2 -0
  3. package/dist/agent.d.ts +56 -0
  4. package/dist/extensions.d.ts +21 -0
  5. package/dist/hooks/engine.d.ts +42 -0
  6. package/dist/hooks/index.d.ts +2 -0
  7. package/dist/hooks/lifecycle.d.ts +5 -0
  8. package/dist/hooks/node.d.ts +2 -0
  9. package/dist/hooks/subprocess-runner.d.ts +16 -0
  10. package/dist/hooks/subprocess.d.ts +268 -0
  11. package/dist/index.browser.d.ts +1 -0
  12. package/dist/index.browser.js +49 -0
  13. package/dist/index.d.ts +15 -0
  14. package/dist/index.js +49 -0
  15. package/dist/index.node.d.ts +5 -0
  16. package/dist/index.node.js +49 -0
  17. package/dist/mcp/index.d.ts +4 -0
  18. package/dist/mcp/policies.d.ts +14 -0
  19. package/dist/mcp/tools.d.ts +9 -0
  20. package/dist/mcp/types.d.ts +35 -0
  21. package/dist/message-builder.d.ts +31 -0
  22. package/dist/prompts/cline.d.ts +1 -0
  23. package/dist/prompts/index.d.ts +1 -0
  24. package/dist/runtime/agent-runtime-bus.d.ts +13 -0
  25. package/dist/runtime/conversation-store.d.ts +16 -0
  26. package/dist/runtime/lifecycle-orchestrator.d.ts +28 -0
  27. package/dist/runtime/tool-orchestrator.d.ts +39 -0
  28. package/dist/runtime/turn-processor.d.ts +21 -0
  29. package/dist/teams/index.d.ts +3 -0
  30. package/dist/teams/multi-agent.d.ts +566 -0
  31. package/dist/teams/spawn-agent-tool.d.ts +85 -0
  32. package/dist/teams/team-tools.d.ts +51 -0
  33. package/dist/tools/ask-question.d.ts +12 -0
  34. package/dist/tools/create.d.ts +59 -0
  35. package/dist/tools/execution.d.ts +61 -0
  36. package/dist/tools/formatting.d.ts +20 -0
  37. package/dist/tools/index.d.ts +11 -0
  38. package/dist/tools/registry.d.ts +26 -0
  39. package/dist/tools/validation.d.ts +27 -0
  40. package/dist/types.d.ts +826 -0
  41. package/package.json +54 -0
  42. package/src/agent-input.ts +116 -0
  43. package/src/agent.test.ts +931 -0
  44. package/src/agent.ts +1050 -0
  45. package/src/example.test.ts +564 -0
  46. package/src/extensions.ts +337 -0
  47. package/src/hooks/engine.test.ts +163 -0
  48. package/src/hooks/engine.ts +537 -0
  49. package/src/hooks/index.ts +6 -0
  50. package/src/hooks/lifecycle.ts +239 -0
  51. package/src/hooks/node.ts +18 -0
  52. package/src/hooks/subprocess-runner.ts +140 -0
  53. package/src/hooks/subprocess.test.ts +180 -0
  54. package/src/hooks/subprocess.ts +620 -0
  55. package/src/index.browser.ts +1 -0
  56. package/src/index.node.ts +21 -0
  57. package/src/index.ts +133 -0
  58. package/src/mcp/index.ts +17 -0
  59. package/src/mcp/policies.test.ts +51 -0
  60. package/src/mcp/policies.ts +53 -0
  61. package/src/mcp/tools.test.ts +76 -0
  62. package/src/mcp/tools.ts +60 -0
  63. package/src/mcp/types.ts +41 -0
  64. package/src/message-builder.test.ts +175 -0
  65. package/src/message-builder.ts +429 -0
  66. package/src/prompts/cline.ts +49 -0
  67. package/src/prompts/index.ts +1 -0
  68. package/src/runtime/agent-runtime-bus.ts +53 -0
  69. package/src/runtime/conversation-store.ts +61 -0
  70. package/src/runtime/lifecycle-orchestrator.ts +90 -0
  71. package/src/runtime/tool-orchestrator.ts +177 -0
  72. package/src/runtime/turn-processor.ts +250 -0
  73. package/src/streaming.test.ts +197 -0
  74. package/src/streaming.ts +307 -0
  75. package/src/teams/index.ts +63 -0
  76. package/src/teams/multi-agent.lifecycle.test.ts +48 -0
  77. package/src/teams/multi-agent.ts +1866 -0
  78. package/src/teams/spawn-agent-tool.test.ts +172 -0
  79. package/src/teams/spawn-agent-tool.ts +223 -0
  80. package/src/teams/team-tools.test.ts +448 -0
  81. package/src/teams/team-tools.ts +929 -0
  82. package/src/tools/ask-question.ts +78 -0
  83. package/src/tools/create.ts +104 -0
  84. package/src/tools/execution.ts +311 -0
  85. package/src/tools/formatting.ts +73 -0
  86. package/src/tools/index.ts +45 -0
  87. package/src/tools/registry.ts +52 -0
  88. package/src/tools/tools.test.ts +292 -0
  89. package/src/tools/validation.ts +73 -0
  90. package/src/types.ts +966 -0
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@clinebot/agents",
3
+ "version": "0.0.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/cline/cline.git",
7
+ "directory": "packages/agents"
8
+ },
9
+ "main": "dist/index.js",
10
+ "dependencies": {
11
+ "@clinebot/llms": "workspace:*",
12
+ "@clinebot/shared": "workspace:*",
13
+ "zod": "^4.3.6"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "development": "./src/index.ts",
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./node": {
22
+ "development": "./src/index.node.ts",
23
+ "types": "./src/index.node.ts",
24
+ "import": "./dist/index.node.js"
25
+ },
26
+ "./browser": {
27
+ "development": "./src/index.browser.ts",
28
+ "types": "./dist/index.browser.d.ts",
29
+ "import": "./dist/index.browser.js"
30
+ }
31
+ },
32
+ "description": "High-level SDK for building agentic loops with LLMs",
33
+ "files": [
34
+ "dist",
35
+ "src"
36
+ ],
37
+ "keywords": [
38
+ "llm",
39
+ "agents",
40
+ "ai",
41
+ "tool-calling"
42
+ ],
43
+ "license": "Apache-2.0",
44
+ "scripts": {
45
+ "build": "bun run bun.mts && bun tsc -p tsconfig.build.json",
46
+ "dev": "bun build ./src/index.ts --outdir ./dist --target node --format esm --watch",
47
+ "clean": "rm -rf dist node_modules",
48
+ "typecheck": "bun tsc -p tsconfig.dev.json --noEmit",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest"
51
+ },
52
+ "type": "module",
53
+ "types": "dist/index.d.ts"
54
+ }
@@ -0,0 +1,116 @@
1
+ import type { providers } from "@clinebot/llms";
2
+
3
+ export async function buildInitialUserContent(
4
+ userMessage: string,
5
+ userImages?: string[],
6
+ userFiles?: string[],
7
+ userFileContentLoader?: (path: string) => Promise<string>,
8
+ ): Promise<string | providers.ContentBlock[]> {
9
+ const imageBlocks = buildImageBlocks(userImages);
10
+ const fileTextBlocks = await buildUserFileContentBlock(
11
+ userFiles,
12
+ userFileContentLoader,
13
+ );
14
+
15
+ if (imageBlocks.length === 0 && !fileTextBlocks) {
16
+ return userMessage;
17
+ }
18
+
19
+ const content: providers.ContentBlock[] = [
20
+ {
21
+ type: "text",
22
+ text: userMessage,
23
+ },
24
+ ...imageBlocks,
25
+ ];
26
+ if (fileTextBlocks) {
27
+ content.push(...fileTextBlocks);
28
+ }
29
+ return content;
30
+ }
31
+
32
+ function buildImageBlocks(userImages?: string[]): providers.ImageContent[] {
33
+ if (!userImages || userImages.length === 0) {
34
+ return [];
35
+ }
36
+
37
+ const blocks: providers.ImageContent[] = [];
38
+ for (const image of userImages) {
39
+ const block = parseDataUrlImage(image);
40
+ if (block) {
41
+ blocks.push(block);
42
+ }
43
+ }
44
+ return blocks;
45
+ }
46
+
47
+ function parseDataUrlImage(image: string): providers.ImageContent | undefined {
48
+ const value = image.trim();
49
+ if (!value) {
50
+ return undefined;
51
+ }
52
+
53
+ const dataUrlMatch = value.match(/^data:([^;,]+);base64,(.+)$/);
54
+ if (dataUrlMatch) {
55
+ const mediaType = dataUrlMatch[1];
56
+ const data = dataUrlMatch[2];
57
+ if (!mediaType || !data) {
58
+ return undefined;
59
+ }
60
+ return {
61
+ type: "image",
62
+ mediaType,
63
+ data,
64
+ };
65
+ }
66
+
67
+ // Fallback: treat as plain base64 payload.
68
+ return {
69
+ type: "image",
70
+ mediaType: "image/png",
71
+ data: value,
72
+ };
73
+ }
74
+
75
+ async function buildUserFileContentBlock(
76
+ userFiles?: string[],
77
+ userFileContentLoader?: (path: string) => Promise<string>,
78
+ ): Promise<providers.FileContent[] | undefined> {
79
+ if (!userFiles || userFiles.length === 0) {
80
+ return undefined;
81
+ }
82
+
83
+ const loader =
84
+ userFileContentLoader ??
85
+ (async () => {
86
+ throw new Error(
87
+ "File loading is not configured in this runtime. Provide userFileContentLoader to enable userFiles support.",
88
+ );
89
+ });
90
+
91
+ const contents = await Promise.all(
92
+ userFiles.map(async (filePath) => {
93
+ const normalizedPath = filePath.replace(/\\/g, "/");
94
+ try {
95
+ const content = await loader(filePath);
96
+ return {
97
+ type: "file",
98
+ path: normalizedPath,
99
+ content,
100
+ } satisfies providers.FileContent;
101
+ } catch (error) {
102
+ const message = error instanceof Error ? error.message : String(error);
103
+ return {
104
+ type: "file",
105
+ path: normalizedPath,
106
+ content: `Error fetching content: ${message}`,
107
+ } satisfies providers.FileContent;
108
+ }
109
+ }),
110
+ );
111
+
112
+ if (contents.length === 0) {
113
+ return undefined;
114
+ }
115
+ return contents;
116
+ }