@omp-provider-capabilities/openrouter 0.1.2 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Enver Francisco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -10,34 +10,30 @@ OpenRouter provider features for OMP: batch execution and server tools.
10
10
 
11
11
  ## Installation
12
12
 
13
- ```bash
14
- npm install @omp-provider-capabilities/openrouter @omp-provider-capabilities/core
15
- ```
13
+ Install via OMP plugin manager:
16
14
 
17
- ## Usage
15
+ ```sh
16
+ omp plugin install @omp-provider-capabilities/openrouter
17
+ ```
18
18
 
19
- ```typescript
20
- import { OpenRouterBatchClient } from "@omp-provider-capabilities/openrouter";
19
+ Install from GitHub:
21
20
 
22
- const batch = new OpenRouterBatchClient({ apiKey: process.env.OPENROUTER_API_KEY });
21
+ ```sh
22
+ omp plugin install https://github.com/blyzer/omp-provider-capabilities/tree/main/packages/openrouter
23
+ ```
23
24
 
24
- // Submit batch job
25
- const job = await batch.create({
26
- model: "anthropic/claude-sonnet-4",
27
- requests: [{ prompt: "Analyze this..." }]
28
- });
25
+ Link a local checkout:
29
26
 
30
- // Poll for results
31
- const results = await batch.waitForCompletion(job.id);
27
+ ```sh
28
+ omp plugin link /path/to/omp-provider-capabilities/packages/openrouter
32
29
  ```
33
30
 
34
- ## Server Tools
31
+ Load the extension source for one invocation:
35
32
 
36
- - **Shell**: Execute shell commands (beta)
37
- - **Web Search**: Real-time web search (beta)
33
+ ```sh
34
+ omp -e /path/to/omp-provider-capabilities/packages/openrouter/src/index.ts
35
+ ```
38
36
 
39
- ## Batch API
37
+ ## License
40
38
 
41
- - **Endpoint**: `/v1/batches` (multi-endpoint support)
42
- - **Discount**: 50% off real-time pricing
43
- - **Status**: Stable
39
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omp-provider-capabilities/openrouter",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "OpenRouter provider extension: batch execution, server tools (shell, web search).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -17,9 +17,22 @@
17
17
  "omp": {
18
18
  "extensions": [
19
19
  "./src/index.ts"
20
- ]
20
+ ],
21
+ "settings": {
22
+ "batch.enabled": {
23
+ "type": "boolean",
24
+ "default": true,
25
+ "description": "Enable OpenRouter batch API"
26
+ },
27
+ "tools.enabled": {
28
+ "type": "boolean",
29
+ "default": true,
30
+ "description": "Enable OpenRouter server tools"
31
+ }
32
+ }
21
33
  },
22
34
  "files": [
35
+ "LICENSE",
23
36
  "src/",
24
37
  "README.md",
25
38
  "!src/**/*.test.ts",
@@ -33,5 +46,6 @@
33
46
  "omp-plugin",
34
47
  "omp-extension",
35
48
  "oh-my-pi"
36
- ]
49
+ ],
50
+ "license": "MIT"
37
51
  }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * OpenRouter Agent SDK wrapper.
3
+ *
4
+ * Wraps OpenRouter's API for multi-turn agent loops via direct HTTP.
5
+ */
6
+
7
+ import type {
8
+ AgentSDK,
9
+ AgentConfig,
10
+ AgentResult,
11
+ AgentMessage,
12
+ AgentTool,
13
+ } from "@omp-provider-capabilities/core";
14
+
15
+ export class OpenRouterAgentSDK implements AgentSDK {
16
+ public provider = "openrouter";
17
+ private apiKey: string;
18
+
19
+ constructor(apiKey: string) {
20
+ this.apiKey = apiKey;
21
+ }
22
+
23
+ isAvailable(): boolean {
24
+ return !!this.apiKey;
25
+ }
26
+
27
+ async run(prompt: string, config: AgentConfig): Promise<AgentResult> {
28
+ const history: AgentMessage[] = [...(config.history || [])];
29
+ const maxTurns = config.maxTurns || 10;
30
+ let toolCallCount = 0;
31
+ let totalInputTokens = 0;
32
+ let totalOutputTokens = 0;
33
+
34
+ const messages: Array<{ role: string; content: string }> = [
35
+ ...(config.history || []).map((m) => ({ role: m.role, content: m.content })),
36
+ { role: "user", content: prompt },
37
+ ];
38
+
39
+ if (config.instruction) {
40
+ messages.unshift({ role: "system", content: config.instruction });
41
+ }
42
+
43
+ for (let turn = 0; turn < maxTurns; turn++) {
44
+ const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
45
+ method: "POST",
46
+ headers: {
47
+ "Content-Type": "application/json",
48
+ Authorization: `Bearer ${this.apiKey}`,
49
+ "HTTP-Referer": "https://github.com/blyzer/omp-provider-capabilities",
50
+ "X-Title": "OMP Provider Capabilities",
51
+ },
52
+ body: JSON.stringify({
53
+ model: config.model || "anthropic/claude-sonnet-4",
54
+ messages,
55
+ max_tokens: 4096,
56
+ tools: config.tools?.map((t) => ({
57
+ type: "function",
58
+ function: { name: t.name, description: t.description, parameters: t.parameters },
59
+ })),
60
+ }),
61
+ });
62
+
63
+ if (!response.ok) {
64
+ const errorText = await response.text();
65
+ return { output: "", history, toolCallCount, error: `OpenRouter API error: ${response.status} ${errorText}` };
66
+ }
67
+
68
+ const data = await response.json();
69
+ if (data.usage) {
70
+ totalInputTokens += data.usage.prompt_tokens || 0;
71
+ totalOutputTokens += data.usage.completion_tokens || 0;
72
+ }
73
+
74
+ const choices = data.choices || [];
75
+ if (choices.length === 0) break;
76
+
77
+ const message = choices[0].message;
78
+ if (message.tool_calls) {
79
+ toolCallCount += message.tool_calls.length;
80
+ for (const tc of message.tool_calls) {
81
+ messages.push({ role: "assistant", content: JSON.stringify(tc) });
82
+ const tool = config.tools?.find((t) => t.name === tc.function?.name);
83
+ let result = "Tool not found";
84
+ if (tool) {
85
+ try {
86
+ result = await tool.execute(tc.function?.arguments ? JSON.parse(tc.function.arguments) : {});
87
+ } catch (e) {
88
+ result = `Tool error: ${e instanceof Error ? e.message : String(e)}`;
89
+ }
90
+ }
91
+ messages.push({ role: "tool", content: result });
92
+ history.push({ role: "tool", content: result, toolCallId: tc.id, toolName: tc.function?.name });
93
+ }
94
+ } else if (message.content) {
95
+ messages.push({ role: "assistant", content: message.content });
96
+ history.push({ role: "assistant", content: message.content });
97
+ return {
98
+ output: message.content, history, toolCallCount,
99
+ usage: { inputTokens: totalInputTokens, outputTokens: totalOutputTokens, totalTokens: totalInputTokens + totalOutputTokens },
100
+ };
101
+ }
102
+ }
103
+
104
+ return {
105
+ output: "", history, toolCallCount,
106
+ usage: { inputTokens: totalInputTokens, outputTokens: totalOutputTokens, totalTokens: totalInputTokens + totalOutputTokens },
107
+ };
108
+ }
109
+ }
package/src/index.ts CHANGED
@@ -145,3 +145,4 @@ export default function openrouterExtension(pi: ExtensionAPI) {
145
145
  await store.save();
146
146
  });
147
147
  }
148
+ export { OpenRouterAgentSDK } from './agent-sdk';