@profullstack/ai-sdk-c0mpute 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +111 -2
- package/dist/index.cjs +124 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +103 -0
- package/package.json +77 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Profullstack, Inc.
|
|
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
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @profullstack/ai-sdk-c0mpute
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[c0mpute](https://c0mpute.com) provider for the [Vercel AI SDK](https://ai-sdk.dev).
|
|
4
|
+
|
|
5
|
+
c0mpute is a decentralized, peer-to-peer compute network. Your request runs on someone's spare computer (a "node") that serves open-weight models such as Qwen, Devstral and Nemotron. There is no rate card: every job is a sealed-bid auction among the nodes online, the lowest bid under your cap wins, and the market takes a 5% fee. Speed and quality vary by node and model, so treat it as a cheap, open alternative for everyday text work rather than a drop-in for a frontier model.
|
|
6
|
+
|
|
7
|
+
The whole stack is MIT licensed: [github.com/profullstack/c0mpute](https://github.com/profullstack/c0mpute).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @profullstack/ai-sdk-c0mpute ai
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Get an API key (`c0k_...`) from the keys tab of [c0mpute.com/chat](https://c0mpute.com/chat) (sign in with CoinPay), then:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
export C0MPUTE_API_KEY=c0k_...
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Usage is billed to your c0mpute balance. With an empty balance the account falls back to a small free daily allowance.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { c0mpute } from '@profullstack/ai-sdk-c0mpute';
|
|
27
|
+
import { generateText } from 'ai';
|
|
28
|
+
|
|
29
|
+
const { text, response } = await generateText({
|
|
30
|
+
model: c0mpute('auto'),
|
|
31
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(text);
|
|
35
|
+
console.log('served by', response.modelId); // the concrete model the router picked
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Streaming
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { c0mpute } from '@profullstack/ai-sdk-c0mpute';
|
|
42
|
+
import { streamText } from 'ai';
|
|
43
|
+
|
|
44
|
+
const result = streamText({
|
|
45
|
+
model: c0mpute('auto:fast'),
|
|
46
|
+
prompt: 'Explain sealed-bid auctions in three sentences.',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
for await (const chunk of result.textStream) process.stdout.write(chunk);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Streams are standard Server-Sent Events. A job waits in an auction and a queue before a node starts it, so the first text can take several seconds, and it often arrives in a few large chunks rather than token by token.
|
|
53
|
+
|
|
54
|
+
### Custom settings
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { createC0mpute } from '@profullstack/ai-sdk-c0mpute';
|
|
58
|
+
|
|
59
|
+
const c0mpute = createC0mpute({
|
|
60
|
+
apiKey: process.env.MY_C0MPUTE_KEY, // defaults to C0MPUTE_API_KEY
|
|
61
|
+
baseURL: 'https://c0mpute.com/v1', // the default
|
|
62
|
+
headers: { 'x-app': 'my-app' },
|
|
63
|
+
// fetch: customFetch,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Models
|
|
68
|
+
|
|
69
|
+
| Model id | What it is |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `auto` | The c0mpute router picks an open model per request (default choice) |
|
|
72
|
+
| `auto:fast`, `auto:standard`, `auto:high`, `auto:max` | Router with a speed / quality preference |
|
|
73
|
+
| `qwen3:4b`, `qwen2.5-coder:7b`, `qwen2.5-coder:14b`, `qwen3-coder:30b`, `qwen3.8:27b`, `devstral:24b`, `nemotron-3-nano:30b`, ... | A specific open-weight model |
|
|
74
|
+
|
|
75
|
+
Concrete models are only available while a node that serves them is online. The live list is at [c0mpute.com/v1/models](https://c0mpute.com/v1/models). If no node serves a model right now the API answers with an error that names the ones that are, and under heavy load you may see `Network is busy`. `auto` is the most reliable choice. The model that actually answered is in `response.modelId`, and the router's reasoning is in `providerMetadata.c0mpute.route`.
|
|
76
|
+
|
|
77
|
+
## What works and what does not
|
|
78
|
+
|
|
79
|
+
| Feature | Status |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| Text generation (`generateText`) | Yes |
|
|
82
|
+
| Streaming (`streamText`) | Yes |
|
|
83
|
+
| `temperature`, `maxOutputTokens` (up to 8192) | Yes |
|
|
84
|
+
| Tool calling | No. Tools are not sent to the model and the SDK emits an `unsupported` warning. Use c0mpute chat plugins (remote MCP servers) on c0mpute.com if you need tools. |
|
|
85
|
+
| Image / file input | No. Text only; non-text parts are removed with a warning. |
|
|
86
|
+
| Structured output | Not enforced. Ask for JSON in the prompt and validate it yourself. |
|
|
87
|
+
| Embeddings, images | Not through this provider |
|
|
88
|
+
|
|
89
|
+
The API also limits a request to 200 messages and 200,000 characters. Very long outputs from large models on CPU nodes may not finish before the stream closes (about 10 minutes), so split long jobs.
|
|
90
|
+
|
|
91
|
+
## Run a node and earn
|
|
92
|
+
|
|
93
|
+
c0mpute is only as big as the machines on it. If you have a spare CPU or GPU, run a node and get paid for the jobs it wins:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
curl -fsSL https://c0mpute.com/install.sh | sh
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Linux, macOS and Windows (WSL2), CPU or GPU. See [c0mpute.com/providers](https://c0mpute.com/providers).
|
|
100
|
+
|
|
101
|
+
## Development
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npm install
|
|
105
|
+
npm test # unit tests, no network
|
|
106
|
+
C0MPUTE_API_KEY=c0k_... npm run test:live # real calls against c0mpute.com
|
|
107
|
+
npm run build
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT, see [LICENSE](LICENSE). Made by [Profullstack](https://profullstack.com).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
C0MPUTE_BASE_URL: () => C0MPUTE_BASE_URL,
|
|
24
|
+
c0mpute: () => c0mpute,
|
|
25
|
+
createC0mpute: () => createC0mpute,
|
|
26
|
+
toC0mputeBody: () => toC0mputeBody
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
30
|
+
var import_provider = require("@ai-sdk/provider");
|
|
31
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
32
|
+
var C0MPUTE_BASE_URL = "https://c0mpute.com/v1";
|
|
33
|
+
var DROPPED_FIELDS = ["tools", "tool_choice", "parallel_tool_calls"];
|
|
34
|
+
function toC0mputeBody(body, warnings) {
|
|
35
|
+
const out = { ...body };
|
|
36
|
+
for (const field of DROPPED_FIELDS) {
|
|
37
|
+
if (out[field] !== void 0) {
|
|
38
|
+
if (field === "tools") {
|
|
39
|
+
warnings?.push({
|
|
40
|
+
type: "unsupported",
|
|
41
|
+
feature: "tools",
|
|
42
|
+
details: "c0mpute does not support tool calling yet; tools were not sent to the model."
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
delete out[field];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(out.messages)) {
|
|
49
|
+
let droppedParts = false;
|
|
50
|
+
out.messages = out.messages.map((message) => {
|
|
51
|
+
if (!Array.isArray(message.content)) return message;
|
|
52
|
+
const text = message.content.filter((part) => {
|
|
53
|
+
const isText = part?.type === "text" && typeof part.text === "string";
|
|
54
|
+
if (!isText) droppedParts = true;
|
|
55
|
+
return isText;
|
|
56
|
+
}).map((part) => part.text).join("\n");
|
|
57
|
+
return { ...message, content: text };
|
|
58
|
+
});
|
|
59
|
+
if (droppedParts) {
|
|
60
|
+
warnings?.push({
|
|
61
|
+
type: "unsupported",
|
|
62
|
+
feature: "non-text message content",
|
|
63
|
+
details: "c0mpute accepts text only; image and file parts were removed from the prompt."
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
var routeMetadata = {
|
|
70
|
+
async extractMetadata({ parsedBody }) {
|
|
71
|
+
const route = parsedBody?.x_c0mpute_route;
|
|
72
|
+
return route ? { c0mpute: { route } } : void 0;
|
|
73
|
+
},
|
|
74
|
+
createStreamExtractor() {
|
|
75
|
+
let route;
|
|
76
|
+
return {
|
|
77
|
+
processChunk(chunk) {
|
|
78
|
+
const r = chunk?.x_c0mpute_route;
|
|
79
|
+
if (r) route = r;
|
|
80
|
+
},
|
|
81
|
+
buildMetadata() {
|
|
82
|
+
return route ? { c0mpute: { route } } : void 0;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function createC0mpute(options = {}) {
|
|
88
|
+
const inner = (0, import_openai_compatible.createOpenAICompatible)({
|
|
89
|
+
name: "c0mpute",
|
|
90
|
+
baseURL: (0, import_provider_utils.withoutTrailingSlash)(options.baseURL) ?? C0MPUTE_BASE_URL,
|
|
91
|
+
apiKey: () => (0, import_provider_utils.loadApiKey)({
|
|
92
|
+
apiKey: options.apiKey,
|
|
93
|
+
environmentVariableName: "C0MPUTE_API_KEY",
|
|
94
|
+
description: "c0mpute"
|
|
95
|
+
}),
|
|
96
|
+
headers: options.headers,
|
|
97
|
+
fetch: options.fetch,
|
|
98
|
+
supportsStructuredOutputs: false,
|
|
99
|
+
transformRequestBody: toC0mputeBody,
|
|
100
|
+
metadataExtractor: routeMetadata
|
|
101
|
+
});
|
|
102
|
+
const languageModel = (modelId) => inner.chatModel(modelId);
|
|
103
|
+
const provider = ((modelId) => languageModel(modelId));
|
|
104
|
+
Object.assign(provider, {
|
|
105
|
+
specificationVersion: "v4",
|
|
106
|
+
languageModel,
|
|
107
|
+
chatModel: languageModel,
|
|
108
|
+
embeddingModel: (modelId) => {
|
|
109
|
+
throw new import_provider.NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
110
|
+
},
|
|
111
|
+
imageModel: (modelId) => {
|
|
112
|
+
throw new import_provider.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return provider;
|
|
116
|
+
}
|
|
117
|
+
var c0mpute = createC0mpute();
|
|
118
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
119
|
+
0 && (module.exports = {
|
|
120
|
+
C0MPUTE_BASE_URL,
|
|
121
|
+
c0mpute,
|
|
122
|
+
createC0mpute,
|
|
123
|
+
toC0mputeBody
|
|
124
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ProviderV4, LanguageModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
/** Default OpenAI-compatible endpoint of the c0mpute network. */
|
|
5
|
+
declare const C0MPUTE_BASE_URL = "https://c0mpute.com/v1";
|
|
6
|
+
/**
|
|
7
|
+
* Model ids served on c0mpute. `auto` and the `auto:<effort>` aliases ask the
|
|
8
|
+
* c0mpute router to pick an open model per request. Concrete ids come and go
|
|
9
|
+
* with the nodes online (GET https://c0mpute.com/v1/models lists them), so any
|
|
10
|
+
* string is accepted.
|
|
11
|
+
*/
|
|
12
|
+
type C0mputeModelId = 'auto' | 'auto:fast' | 'auto:standard' | 'auto:high' | 'auto:max' | 'qwen3:4b' | 'qwen2.5-coder:7b' | 'qwen2.5-coder:14b' | 'qwen3-coder:30b' | 'qwen3.8:27b' | 'devstral:24b' | 'deepseek-coder-v2:16b' | 'nemotron-3-nano:4b' | 'nemotron-3-nano:30b' | (string & {});
|
|
13
|
+
interface C0mputeProviderSettings {
|
|
14
|
+
/**
|
|
15
|
+
* c0mpute API key (`c0k_...`), from the keys tab of https://c0mpute.com/chat.
|
|
16
|
+
* Defaults to the `C0MPUTE_API_KEY` environment variable.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
/** Base URL. Defaults to `https://c0mpute.com/v1`. */
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
/** Extra headers sent with every request. */
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
/** Custom fetch, e.g. for testing or a proxy. */
|
|
24
|
+
fetch?: FetchFunction;
|
|
25
|
+
}
|
|
26
|
+
interface C0mputeProvider extends ProviderV4 {
|
|
27
|
+
(modelId: C0mputeModelId): LanguageModelV4;
|
|
28
|
+
languageModel(modelId: C0mputeModelId): LanguageModelV4;
|
|
29
|
+
chatModel(modelId: C0mputeModelId): LanguageModelV4;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Shape a Chat Completions body for c0mpute. The c0mpute API accepts only
|
|
33
|
+
* string message content and system/user/assistant roles, and does not do
|
|
34
|
+
* tool calling, so:
|
|
35
|
+
* - text-only content arrays are joined into one string,
|
|
36
|
+
* - non-text parts (images, files) are dropped with a warning,
|
|
37
|
+
* - `tools` / `tool_choice` are dropped with a warning.
|
|
38
|
+
*/
|
|
39
|
+
declare function toC0mputeBody(body: Record<string, any>, warnings?: SharedV4Warning[]): Record<string, any>;
|
|
40
|
+
/** Create a c0mpute provider instance. */
|
|
41
|
+
declare function createC0mpute(options?: C0mputeProviderSettings): C0mputeProvider;
|
|
42
|
+
/** Default instance. Reads `C0MPUTE_API_KEY` at request time. */
|
|
43
|
+
declare const c0mpute: C0mputeProvider;
|
|
44
|
+
|
|
45
|
+
export { C0MPUTE_BASE_URL, c0mpute, createC0mpute, toC0mputeBody };
|
|
46
|
+
export type { C0mputeModelId, C0mputeProvider, C0mputeProviderSettings };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ProviderV4, LanguageModelV4, SharedV4Warning } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
|
|
4
|
+
/** Default OpenAI-compatible endpoint of the c0mpute network. */
|
|
5
|
+
declare const C0MPUTE_BASE_URL = "https://c0mpute.com/v1";
|
|
6
|
+
/**
|
|
7
|
+
* Model ids served on c0mpute. `auto` and the `auto:<effort>` aliases ask the
|
|
8
|
+
* c0mpute router to pick an open model per request. Concrete ids come and go
|
|
9
|
+
* with the nodes online (GET https://c0mpute.com/v1/models lists them), so any
|
|
10
|
+
* string is accepted.
|
|
11
|
+
*/
|
|
12
|
+
type C0mputeModelId = 'auto' | 'auto:fast' | 'auto:standard' | 'auto:high' | 'auto:max' | 'qwen3:4b' | 'qwen2.5-coder:7b' | 'qwen2.5-coder:14b' | 'qwen3-coder:30b' | 'qwen3.8:27b' | 'devstral:24b' | 'deepseek-coder-v2:16b' | 'nemotron-3-nano:4b' | 'nemotron-3-nano:30b' | (string & {});
|
|
13
|
+
interface C0mputeProviderSettings {
|
|
14
|
+
/**
|
|
15
|
+
* c0mpute API key (`c0k_...`), from the keys tab of https://c0mpute.com/chat.
|
|
16
|
+
* Defaults to the `C0MPUTE_API_KEY` environment variable.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
/** Base URL. Defaults to `https://c0mpute.com/v1`. */
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
/** Extra headers sent with every request. */
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
/** Custom fetch, e.g. for testing or a proxy. */
|
|
24
|
+
fetch?: FetchFunction;
|
|
25
|
+
}
|
|
26
|
+
interface C0mputeProvider extends ProviderV4 {
|
|
27
|
+
(modelId: C0mputeModelId): LanguageModelV4;
|
|
28
|
+
languageModel(modelId: C0mputeModelId): LanguageModelV4;
|
|
29
|
+
chatModel(modelId: C0mputeModelId): LanguageModelV4;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Shape a Chat Completions body for c0mpute. The c0mpute API accepts only
|
|
33
|
+
* string message content and system/user/assistant roles, and does not do
|
|
34
|
+
* tool calling, so:
|
|
35
|
+
* - text-only content arrays are joined into one string,
|
|
36
|
+
* - non-text parts (images, files) are dropped with a warning,
|
|
37
|
+
* - `tools` / `tool_choice` are dropped with a warning.
|
|
38
|
+
*/
|
|
39
|
+
declare function toC0mputeBody(body: Record<string, any>, warnings?: SharedV4Warning[]): Record<string, any>;
|
|
40
|
+
/** Create a c0mpute provider instance. */
|
|
41
|
+
declare function createC0mpute(options?: C0mputeProviderSettings): C0mputeProvider;
|
|
42
|
+
/** Default instance. Reads `C0MPUTE_API_KEY` at request time. */
|
|
43
|
+
declare const c0mpute: C0mputeProvider;
|
|
44
|
+
|
|
45
|
+
export { C0MPUTE_BASE_URL, c0mpute, createC0mpute, toC0mputeBody };
|
|
46
|
+
export type { C0mputeModelId, C0mputeProvider, C0mputeProviderSettings };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createOpenAICompatible
|
|
4
|
+
} from "@ai-sdk/openai-compatible";
|
|
5
|
+
import {
|
|
6
|
+
NoSuchModelError
|
|
7
|
+
} from "@ai-sdk/provider";
|
|
8
|
+
import {
|
|
9
|
+
loadApiKey,
|
|
10
|
+
withoutTrailingSlash
|
|
11
|
+
} from "@ai-sdk/provider-utils";
|
|
12
|
+
var C0MPUTE_BASE_URL = "https://c0mpute.com/v1";
|
|
13
|
+
var DROPPED_FIELDS = ["tools", "tool_choice", "parallel_tool_calls"];
|
|
14
|
+
function toC0mputeBody(body, warnings) {
|
|
15
|
+
const out = { ...body };
|
|
16
|
+
for (const field of DROPPED_FIELDS) {
|
|
17
|
+
if (out[field] !== void 0) {
|
|
18
|
+
if (field === "tools") {
|
|
19
|
+
warnings?.push({
|
|
20
|
+
type: "unsupported",
|
|
21
|
+
feature: "tools",
|
|
22
|
+
details: "c0mpute does not support tool calling yet; tools were not sent to the model."
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
delete out[field];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(out.messages)) {
|
|
29
|
+
let droppedParts = false;
|
|
30
|
+
out.messages = out.messages.map((message) => {
|
|
31
|
+
if (!Array.isArray(message.content)) return message;
|
|
32
|
+
const text = message.content.filter((part) => {
|
|
33
|
+
const isText = part?.type === "text" && typeof part.text === "string";
|
|
34
|
+
if (!isText) droppedParts = true;
|
|
35
|
+
return isText;
|
|
36
|
+
}).map((part) => part.text).join("\n");
|
|
37
|
+
return { ...message, content: text };
|
|
38
|
+
});
|
|
39
|
+
if (droppedParts) {
|
|
40
|
+
warnings?.push({
|
|
41
|
+
type: "unsupported",
|
|
42
|
+
feature: "non-text message content",
|
|
43
|
+
details: "c0mpute accepts text only; image and file parts were removed from the prompt."
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
var routeMetadata = {
|
|
50
|
+
async extractMetadata({ parsedBody }) {
|
|
51
|
+
const route = parsedBody?.x_c0mpute_route;
|
|
52
|
+
return route ? { c0mpute: { route } } : void 0;
|
|
53
|
+
},
|
|
54
|
+
createStreamExtractor() {
|
|
55
|
+
let route;
|
|
56
|
+
return {
|
|
57
|
+
processChunk(chunk) {
|
|
58
|
+
const r = chunk?.x_c0mpute_route;
|
|
59
|
+
if (r) route = r;
|
|
60
|
+
},
|
|
61
|
+
buildMetadata() {
|
|
62
|
+
return route ? { c0mpute: { route } } : void 0;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
function createC0mpute(options = {}) {
|
|
68
|
+
const inner = createOpenAICompatible({
|
|
69
|
+
name: "c0mpute",
|
|
70
|
+
baseURL: withoutTrailingSlash(options.baseURL) ?? C0MPUTE_BASE_URL,
|
|
71
|
+
apiKey: () => loadApiKey({
|
|
72
|
+
apiKey: options.apiKey,
|
|
73
|
+
environmentVariableName: "C0MPUTE_API_KEY",
|
|
74
|
+
description: "c0mpute"
|
|
75
|
+
}),
|
|
76
|
+
headers: options.headers,
|
|
77
|
+
fetch: options.fetch,
|
|
78
|
+
supportsStructuredOutputs: false,
|
|
79
|
+
transformRequestBody: toC0mputeBody,
|
|
80
|
+
metadataExtractor: routeMetadata
|
|
81
|
+
});
|
|
82
|
+
const languageModel = (modelId) => inner.chatModel(modelId);
|
|
83
|
+
const provider = ((modelId) => languageModel(modelId));
|
|
84
|
+
Object.assign(provider, {
|
|
85
|
+
specificationVersion: "v4",
|
|
86
|
+
languageModel,
|
|
87
|
+
chatModel: languageModel,
|
|
88
|
+
embeddingModel: (modelId) => {
|
|
89
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
90
|
+
},
|
|
91
|
+
imageModel: (modelId) => {
|
|
92
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return provider;
|
|
96
|
+
}
|
|
97
|
+
var c0mpute = createC0mpute();
|
|
98
|
+
export {
|
|
99
|
+
C0MPUTE_BASE_URL,
|
|
100
|
+
c0mpute,
|
|
101
|
+
createC0mpute,
|
|
102
|
+
toC0mputeBody
|
|
103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@profullstack/ai-sdk-c0mpute",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "c0mpute provider for the Vercel AI SDK: open-weight models on a peer-to-peer compute network, priced by sealed-bid auction.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Profullstack, Inc. <hello@c0mpute.com>",
|
|
7
|
+
"homepage": "https://github.com/profullstack/ai-sdk-c0mpute#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/profullstack/ai-sdk-c0mpute.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/profullstack/ai-sdk-c0mpute/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ai",
|
|
17
|
+
"ai-sdk",
|
|
18
|
+
"vercel-ai-sdk",
|
|
19
|
+
"provider",
|
|
20
|
+
"c0mpute",
|
|
21
|
+
"llm",
|
|
22
|
+
"open-weight",
|
|
23
|
+
"decentralized",
|
|
24
|
+
"p2p",
|
|
25
|
+
"openai-compatible"
|
|
26
|
+
],
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/index.d.cts",
|
|
40
|
+
"default": "./dist/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=22"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
55
|
+
"typecheck": "tsc -p .",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:live": "C0MPUTE_LIVE=1 vitest run test/live.test.ts",
|
|
58
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@ai-sdk/openai-compatible": "^3.0.94",
|
|
62
|
+
"@ai-sdk/provider": "^4.0.39",
|
|
63
|
+
"@ai-sdk/provider-utils": "^5.0.83"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/node": "^26.6.6",
|
|
70
|
+
"ai": "^7.0.179",
|
|
71
|
+
"tsup": "^9.0.0",
|
|
72
|
+
"typescript": "^6.0.3",
|
|
73
|
+
"vitest": "^5.1.1",
|
|
74
|
+
"zod": "^4.6.7"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
}
|
|
79
|
+
}
|