@kognitivedev/vercel-ai-provider 0.1.1 → 0.1.2
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/README.md +38 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -2
- package/package.json +1 -1
- package/src/index.ts +15 -5
package/README.md
CHANGED
|
@@ -85,7 +85,8 @@ type CLModelWrapper = (
|
|
|
85
85
|
userId?: string;
|
|
86
86
|
agentId?: string;
|
|
87
87
|
sessionId?: string;
|
|
88
|
-
}
|
|
88
|
+
},
|
|
89
|
+
providerOptions?: Record<string, unknown>
|
|
89
90
|
) => LanguageModelV2;
|
|
90
91
|
```
|
|
91
92
|
|
|
@@ -97,6 +98,7 @@ type CLModelWrapper = (
|
|
|
97
98
|
| `settings.userId` | `string` | - | User identifier (required for memory features) |
|
|
98
99
|
| `settings.agentId` | `string` | - | Override default agent ID |
|
|
99
100
|
| `settings.sessionId` | `string` | - | Session identifier (required for logging) |
|
|
101
|
+
| `providerOptions` | `Record<string, unknown>` | - | Provider-specific options passed directly to the underlying provider |
|
|
100
102
|
|
|
101
103
|
## Usage Examples
|
|
102
104
|
|
|
@@ -124,6 +126,41 @@ const { text } = await generateText({
|
|
|
124
126
|
});
|
|
125
127
|
```
|
|
126
128
|
|
|
129
|
+
### With OpenRouter (Provider Options)
|
|
130
|
+
|
|
131
|
+
Pass provider-specific options as the third parameter:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { createCognitiveLayer } from "@kognitivedev/vercel-ai-provider";
|
|
135
|
+
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
136
|
+
import { generateText } from "ai";
|
|
137
|
+
|
|
138
|
+
const openrouter = createOpenRouter({
|
|
139
|
+
apiKey: process.env.OPENROUTER_API_KEY
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const clModel = createCognitiveLayer({
|
|
143
|
+
provider: openrouter.chat,
|
|
144
|
+
clConfig: {
|
|
145
|
+
appId: "my-app",
|
|
146
|
+
baseUrl: "https://api.kognitive.dev"
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Pass provider-specific options as the third parameter
|
|
151
|
+
const { text } = await generateText({
|
|
152
|
+
model: clModel("moonshotai/kimi-k2-0905", {
|
|
153
|
+
userId: "user-123",
|
|
154
|
+
sessionId: "session-abc"
|
|
155
|
+
}, {
|
|
156
|
+
provider: {
|
|
157
|
+
only: ["openai"]
|
|
158
|
+
}
|
|
159
|
+
}),
|
|
160
|
+
prompt: "What's the weather like?"
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
127
164
|
### With Anthropic
|
|
128
165
|
|
|
129
166
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type CLModelWrapper = (modelId: string, settings?: {
|
|
|
15
15
|
userId?: string;
|
|
16
16
|
agentId?: string;
|
|
17
17
|
sessionId?: string;
|
|
18
|
-
}) => LanguageModelV2;
|
|
18
|
+
}, providerOptions?: Record<string, unknown>) => LanguageModelV2;
|
|
19
19
|
export declare function createCognitiveLayer(config: {
|
|
20
20
|
provider: any;
|
|
21
21
|
clConfig: CognitiveLayerConfig;
|
package/dist/index.js
CHANGED
|
@@ -52,8 +52,11 @@ function createCognitiveLayer(config) {
|
|
|
52
52
|
const updated = [{ role: "system", content: memoryPrompt }, ...incomingMessages];
|
|
53
53
|
return { nextParams, messages: updated, mode: "prepend-system" };
|
|
54
54
|
};
|
|
55
|
-
return (modelId, settings) => {
|
|
56
|
-
|
|
55
|
+
return (modelId, settings, providerOptions) => {
|
|
56
|
+
// Pass provider options through to the underlying provider
|
|
57
|
+
const model = (providerOptions
|
|
58
|
+
? provider(modelId, providerOptions)
|
|
59
|
+
: provider(modelId));
|
|
57
60
|
const userId = settings === null || settings === void 0 ? void 0 : settings.userId;
|
|
58
61
|
const agentId = (settings === null || settings === void 0 ? void 0 : settings.agentId) || clConfig.defaultAgentId || "default";
|
|
59
62
|
const sessionId = settings === null || settings === void 0 ? void 0 : settings.sessionId;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,7 +16,8 @@ export interface CognitiveLayerConfig {
|
|
|
16
16
|
|
|
17
17
|
export type CLModelWrapper = (
|
|
18
18
|
modelId: string,
|
|
19
|
-
settings?: { userId?: string; agentId?: string; sessionId?: string }
|
|
19
|
+
settings?: { userId?: string; agentId?: string; sessionId?: string },
|
|
20
|
+
providerOptions?: Record<string, unknown>
|
|
20
21
|
) => LanguageModelV2;
|
|
21
22
|
|
|
22
23
|
export function createCognitiveLayer(config: {
|
|
@@ -92,8 +93,17 @@ export function createCognitiveLayer(config: {
|
|
|
92
93
|
return { nextParams, messages: updated, mode: "prepend-system" };
|
|
93
94
|
};
|
|
94
95
|
|
|
95
|
-
return (
|
|
96
|
-
|
|
96
|
+
return (
|
|
97
|
+
modelId: string,
|
|
98
|
+
settings?: { userId?: string; agentId?: string; sessionId?: string },
|
|
99
|
+
providerOptions?: Record<string, unknown>
|
|
100
|
+
) => {
|
|
101
|
+
// Pass provider options through to the underlying provider
|
|
102
|
+
const model = (
|
|
103
|
+
providerOptions
|
|
104
|
+
? provider(modelId, providerOptions)
|
|
105
|
+
: provider(modelId)
|
|
106
|
+
) as LanguageModelV2;
|
|
97
107
|
const userId = settings?.userId;
|
|
98
108
|
const agentId = settings?.agentId || clConfig.defaultAgentId || "default";
|
|
99
109
|
const sessionId = settings?.sessionId;
|
|
@@ -158,7 +168,7 @@ ${userContext}
|
|
|
158
168
|
systemPromptToAdd
|
|
159
169
|
);
|
|
160
170
|
|
|
161
|
-
|
|
171
|
+
|
|
162
172
|
|
|
163
173
|
console.log("CL: injecting memory system prompt", {
|
|
164
174
|
systemPromptToAdd
|
|
@@ -169,7 +179,7 @@ ${userContext}
|
|
|
169
179
|
|
|
170
180
|
return { ...nextParams, prompt: messagesWithMemory };
|
|
171
181
|
},
|
|
172
|
-
|
|
182
|
+
|
|
173
183
|
async wrapGenerate({ doGenerate, params }) {
|
|
174
184
|
const result = await doGenerate();
|
|
175
185
|
|