@iinm/plain-agent 1.8.4 → 1.8.5

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 (84) hide show
  1. package/bin/plain +1 -1
  2. package/package.json +7 -5
  3. package/sandbox/bin/plain-sandbox +13 -0
  4. package/src/agent.d.ts +52 -0
  5. package/src/agent.mjs +204 -0
  6. package/src/agentLoop.mjs +419 -0
  7. package/src/agentState.mjs +41 -0
  8. package/src/claudeCodePlugin.mjs +164 -0
  9. package/src/cliArgs.mjs +175 -0
  10. package/src/cliBatch.mjs +147 -0
  11. package/src/cliCommands.mjs +283 -0
  12. package/src/cliCompleter.mjs +227 -0
  13. package/src/cliCost.mjs +309 -0
  14. package/src/cliFormatter.mjs +413 -0
  15. package/src/cliInteractive.mjs +529 -0
  16. package/src/cliInterruptTransform.mjs +51 -0
  17. package/src/cliMuteTransform.mjs +26 -0
  18. package/src/cliPasteTransform.mjs +183 -0
  19. package/src/config.d.ts +36 -0
  20. package/src/config.mjs +197 -0
  21. package/src/context/loadAgentRoles.mjs +294 -0
  22. package/src/context/loadPrompts.mjs +337 -0
  23. package/src/context/loadUserMessageContext.mjs +147 -0
  24. package/src/costTracker.mjs +210 -0
  25. package/src/env.mjs +44 -0
  26. package/src/main.mjs +281 -0
  27. package/src/mcpClient.mjs +351 -0
  28. package/src/mcpIntegration.mjs +160 -0
  29. package/src/model.d.ts +109 -0
  30. package/src/modelCaller.mjs +32 -0
  31. package/src/modelDefinition.d.ts +92 -0
  32. package/src/prompt.mjs +138 -0
  33. package/src/providers/anthropic.d.ts +248 -0
  34. package/src/providers/anthropic.mjs +587 -0
  35. package/src/providers/bedrock.d.ts +249 -0
  36. package/src/providers/bedrock.mjs +700 -0
  37. package/src/providers/gemini.d.ts +208 -0
  38. package/src/providers/gemini.mjs +754 -0
  39. package/src/providers/openai.d.ts +281 -0
  40. package/src/providers/openai.mjs +544 -0
  41. package/src/providers/openaiCompatible.d.ts +147 -0
  42. package/src/providers/openaiCompatible.mjs +652 -0
  43. package/src/providers/platform/awsSigV4.mjs +184 -0
  44. package/src/providers/platform/azure.mjs +42 -0
  45. package/src/providers/platform/bedrock.mjs +78 -0
  46. package/src/providers/platform/googleCloud.mjs +34 -0
  47. package/src/subagent.mjs +265 -0
  48. package/src/tmpfile.mjs +27 -0
  49. package/src/tool.d.ts +74 -0
  50. package/src/toolExecutor.mjs +236 -0
  51. package/src/toolInputValidator.mjs +183 -0
  52. package/src/toolUseApprover.mjs +99 -0
  53. package/src/tools/askURL.mjs +209 -0
  54. package/src/tools/askWeb.mjs +208 -0
  55. package/src/tools/compactContext.d.ts +4 -0
  56. package/src/tools/compactContext.mjs +87 -0
  57. package/src/tools/execCommand.d.ts +22 -0
  58. package/src/tools/execCommand.mjs +200 -0
  59. package/src/tools/patchFile.d.ts +4 -0
  60. package/src/tools/patchFile.mjs +133 -0
  61. package/src/tools/switchToMainAgent.d.ts +3 -0
  62. package/src/tools/switchToMainAgent.mjs +43 -0
  63. package/src/tools/switchToSubagent.d.ts +4 -0
  64. package/src/tools/switchToSubagent.mjs +59 -0
  65. package/src/tools/tmuxCommand.d.ts +14 -0
  66. package/src/tools/tmuxCommand.mjs +194 -0
  67. package/src/tools/writeFile.d.ts +4 -0
  68. package/src/tools/writeFile.mjs +56 -0
  69. package/src/usageStore.mjs +167 -0
  70. package/src/utils/evalJSONConfig.mjs +72 -0
  71. package/src/utils/matchValue.d.ts +6 -0
  72. package/src/utils/matchValue.mjs +40 -0
  73. package/src/utils/noThrow.mjs +31 -0
  74. package/src/utils/notify.mjs +29 -0
  75. package/src/utils/parseFileRange.mjs +18 -0
  76. package/src/utils/readFileRange.mjs +33 -0
  77. package/src/utils/retryOnError.mjs +41 -0
  78. package/src/voiceInput.mjs +61 -0
  79. package/src/voiceInputGemini.mjs +105 -0
  80. package/src/voiceInputOpenAI.mjs +104 -0
  81. package/src/voiceInputSession.mjs +543 -0
  82. package/src/voiceToggleKey.mjs +62 -0
  83. package/dist/main.mjs +0 -473
  84. package/dist/main.mjs.map +0 -7
