@imisbahk/hive 0.1.0 → 0.1.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.
Files changed (69) hide show
  1. package/.github/workflows/publish.yml +31 -0
  2. package/.rocket/README.md +8 -8
  3. package/.rocket/SYMBOLS.md +260 -117
  4. package/CONTRIBUTING.md +2 -1
  5. package/FEATURES.md +55 -0
  6. package/README.md +13 -11
  7. package/dist/agent/agent.d.ts +10 -1
  8. package/dist/agent/agent.d.ts.map +1 -1
  9. package/dist/agent/agent.js +351 -1
  10. package/dist/agent/agent.js.map +1 -1
  11. package/dist/browser/browser.d.ts +9 -0
  12. package/dist/browser/browser.d.ts.map +1 -0
  13. package/dist/browser/browser.js +338 -0
  14. package/dist/browser/browser.js.map +1 -0
  15. package/dist/cli/commands/chat.d.ts +5 -1
  16. package/dist/cli/commands/chat.d.ts.map +1 -1
  17. package/dist/cli/commands/chat.js +560 -38
  18. package/dist/cli/commands/chat.js.map +1 -1
  19. package/dist/cli/commands/config.d.ts +11 -0
  20. package/dist/cli/commands/config.d.ts.map +1 -1
  21. package/dist/cli/commands/config.js +50 -15
  22. package/dist/cli/commands/config.js.map +1 -1
  23. package/dist/cli/commands/init.d.ts.map +1 -1
  24. package/dist/cli/commands/init.js +39 -14
  25. package/dist/cli/commands/init.js.map +1 -1
  26. package/dist/cli/commands/nuke.d.ts.map +1 -1
  27. package/dist/cli/commands/nuke.js +5 -4
  28. package/dist/cli/commands/nuke.js.map +1 -1
  29. package/dist/cli/commands/status.d.ts +5 -0
  30. package/dist/cli/commands/status.d.ts.map +1 -1
  31. package/dist/cli/commands/status.js +15 -5
  32. package/dist/cli/commands/status.js.map +1 -1
  33. package/dist/cli/index.js +34 -12
  34. package/dist/cli/index.js.map +1 -1
  35. package/dist/cli/ui.d.ts +7 -0
  36. package/dist/cli/ui.d.ts.map +1 -0
  37. package/dist/cli/ui.js +96 -0
  38. package/dist/cli/ui.js.map +1 -0
  39. package/dist/providers/base.d.ts +37 -1
  40. package/dist/providers/base.d.ts.map +1 -1
  41. package/dist/providers/base.js +104 -0
  42. package/dist/providers/base.js.map +1 -1
  43. package/dist/providers/openai-compatible.d.ts +2 -1
  44. package/dist/providers/openai-compatible.d.ts.map +1 -1
  45. package/dist/providers/openai-compatible.js +18 -1
  46. package/dist/providers/openai-compatible.js.map +1 -1
  47. package/package.json +9 -1
  48. package/prompts/Browser.md +13 -0
  49. package/prompts/Debugging.md +15 -0
  50. package/prompts/Execution.md +13 -0
  51. package/prompts/Planning.md +13 -0
  52. package/prompts/Product.md +14 -0
  53. package/prompts/Review.md +15 -0
  54. package/prompts/Safety.md +12 -0
  55. package/prompts/Search.md +14 -0
  56. package/prompts/Tools.md +14 -0
  57. package/prompts/Writing.md +13 -0
  58. package/releases/v1/v0.1/RELEASE-NOTES.md +46 -0
  59. package/src/agent/agent.ts +442 -2
  60. package/src/browser/browser.ts +410 -0
  61. package/src/cli/commands/chat.ts +705 -34
  62. package/src/cli/commands/config.ts +78 -15
  63. package/src/cli/commands/init.ts +60 -14
  64. package/src/cli/commands/nuke.ts +11 -7
  65. package/src/cli/commands/status.ts +28 -5
  66. package/src/cli/index.ts +37 -9
  67. package/src/cli/ui.ts +120 -0
  68. package/src/providers/base.ts +176 -1
  69. package/src/providers/openai-compatible.ts +24 -0
@@ -12,11 +12,38 @@ export const SUPPORTED_PROVIDER_NAMES = [
12
12
  ] as const;
13
13
 
14
14
  export type ProviderName = (typeof SUPPORTED_PROVIDER_NAMES)[number];
