@jaibber/sdk 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.
package/dist/index.d.cts CHANGED
@@ -15,6 +15,26 @@ interface AnthropicProviderOptions {
15
15
  /** Max tokens (default: 8192) */
16
16
  maxTokens?: number;
17
17
  }
18
+ interface OpenAIProviderOptions {
19
+ /** OpenAI API key (sk-...) */
20
+ apiKey: string;
21
+ /** Model ID (default: "gpt-4o") */
22
+ model?: string;
23
+ /** Max tokens (default: 8192) */
24
+ maxTokens?: number;
25
+ }
26
+ interface GoogleProviderOptions {
27
+ /** Google AI API key (AIza...) */
28
+ apiKey: string;
29
+ /** Model ID (default: "gemini-2.0-flash") */
30
+ model?: string;
31
+ /** Max tokens (default: 8192) */
32
+ maxTokens?: number;
33
+ }
34
+ interface ClaudeCLIProviderOptions {
35
+ /** Working directory for Claude CLI (default: cwd) */
36
+ projectDir?: string;
37
+ }
18
38
 
19
39
  /**
20
40
  * REST API client wrapping the Jaibber server endpoints.
@@ -27,6 +47,8 @@ declare class JaibberClient {
27
47
  userId: string | null;
28
48
  username: string | null;
29
49
  constructor(serverUrl: string);
50
+ /** POST /api/auth/register — create a new account, stores JWT. */
51
+ register(username: string, password: string): Promise<void>;
30
52
  /** POST /api/auth/token — login with credentials, stores JWT. */
31
53
  login(username: string, password: string): Promise<void>;
32
54
  get isAuthenticated(): boolean;
@@ -184,6 +206,7 @@ interface AblyMessage {
184
206
  respondingChain?: string[];
185
207
  isTaskNotification?: boolean;
186
208
  attachments?: MessageAttachment[];
209
+ parentMessageId?: string;
187
210
  }
188
211
  type TaskStatus = "submitted" | "working" | "input-required" | "completed" | "failed" | "cancelled";
189
212
  type TaskPriority = "low" | "medium" | "high" | "urgent";
@@ -267,6 +290,7 @@ interface ServerMessage {
267
290
  senderName: string;
268
291
  type: "message" | "response" | "error";
269
292
  text: string;
293
+ parentMessageId?: string;
270
294
  createdAt: string;
271
295
  }