@@ -0,0 +1,249 @@
1
+ /* Model Configuration */
2
+ export type BedrockConverseModelConfig = {
3
+ model: string;
4
+ inferenceConfig?: {
5
+ maxTokens?: number;
6
+ temperature?: number;
7
+ topP?: number;
8
+ };
9
+ additionalModelRequestFields?: Record<string, unknown>;
10
+ enablePromptCaching?: boolean;
11
+ };
12
+
13
+ /* Request */
14
+ export type BedrockConverseRequest = {
15
+ modelId?: string;
16
+ messages: BedrockMessage[];
17
+ system?: BedrockSystemContentBlock[];
18
+ toolConfig?: BedrockToolConfig;
19
+ additionalModelRequestFields?: Record<string, unknown>;
20
+ inferenceConfig?: {
21
+ maxTokens?: number;
22
+ temperature?: number;
23
+ };
24
+ };
25
+
26
+ /* Message */
27
+ export type BedrockMessage = BedrockUserMessage | BedrockAssistantMessage;
28
+
29
+ export type BedrockUserMessage = {
30
+ role: "user";
31
+ content: BedrockContentBlock[];
32
+ };
33
+
34
+ export type BedrockAssistantMessage = {
35
+ role: "assistant";
36
+ content: BedrockAssistantContentBlock[];
37
+ };
38
+
39
+ export type BedrockSystemContentBlock =
40
+ | {
41
+ text: string;
42
+ }
43
+ | BedrockCachePointBlock;
44
+
45
+ /* Content Block */
46
+ export type BedrockContentBlock =
47
+ | BedrockTextBlock
48
+ | BedrockImageBlock
49
+ | BedrockToolUseBlock
50
+ | BedrockToolResultBlock
51
+ | BedrockCachePointBlock;
52
+
53
+ export type BedrockAssistantContentBlock =
54
+ | BedrockTextBlock
55
+ | BedrockToolUseBlock
56
+ | BedrockReasoningContentBlock
57
+ | BedrockCachePointBlock;
58
+
59
+ export type BedrockTextBlock = {
60
+ text: string;
61
+ cachePoint?: {
62
+ type: "default";
63
+ };
64
+ };
65
+
66
+ export type BedrockImageBlock = {
67
+ image: {
68
+ format: "png" | "jpeg" | "gif" | "webp";
69
+ source: {
70
+ bytes?: string; // base64 encoded
71
+ };
72
+ };
73
+ };
74
+
75
+ export type BedrockToolUseBlock = {
76
+ toolUse: {
77
+ toolUseId: string;
78
+ name: string;
79
+ input: Record<string, unknown>;
80
+ };
81
+ };
82
+
83
+ export type BedrockToolResultBlock = {
84
+ toolResult: {
85
+ toolUseId: string;
86
+ content: BedrockToolResultContent[];
87
+ status?: "success" | "error";
88
+ };
89
+ };
90
+
91
+ export type BedrockToolResultContent =
92
+ | { text: string }
93
+ | { image: BedrockImageBlock["image"] };
94
+
95
+ // Message history type - used when sending back to API
96
+ // Claude Haiku 4.5 and Nova use this format
97
+ // Note: reasoningText and redactedContent are mutually exclusive (union type)
98
+ export type BedrockReasoningContentBlock = {
99
+ reasoningContent:
100
+ | {
101
+ reasoningText: {
102
+ text: string;
103
+ signature?: string;
104
+ };
105
+ }
106
+ | {
107
+ redactedContent: string; // Base64-encoded binary
108
+ };
109
+ };
110
+
111
+ // Internal type for accumulating reasoning content during streaming
112
+ // Note: Streaming API uses flat structure (reasoningContent.text, reasoningContent.redactedContent)
113
+ // but message history uses nested structure (reasoningContent.reasoningText.text, reasoningContent.redactedContent)
114
+ export type BedrockReasoningContentAccumulator = {
115
+ reasoningContent: {
116
+ text?: string;
117
+ signature?: string;
118
+ redactedContent?: string; // Base64-encoded binary
119
+ };
120
+ };
121
+
122
+ // Internal type for accumulating partial content during streaming
123
+ // Note: reasoningContent uses flat structure during streaming, but nested structure in message history
124
+ export type BedrockAssistantContentBlockWithPartial = {
125
+ text?: string;
126
+ toolUse?: {
127
+ toolUseId?: string;
128
+ name?: string;
129
+ input?: unknown;
130
+ };
131
+ reasoningContent?: {
132
+ text?: string;
133
+ signature?: string;
134
+ redactedContent?: string; // Base64-encoded binary
135
+ };
136
+ cachePoint?: {
137
+ type: "default";
138
+ };
139
+ _partialInput?: string;
140
+ };
141
+
142
+ export type BedrockCachePointBlock = {
143
+ cachePoint: {
144
+ type: "default";
145
+ };
146
+ };
147
+
148
+ /* Tool Configuration */
149
+ export type BedrockToolConfig = {
150
+ tools: BedrockTool[];
151
+ toolChoice?: BedrockToolChoice;
152
+ };
153
+
154
+ export type BedrockTool = {
155
+ toolSpec: {
156
+ name: string;
157
+ description?: string;
158
+ inputSchema: {
159
+ json: Record<string, unknown>;
160
+ };
161
+ };
162
+ };
163
+
164
+ export type BedrockToolChoice =
165
+ | { auto: Record<string, never> }
166
+ | { any: Record<string, never> }
167
+ | { tool: { name: string } };
168
+
169
+ /* Response */
170
+ export type BedrockConverseResponse = {
171
+ metrics: {
172
+ latencyMs: number;
173
+ };
174
+ output: {
175
+ message: BedrockAssistantMessage;
176
+ };
177
+ stopReason: "end_turn" | "tool_use" | "max_tokens" | "stop_sequence";
178
+ usage: BedrockUsage;
179
+ };
180
+
181
+ /* Usage */
182
+ export type BedrockUsage = {
183
+ inputTokens: number;
184
+ outputTokens: number;
185
+ totalTokens: number;
186
+ cacheReadInputTokens?: number;
187
+ cacheWriteInputTokens?: number;
188
+ };
189
+
190
+ /* Stream Event */
191
+ export type BedrockStreamEvent =
192
+ | BedrockStreamMessageStartEvent
193
+ | BedrockStreamContentBlockStartEvent
194
+ | BedrockStreamContentBlockDeltaEvent
195
+ | BedrockStreamContentBlockStopEvent
196
+ | BedrockStreamMessageStopEvent
197
+ | BedrockStreamMetadataEvent;
198
+
199
+ export type BedrockStreamMessageStartEvent = {
200
+ messageStart: {
201
+ requestId: string;
202
+ };
203
+ };
204
+
205
+ export type BedrockStreamContentBlockStartEvent = {
206
+ contentBlockIndex: number;
207
+ start: {
208
+ text?: string;
209
+ toolUse?: {
210
+ toolUseId: string;
211
+ name: string;
212
+ };
213
+ };
214
+ };
215
+
216
+ export type BedrockStreamContentBlockDeltaEvent = {
217
+ contentBlockIndex: number;
218
+ delta: {
219
+ text?: string;
220
+ toolUse?: {
221
+ toolUseId?: string;
222
+ name?: string;
223
+ input?: string; // partial JSON
224
+ };
225
+ reasoningContent?: {
226
+ text?: string;
227
+ signature?: string;
228
+ redactedContent?: string; // Base64-encoded binary
229
+ };
230
+ };
231
+ };
232
+
233
+ export type BedrockStreamContentBlockStopEvent = {
234
+ contentBlockStop: {
235
+ contentBlockIndex: number;
236
+ };
237
+ };
238
+
239
+ export type BedrockStreamMessageStopEvent = {
240
+ stopReason: "end_turn" | "tool_use" | "max_tokens" | "stop_sequence";
241
+ additionalModelResponseFields?: Record<string, unknown>;
242
+ };
243
+
244
+ export type BedrockStreamMetadataEvent = {
245
+ usage: BedrockUsage;
246
+ metrics: {
247
+ latencyMs: number;
248
+ };
249
+ };