15
- export type ProviderMessageRole = "system" | "user" | "assistant";
15
+ export type ProviderMessageRole = "system" | "user" | "assistant" | "tool";
16
+
17
+ export interface ProviderToolDefinition {
18
+ type: "function";
19
+ function: {
20
+ name: string;
21
+ description: string;
22
+ parameters: Record<string, unknown>;
23
+ };
24
+ }
25
+
26
+ export interface ProviderToolCallPayload {
27
+ id: string;
28
+ type: "function";
29
+ function: {
30
+ name: string;
31
+ arguments: string;
32
+ };
33
+ }
34
+
35
+ export interface ProviderToolCall {
36
+ id: string;
37
+ name: string;
38
+ arguments: string;
39
+ }
16
40
 
17
41
  export interface ProviderMessage {
18
42
  role: ProviderMessageRole;
19
43
  content: string;
44
+ name?: string;
45
+ tool_call_id?: string;
46
+ tool_calls?: ProviderToolCallPayload[];
20
47
  }
21
48
 
22
49
  export interface StreamChatRequest {
@@ -26,10 +53,20 @@ export interface StreamChatRequest {
26
53
  maxTokens?: number;
27
54
  }
28
55
 
56
+ export interface CompleteChatRequest extends StreamChatRequest {
57
+ tools?: ProviderToolDefinition[];
58
+ }
59
+
60
+ export interface CompleteChatResponse {
61
+ content: string;
62
+ toolCalls: ProviderToolCall[];
63
+ }
64
+
29
65
  export interface Provider {
30
66
  readonly name: ProviderName;
31
67
  readonly defaultModel: string;
32
68
  streamChat(request: StreamChatRequest): AsyncGenerator<string>;
69
+ completeChat?(request: CompleteChatRequest): Promise<CompleteChatResponse>;
33
70
  }
34
71
 
35
72
  export class ProviderConfigurationError extends Error {
@@ -58,6 +95,10 @@ export interface OpenAICompatibleStreamInput {
58
95
  extraBody?: Record<string, unknown>;
59
96
  }
60
97
 
98
+ export interface OpenAICompatibleCompleteInput extends OpenAICompatibleStreamInput {
99
+ tools?: ProviderToolDefinition[];
100
+ }
101
+
61
102
  export function normalizeProviderName(raw?: string): ProviderName {
62
103
  if (!raw) {
63
104
  return "openai";
@@ -146,6 +187,71 @@ export async function* streamOpenAICompatibleChat(
146
187
  }
147
188
  }
148
189
 
190
+ export async function completeOpenAICompatibleChat(
191
+ input: OpenAICompatibleCompleteInput,
192
+ ): Promise<CompleteChatResponse> {
193
+ const endpoint = `${input.baseUrl.replace(/\/$/, "")}/chat/completions`;
194
+
195
+ const headers: Record<string, string> = {
196
+ "content-type": "application/json",
197
+ ...(input.extraHeaders ?? {}),
198
+ };
199
+
200
+ if (input.apiKey) {
201
+ headers.authorization = `Bearer ${input.apiKey}`;
202
+ }
203
+
204
+ const body: Record<string, unknown> = {
205
+ model: input.model,
206
+ messages: input.messages,
207
+ stream: false,
208
+ ...(input.extraBody ?? {}),
209
+ };
210
+
211
+ if (input.temperature !== undefined) {
212
+ body.temperature = input.temperature;
213
+ }
214
+
215
+ if (input.maxTokens !== undefined) {
216
+ body.max_tokens = input.maxTokens;
217
+ }
218
+
219
+ if (input.tools && input.tools.length > 0) {
220
+ body.tools = input.tools;
221
+ body.tool_choice = "auto";
222
+ }
223
+
224
+ const response = await fetch(endpoint, {
225
+ method: "POST",
226
+ headers,
227
+ body: JSON.stringify(body),
228
+ });
229
+
230
+ await ensureOk(response, `${input.provider} request failed`);
231
+
232
+ const payload = (await response.json()) as Record<string, unknown>;
233
+ const errorMessage = pickErrorMessage(payload);
234
+ if (errorMessage) {
235
+ throw new ProviderRequestError(`${input.provider} error: ${errorMessage}`);
236
+ }
237
+
238
+ const maybeChoices = payload.choices;
239
+ if (!Array.isArray(maybeChoices) || maybeChoices.length === 0) {
240
+ throw new ProviderRequestError(`${input.provider} response did not include choices.`);
241
+ }
242
+
243
+ const firstChoice = maybeChoices[0] as Record<string, unknown>;
244
+ const message = firstChoice.message as Record<string, unknown> | undefined;
245
+
246
+ const content = pickMessageContent(message);
247
+ const toolCalls = pickToolCalls(message);
248
+
249
+ return {
250
+ content,
251
+ toolCalls,
252
+ };
253
+ }
254
+
149
255
  export async function* iterateSseData(response: Response): AsyncGenerator<string> {
150
256
  if (!response.body) {
151
257
  return;
@@ -220,6 +326,75 @@ function pickErrorMessage(payload: Record<string, unknown>): string | null {
220
326
  return null;
221
327
  }
222
328
 
329
+ function pickMessageContent(message: Record<string, unknown> | undefined): string {
330
+ if (!message) {
331
+ return "";
332
+ }
333
+
334
+ const rawContent = message.content;
335
+ if (typeof rawContent === "string") {
336
+ return rawContent;
337
+ }
338
+
339
+ if (Array.isArray(rawContent)) {
340
+ return rawContent
341
+ .map((part) => {
342
+ if (typeof part === "string") {
343
+ return part;
344
+ }
345
+
346
+ if (part && typeof part === "object") {
347
+ const asRecord = part as Record<string, unknown>;
348
+ if (typeof asRecord.text === "string") {
349
+ return asRecord.text;
350
+ }
351
+ }
352
+
353
+ return "";
354
+ })
355
+ .join("");
356
+ }
357
+
358
+ return "";
359
+ }
360
+
361
+ function pickToolCalls(message: Record<string, unknown> | undefined): ProviderToolCall[] {
362
+ if (!message) {
363
+ return [];
364
+ }
365
+
366
+ const rawToolCalls = message.tool_calls;
367
+ if (!Array.isArray(rawToolCalls)) {
368
+ return [];
369
+ }
370
+
371
+ const calls: ProviderToolCall[] = [];
372
+ for (const toolCall of rawToolCalls) {
373
+ if (!toolCall || typeof toolCall !== "object") {
374
+ continue;
375
+ }
376
+
377
+ const callRecord = toolCall as Record<string, unknown>;
378
+ const callId = typeof callRecord.id === "string" ? callRecord.id : "";
379
+ const callFunction = callRecord.function as Record<string, unknown> | undefined;
380
+ const callName = typeof callFunction?.name === "string" ? callFunction.name : "";
381
+ const callArguments =
382
+ typeof callFunction?.arguments === "string" ? callFunction.arguments : "{}";
383
+
384
+ if (callId.length === 0 || callName.length === 0) {
385
+ continue;
386
+ }
387
+
388
+ calls.push({
389
+ id: callId,
390
+ name: callName,
391
+ arguments: callArguments,
392
+ });
393
+ }
394
+
395
+ return calls;
396
+ }
397
+
223
398
  async function ensureOk(response: Response, fallbackMessage: string): Promise<void> {
224
399
  if (response.ok) {
225
400
  return;
@@ -1,4 +1,7 @@
1
1
  import {
2
+ completeOpenAICompatibleChat,
3
+ type CompleteChatRequest,
4
+ type CompleteChatResponse,
2
5
  ProviderConfigurationError,
3
6
  type Provider,
4
7
  type ProviderName,
@@ -55,4 +58,25 @@ export class OpenAICompatibleProvider implements Provider {
55
58
  extraBody: this.extraBody,
56
59
  });
57
60
  }
61
+
62
+ async completeChat(request: CompleteChatRequest): Promise<CompleteChatResponse> {
63
+ if (!this.allowMissingApiKey && !this.apiKey) {
64
+ throw new ProviderConfigurationError(
65
+ `Provider \"${this.name}\" is missing an API key.`,
66
+ );
67
+ }
68
+
69
+ return completeOpenAICompatibleChat({
70
+ provider: this.name,
71
+ baseUrl: this.baseUrl,
72
+ apiKey: this.apiKey,
73
+ model: request.model ?? this.defaultModel,
74
+ messages: request.messages,
75
+ temperature: request.temperature,
76
+ maxTokens: request.maxTokens,
77
+ tools: request.tools,
78
+ extraHeaders: this.extraHeaders,
79
+ extraBody: this.extraBody,
80
+ });
81
+ }
58
82
  }