272
296
  interface PersistMessagePayload {
@@ -275,6 +299,7 @@ interface PersistMessagePayload {
275
299
  senderName: string;
276
300
  type: "message" | "response" | "error";
277
301
  text: string;
302
+ parentMessageId?: string;
278
303
  }
279
304
 
280
305
  /**
@@ -316,6 +341,9 @@ declare class JaibberAgent extends EventEmitter {
316
341
  onTask(handler: TaskHandler): void;
317
342
  /** Use a built-in LLM provider. */
318
343
  useProvider(name: "anthropic", options: AnthropicProviderOptions): void;
344
+ useProvider(name: "openai", options: OpenAIProviderOptions): void;
345
+ useProvider(name: "google", options: GoogleProviderOptions): void;
346
+ useProvider(name: "claude-cli", options?: ClaudeCLIProviderOptions): void;
319
347
  private handleIncomingMessage;
320
348
  /**
321
349
  * Should this agent respond to the message?
@@ -345,4 +373,38 @@ declare class AnthropicProvider implements Provider {
345
373
  generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
346
374
  }
347
375
 
348
- export { type AblyMessage, type AgentConfig, AnthropicProvider, type AnthropicProviderOptions, type ExecutionMode, type IncomingMessage, JaibberAgent, type MessageAttachment, MessageContext, type MessageHandler, type Project, type Provider, type Task, TaskContext, type TaskHandler, type TaskPriority, type TaskStatus };
376
+ /**
377
+ * OpenAI Chat Completions API provider.
378
+ * Streams responses via SSE, same async generator pattern as AnthropicProvider.
379
+ */
380
+ declare class OpenAIProvider implements Provider {
381
+ private apiKey;
382
+ private model;
383
+ private maxTokens;
384
+ constructor(options: OpenAIProviderOptions);
385
+ generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
386
+ }
387
+
388
+ /**
389
+ * Google Gemini API provider.
390
+ * Uses the streamGenerateContent endpoint with SSE streaming.
391
+ */
392
+ declare class GoogleProvider implements Provider {
393
+ private apiKey;
394
+ private model;
395
+ private maxTokens;
396
+ constructor(options: GoogleProviderOptions);
397
+ generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
398
+ }
399
+
400
+ /**
401
+ * Claude CLI provider — shells out to locally-installed `claude` CLI.
402
+ * No API key needed; uses whatever auth the local Claude CLI has.
403
+ */
404
+ declare class ClaudeCLIProvider implements Provider {
405
+ private projectDir;
406
+ constructor(options?: ClaudeCLIProviderOptions);
407
+ generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
408
+ }
409
+
410
+ export { type AblyMessage, type AgentConfig, AnthropicProvider, type AnthropicProviderOptions, ClaudeCLIProvider, type ClaudeCLIProviderOptions, type ExecutionMode, GoogleProvider, type GoogleProviderOptions, type IncomingMessage, JaibberAgent, type MessageAttachment, MessageContext, type MessageHandler, OpenAIProvider, type OpenAIProviderOptions, type Project, type Provider, type Task, TaskContext, type TaskHandler, type TaskPriority, type TaskStatus };
package/dist/index.d.ts CHANGED
@@ -15,6 +15,26 @@ interface AnthropicProviderOptions {
15
15
  /** Max tokens (default: 8192) */
16
16
  maxTokens?: number;
17
17
  }
18
+ interface OpenAIProviderOptions {
19
+ /** OpenAI API key (sk-...) */
20
+ apiKey: string;
21
+ /** Model ID (default: "gpt-4o") */
22
+ model?: string;
23
+ /** Max tokens (default: 8192) */
24
+ maxTokens?: number;
25
+ }
26
+ interface GoogleProviderOptions {
27
+ /** Google AI API key (AIza...) */
28
+ apiKey: string;
29
+ /** Model ID (default: "gemini-2.0-flash") */
30
+ model?: string;
31
+ /** Max tokens (default: 8192) */
32
+ maxTokens?: number;
33
+ }
34
+ interface ClaudeCLIProviderOptions {
35
+ /** Working directory for Claude CLI (default: cwd) */
36
+ projectDir?: string;
37
+ }
18
38
 
19
39
  /**
20
40
  * REST API client wrapping the Jaibber server endpoints.
@@ -27,6 +47,8 @@ declare class JaibberClient {
27
47
  userId: string | null;
28
48
  username: string | null;
29
49
  constructor(serverUrl: string);
50
+ /** POST /api/auth/register — create a new account, stores JWT. */
51
+ register(username: string, password: string): Promise<void>;
30
52
  /** POST /api/auth/token — login with credentials, stores JWT. */
31
53
  login(username: string, password: string): Promise<void>;
32
54
  get isAuthenticated(): boolean;
@@ -184,6 +206,7 @@ interface AblyMessage {
184
206
  respondingChain?: string[];
185
207
  isTaskNotification?: boolean;
186
208
  attachments?: MessageAttachment[];
209
+ parentMessageId?: string;
187
210
  }
188
211
  type TaskStatus = "submitted" | "working" | "input-required" | "completed" | "failed" | "cancelled";
189
212
  type TaskPriority = "low" | "medium" | "high" | "urgent";
@@ -267,6 +290,7 @@ interface ServerMessage {
267
290
  senderName: string;
268
291
  type: "message" | "response" | "error";
269
292
  text: string;
293
+ parentMessageId?: string;
270
294
  createdAt: string;
271
295
  }
272
296
  interface PersistMessagePayload {
@@ -275,6 +299,7 @@ interface PersistMessagePayload {
275
299
  senderName: string;
276
300
  type: "message" | "response" | "error";
277
301
  text: string;
302
+ parentMessageId?: string;
278
303
  }
279
304
 
280
305
  /**
@@ -316,6 +341,9 @@ declare class JaibberAgent extends EventEmitter {
316
341
  onTask(handler: TaskHandler): void;
317
342
  /** Use a built-in LLM provider. */
318
343
  useProvider(name: "anthropic", options: AnthropicProviderOptions): void;
344
+ useProvider(name: "openai", options: OpenAIProviderOptions): void;
345
+ useProvider(name: "google", options: GoogleProviderOptions): void;
346
+ useProvider(name: "claude-cli", options?: ClaudeCLIProviderOptions): void;
319
347
  private handleIncomingMessage;
320
348
  /**
321
349
  * Should this agent respond to the message?
@@ -345,4 +373,38 @@ declare class AnthropicProvider implements Provider {
345
373
  generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
346
374
  }
347
375
 
348
- export { type AblyMessage, type AgentConfig, AnthropicProvider, type AnthropicProviderOptions, type ExecutionMode, type IncomingMessage, JaibberAgent, type MessageAttachment, MessageContext, type MessageHandler, type Project, type Provider, type Task, TaskContext, type TaskHandler, type TaskPriority, type TaskStatus };
376
+ /**
377
+ * OpenAI Chat Completions API provider.
378
+ * Streams responses via SSE, same async generator pattern as AnthropicProvider.
379
+ */
380
+ declare class OpenAIProvider implements Provider {
381
+ private apiKey;
382
+ private model;
383
+ private maxTokens;
384
+ constructor(options: OpenAIProviderOptions);
385
+ generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
386
+ }
387
+
388
+ /**
389
+ * Google Gemini API provider.
390
+ * Uses the streamGenerateContent endpoint with SSE streaming.
391
+ */
392
+ declare class GoogleProvider implements Provider {
393
+ private apiKey;
394
+ private model;
395
+ private maxTokens;
396
+ constructor(options: GoogleProviderOptions);
397
+ generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
398
+ }
399
+
400
+ /**
401
+ * Claude CLI provider — shells out to locally-installed `claude` CLI.
402
+ * No API key needed; uses whatever auth the local Claude CLI has.
403
+ */
404
+ declare class ClaudeCLIProvider implements Provider {
405
+ private projectDir;
406
+ constructor(options?: ClaudeCLIProviderOptions);
407
+ generate(prompt: string, systemPrompt: string, conversationContext: string): AsyncGenerator<string, void, unknown>;
408
+ }
409
+
410
+ export { type AblyMessage, type AgentConfig, AnthropicProvider, type AnthropicProviderOptions, ClaudeCLIProvider, type ClaudeCLIProviderOptions, type ExecutionMode, GoogleProvider, type GoogleProviderOptions, type IncomingMessage, JaibberAgent, type MessageAttachment, MessageContext, type MessageHandler, OpenAIProvider, type OpenAIProviderOptions, type Project, type Provider, type Task, TaskContext, type TaskHandler, type TaskPriority, type TaskStatus };
package/dist/index.js CHANGED
@@ -12,6 +12,25 @@ var JaibberClient = class {
12
12
  this.serverUrl = serverUrl.replace(/\/+$/, "");
13
13
  }
14
14
  // ── Auth ────────────────────────────────────────────────────────────
15
+ /** POST /api/auth/register — create a new account, stores JWT. */
16
+ async register(username, password) {
17
+ const res = await fetch(`${this.serverUrl}/api/auth/register`, {
18
+ method: "POST",
19
+ headers: { "Content-Type": "application/json" },
20
+ body: JSON.stringify({ username, password })
21
+ });
22
+ if (!res.ok) {
23
+ const text = await res.text();
24
+ if (res.status === 409) {
25
+ throw new Error(`Username "${username}" is already taken.`);
26
+ }
27
+ throw new Error(`Registration failed (${res.status}): ${text}`);
28
+ }
29
+ const data = await res.json();
30
+ this.jwt = data.token;
31
+ this.userId = data.userId;
32
+ this.username = data.username;
33
+ }
15
34
  /** POST /api/auth/token — login with credentials, stores JWT. */
16
35
  async login(username, password) {
17
36
  const res = await fetch(`${this.serverUrl}/api/auth/token`, {
@@ -566,6 +585,211 @@ var AnthropicProvider = class {
566
585
  }
567
586
  };
568
587
 
588
+ // src/providers/openai.ts
589
+ var OPENAI_API_URL = "https://api.openai.com/v1/chat/completions";
590
+ var DEFAULT_MODEL2 = "gpt-4o";
591
+ var DEFAULT_MAX_TOKENS2 = 8192;
592
+ var OpenAIProvider = class {
593
+ apiKey;
594
+ model;
595
+ maxTokens;
596
+ constructor(options) {
597
+ this.apiKey = options.apiKey;
598
+ this.model = options.model ?? DEFAULT_MODEL2;
599
+ this.maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS2;
600
+ }
601
+ async *generate(prompt, systemPrompt, conversationContext) {
602
+ let fullText = "";
603
+ if (conversationContext) {
604
+ fullText += 'Below is the recent conversation history for context. Respond ONLY to the final user message. Be conversational and concise \u2014 reply directly to the user as a chat participant. Do NOT narrate your thought process, planning steps, or internal reasoning. Do NOT describe actions you would take (e.g. "I should...", "Let me...", "I will..."). Just answer.\n\n';
605
+ fullText += conversationContext;
606
+ fullText += "\n\n---\n\n";
607
+ }
608
+ fullText += prompt;
609
+ const messages = [];
610
+ if (systemPrompt) {
611
+ messages.push({ role: "system", content: systemPrompt });
612
+ }
613
+ messages.push({ role: "user", content: fullText });
614
+ const response = await fetch(OPENAI_API_URL, {
615
+ method: "POST",
616
+ headers: {
617
+ Authorization: `Bearer ${this.apiKey}`,
618
+ "Content-Type": "application/json"
619
+ },
620
+ body: JSON.stringify({
621
+ model: this.model,
622
+ max_tokens: this.maxTokens,
623
+ stream: true,
624
+ messages
625
+ })
626
+ });
627
+ if (!response.ok) {
628
+ const text = await response.text();
629
+ const status = response.status;
630
+ if (status === 401) {
631
+ throw new Error("Invalid OpenAI API key. Check your API key.");
632
+ } else if (status === 429) {
633
+ throw new Error("OpenAI API rate limit exceeded. Please wait and try again.");
634
+ }
635
+ throw new Error(`OpenAI API returned ${status}: ${text}`);
636
+ }
637
+ if (!response.body) {
638
+ throw new Error("OpenAI API returned no response body");
639
+ }
640
+ const reader = response.body.getReader();
641
+ const decoder = new TextDecoder();
642
+ let buffer = "";
643
+ try {
644
+ while (true) {
645
+ const { done, value } = await reader.read();
646
+ if (done) break;
647
+ buffer += decoder.decode(value, { stream: true });
648
+ while (true) {
649
+ const newlinePos = buffer.indexOf("\n");
650
+ if (newlinePos === -1) break;
651
+ const line = buffer.slice(0, newlinePos).replace(/\r$/, "");
652
+ buffer = buffer.slice(newlinePos + 1);
653
+ if (!line || !line.startsWith("data: ")) continue;
654
+ const data = line.slice(6).trim();
655
+ if (data === "[DONE]") return;
656
+ try {
657
+ const json = JSON.parse(data);
658
+ const content = json?.choices?.[0]?.delta?.content;
659
+ if (content) yield content;
660
+ } catch {
661
+ }
662
+ }
663
+ }
664
+ } finally {
665
+ reader.releaseLock();
666
+ }
667
+ }
668
+ };
669
+
670
+ // src/providers/google.ts
671
+ var DEFAULT_MODEL3 = "gemini-2.0-flash";
672
+ var DEFAULT_MAX_TOKENS3 = 8192;
673
+ var GoogleProvider = class {
674
+ apiKey;
675
+ model;
676
+ maxTokens;
677
+ constructor(options) {
678
+ this.apiKey = options.apiKey;
679
+ this.model = options.model ?? DEFAULT_MODEL3;
680
+ this.maxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS3;
681
+ }
682
+ async *generate(prompt, systemPrompt, conversationContext) {
683
+ let fullText = "";
684
+ if (conversationContext) {
685
+ fullText += 'Below is the recent conversation history for context. Respond ONLY to the final user message. Be conversational and concise \u2014 reply directly to the user as a chat participant. Do NOT narrate your thought process, planning steps, or internal reasoning. Do NOT describe actions you would take (e.g. "I should...", "Let me...", "I will..."). Just answer.\n\n';
686
+ fullText += conversationContext;
687
+ fullText += "\n\n---\n\n";
688
+ }
689
+ fullText += prompt;
690
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/${this.model}:streamGenerateContent?alt=sse&key=${this.apiKey}`;
691
+ const body = {
692
+ contents: [{ parts: [{ text: fullText }] }],
693
+ generationConfig: {
694
+ maxOutputTokens: this.maxTokens
695
+ }
696
+ };
697
+ if (systemPrompt) {
698
+ body.systemInstruction = { parts: [{ text: systemPrompt }] };
699
+ }
700
+ const response = await fetch(url, {
701
+ method: "POST",
702
+ headers: { "Content-Type": "application/json" },
703
+ body: JSON.stringify(body)
704
+ });
705
+ if (!response.ok) {
706
+ const text = await response.text();
707
+ const status = response.status;
708
+ if (status === 400 || status === 403) {
709
+ throw new Error(`Google AI API error (${status}): ${text}`);
710
+ } else if (status === 429) {
711
+ throw new Error("Google AI API rate limit exceeded. Please wait and try again.");
712
+ }
713
+ throw new Error(`Google AI API returned ${status}: ${text}`);
714
+ }
715
+ if (!response.body) {
716
+ throw new Error("Google AI API returned no response body");
717
+ }
718
+ const reader = response.body.getReader();
719
+ const decoder = new TextDecoder();
720
+ let buffer = "";
721
+ try {
722
+ while (true) {
723
+ const { done, value } = await reader.read();
724
+ if (done) break;
725
+ buffer += decoder.decode(value, { stream: true });
726
+ while (true) {
727
+ const newlinePos = buffer.indexOf("\n");
728
+ if (newlinePos === -1) break;
729
+ const line = buffer.slice(0, newlinePos).replace(/\r$/, "");
730
+ buffer = buffer.slice(newlinePos + 1);
731
+ if (!line || !line.startsWith("data: ")) continue;
732
+ const data = line.slice(6).trim();
733
+ if (data === "[DONE]") return;
734
+ try {
735
+ const json = JSON.parse(data);
736
+ const text = json?.candidates?.[0]?.content?.parts?.[0]?.text;
737
+ if (text) yield text;
738
+ } catch {
739
+ }
740
+ }
741
+ }
742
+ } finally {
743
+ reader.releaseLock();
744
+ }
745
+ }
746
+ };
747
+
748
+ // src/providers/claude-cli.ts
749
+ import { spawn } from "child_process";
750
+ var ClaudeCLIProvider = class {
751
+ projectDir;
752
+ constructor(options = {}) {
753
+ this.projectDir = options.projectDir ?? process.cwd();
754
+ }
755
+ async *generate(prompt, systemPrompt, conversationContext) {
756
+ let fullPrompt = "";
757
+ if (systemPrompt) {
758
+ fullPrompt += `[System Instructions]
759
+ ${systemPrompt}
760
+
761
+ `;
762
+ }
763
+ if (conversationContext) {
764
+ fullPrompt += 'Below is the recent conversation history for context. Respond ONLY to the final user message. Be conversational and concise \u2014 reply directly to the user as a chat participant. Do NOT narrate your thought process, planning steps, or internal reasoning. Do NOT describe actions you would take (e.g. "I should...", "Let me...", "I will..."). Just answer.\n\n';
765
+ fullPrompt += conversationContext;
766
+ fullPrompt += "\n\n---\n\n";
767
+ }
768
+ fullPrompt += prompt;
769
+ const child = spawn("claude", ["--print", "--dangerously-skip-permissions", fullPrompt], {
770
+ cwd: this.projectDir,
771
+ stdio: ["ignore", "pipe", "pipe"],
772
+ shell: true
773
+ });
774
+ let stderr = "";
775
+ child.stderr?.on("data", (chunk) => {
776
+ stderr += chunk.toString();
777
+ });
778
+ const stdout = child.stdout;
779
+ for await (const chunk of stdout) {
780
+ const text = chunk.toString();
781
+ if (text) yield text;
782
+ }
783
+ const exitCode = await new Promise((resolve) => {
784
+ child.on("close", resolve);
785
+ });
786
+ if (exitCode !== 0 && exitCode !== null) {
787
+ if (!stderr.trim()) return;
788
+ throw new Error(`Claude CLI exited with code ${exitCode}: ${stderr.trim()}`);
789
+ }
790
+ }
791
+ };
792
+
569
793
  // src/agent.ts
570
794
  var DEFAULT_MAX_DEPTH = 3;
571
795
  var DEFAULT_CHUNK_BATCH_MS = 200;
@@ -664,10 +888,20 @@ var JaibberAgent = class extends EventEmitter {
664
888
  onTask(handler) {
665
889
  this.taskHandler = handler;
666
890
  }
667
- /** Use a built-in LLM provider. */
668
891
  useProvider(name, options) {
669
- if (name === "anthropic") {
670
- this.provider = new AnthropicProvider(options);
892
+ switch (name) {
893
+ case "anthropic":
894
+ this.provider = new AnthropicProvider(options);
895
+ break;
896
+ case "openai":
897
+ this.provider = new OpenAIProvider(options);
898
+ break;
899
+ case "google":
900
+ this.provider = new GoogleProvider(options);
901
+ break;
902
+ case "claude-cli":
903
+ this.provider = new ClaudeCLIProvider(options);
904
+ break;
671
905
  }
672
906
  }
673
907
  // ── Message handling ────────────────────────────────────────────────
@@ -883,8 +1117,11 @@ ${task.description}` : `Task: ${task.title}`;
883
1117
  };
884
1118
  export {
885
1119
  AnthropicProvider,
1120
+ ClaudeCLIProvider,
1121
+ GoogleProvider,
886
1122
  JaibberAgent,
887
1123
  MessageContext,
1124
+ OpenAIProvider,
888
1125
  TaskContext
889
1126
  };
890
1127
  //# sourceMappingURL=index.js.map