@omnirun/sdk 0.4.0 → 0.5.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/llm.d.ts +55 -0
- package/dist/llm.js +36 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a42b442: Add LLM proxy client with streaming support. New `LLM` class provides `chatCompletion()`, `streamChatCompletion()`, `listModels()`, and `getUsage()` methods for the OpenAI-compatible LLM proxy endpoint.
|
|
8
|
+
|
|
3
9
|
## 0.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { Contexts } from "./contexts.js";
|
|
|
8
8
|
export { Exposures } from "./exposures.js";
|
|
9
9
|
export { Production } from "./production.js";
|
|
10
10
|
export { Webhooks } from "./webhooks.js";
|
|
11
|
+
export { LLM } from "./llm.js";
|
|
12
|
+
export type { ChatMessage, ChatCompletionRequest, ChatCompletionResponse, ChatCompletionChoice, ChatCompletionUsage, LLMUsage, LLMModel, } from "./llm.js";
|
|
11
13
|
export { WatchHandle } from "./watch-handle.js";
|
|
12
14
|
export { HTTPClient } from "./client.js";
|
|
13
15
|
export { generateE2EEKeyPair, importE2EEPublicKey, deriveE2EESharedKey, encryptE2EEJSON, decryptE2EEJSON, } from "./e2ee.js";
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { Contexts } from "./contexts.js";
|
|
|
8
8
|
export { Exposures } from "./exposures.js";
|
|
9
9
|
export { Production } from "./production.js";
|
|
10
10
|
export { Webhooks } from "./webhooks.js";
|
|
11
|
+
export { LLM } from "./llm.js";
|
|
11
12
|
export { WatchHandle } from "./watch-handle.js";
|
|
12
13
|
export { HTTPClient } from "./client.js";
|
|
13
14
|
export { generateE2EEKeyPair, importE2EEPublicKey, deriveE2EESharedKey, encryptE2EEJSON, decryptE2EEJSON, } from "./e2ee.js";
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ConnectionConfig } from "./config.js";
|
|
2
|
+
export interface ChatMessage {
|
|
3
|
+
role: "system" | "user" | "assistant";
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ChatCompletionRequest {
|
|
7
|
+
model: string;
|
|
8
|
+
messages: ChatMessage[];
|
|
9
|
+
max_tokens?: number;
|
|
10
|
+
temperature?: number;
|
|
11
|
+
stream?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ChatCompletionChoice {
|
|
14
|
+
index: number;
|
|
15
|
+
message: {
|
|
16
|
+
role: string;
|
|
17
|
+
content: string;
|
|
18
|
+
};
|
|
19
|
+
finish_reason: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatCompletionUsage {
|
|
22
|
+
prompt_tokens: number;
|
|
23
|
+
completion_tokens: number;
|
|
24
|
+
total_tokens: number;
|
|
25
|
+
cost?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ChatCompletionResponse {
|
|
28
|
+
id: string;
|
|
29
|
+
object: string;
|
|
30
|
+
created: number;
|
|
31
|
+
model: string;
|
|
32
|
+
choices: ChatCompletionChoice[];
|
|
33
|
+
usage: ChatCompletionUsage;
|
|
34
|
+
}
|
|
35
|
+
export interface LLMUsage {
|
|
36
|
+
spendUsedCents: number;
|
|
37
|
+
spendCapCents: number;
|
|
38
|
+
remainingCents: number;
|
|
39
|
+
}
|
|
40
|
+
export interface LLMModel {
|
|
41
|
+
id: string;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}
|
|
44
|
+
export declare class LLM {
|
|
45
|
+
private client;
|
|
46
|
+
constructor(config?: Partial<ConnectionConfig>);
|
|
47
|
+
/** Create a chat completion (non-streaming). */
|
|
48
|
+
chatCompletion(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
49
|
+
/** Stream a chat completion, yielding content delta strings. */
|
|
50
|
+
streamChatCompletion(request: ChatCompletionRequest): AsyncGenerator<string>;
|
|
51
|
+
/** List available models. */
|
|
52
|
+
listModels(): Promise<LLMModel[]>;
|
|
53
|
+
/** Get current spend and remaining credits. */
|
|
54
|
+
getUsage(): Promise<LLMUsage>;
|
|
55
|
+
}
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { resolveConfig } from "./config.js";
|
|
2
|
+
import { HTTPClient } from "./client.js";
|
|
3
|
+
export class LLM {
|
|
4
|
+
client;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.client = new HTTPClient(resolveConfig(config));
|
|
7
|
+
}
|
|
8
|
+
/** Create a chat completion (non-streaming). */
|
|
9
|
+
async chatCompletion(request) {
|
|
10
|
+
return this.client.post("/llm/v1/chat/completions", { ...request, stream: false });
|
|
11
|
+
}
|
|
12
|
+
/** Stream a chat completion, yielding content delta strings. */
|
|
13
|
+
async *streamChatCompletion(request) {
|
|
14
|
+
const events = this.client.streamSSEPost("/llm/v1/chat/completions", {
|
|
15
|
+
...request,
|
|
16
|
+
stream: true,
|
|
17
|
+
});
|
|
18
|
+
for await (const event of events) {
|
|
19
|
+
// Each event is a parsed JSON object from the SSE stream.
|
|
20
|
+
// The parseSSE helper silently drops non-JSON lines like [DONE].
|
|
21
|
+
const chunk = event;
|
|
22
|
+
const content = chunk?.choices?.[0]?.delta?.content;
|
|
23
|
+
if (content)
|
|
24
|
+
yield content;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** List available models. */
|
|
28
|
+
async listModels() {
|
|
29
|
+
const resp = await this.client.get("/llm/v1/models");
|
|
30
|
+
return resp.data || [];
|
|
31
|
+
}
|
|
32
|
+
/** Get current spend and remaining credits. */
|
|
33
|
+
async getUsage() {
|
|
34
|
+
return this.client.get("/llm/v1/usage");
|
|
35
|
+
}
|
|
36
|
+
}
|