Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/ai/c0mpute/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# c0mpute

Provides the c0mpute AI provider adapter for sh1pt agent and model workflows.

## What it does

- Connects an AI/model provider to sh1pt.
- Normalizes provider configuration for agent and automation workflows.
- Includes setup guidance for required credentials or provider configuration.

## Package

- Name: `@profullstack/sh1pt-ai-c0mpute`
- Path: `packages/ai/c0mpute`
- Adapter ID: `ai-c0mpute`
- Homepage: https://sh1pt.com

## Scripts

- `build`: `tsc -p tsconfig.json`
- `prepublishOnly`: `pnpm build`
- `typecheck`: `tsc -p tsconfig.json --noEmit`

## Usage

```bash
pnpm add @profullstack/sh1pt-ai-c0mpute
```

## Development

```bash
pnpm --filter @profullstack/sh1pt-ai-c0mpute typecheck
```

Run tests from the repository root when this module includes a test file:

```bash
pnpm vitest run packages/ai/c0mpute/src/index.test.ts
```

<!-- Generated by scripts/gen-module-readmes.mjs -->
38 changes: 38 additions & 0 deletions packages/ai/c0mpute/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@profullstack/sh1pt-ai-c0mpute",
"version": "0.1.0",
"type": "module",
"main": "./src/index.ts",
"types": "./src/index.ts",
"scripts": {
"build": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit",
"prepublishOnly": "pnpm build"
},
"dependencies": {
"@profullstack/sh1pt-core": "workspace:*"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/profullstack/sh1pt.git",
"directory": "packages/ai/c0mpute"
},
"homepage": "https://sh1pt.com",
"bugs": "https://github.com/profullstack/sh1pt/issues",
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
}
}
}
55 changes: 55 additions & 0 deletions packages/ai/c0mpute/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { smokeTest } from '@profullstack/sh1pt-core/testing';
import { afterEach, describe, expect, it, vi } from 'vitest';
import adapter from './index.js';

smokeTest(adapter, { idPrefix: 'ai' });

const ctx = (secrets: Record<string, string> = { C0MPUTE_API_KEY: 'ik_live_test' }, dryRun = false) => ({
secret: (key: string) => secrets[key],
log: () => {},
dryRun,
});

describe('c0mpute generation', () => {
afterEach(() => {
vi.unstubAllGlobals();
});

it('short-circuits dry-run before network calls', async () => {
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
const result = await adapter.generate(ctx(undefined, true), 'hello', {}, {});
expect(result).toEqual({ text: '[dry-run]', model: 'huihui_ai/qwen3.5-abliterated:9b' });
expect(fetchMock).not.toHaveBeenCalled();
});

it('posts to Infernet, peers only', async () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ choices: [{ message: { content: 'hi' } }], model: 'huihui_ai/qwen3.5-abliterated:9b' }),
});
vi.stubGlobal('fetch', fetchMock);

const result = await adapter.generate(ctx(), 'hello', { system: 'be brief', maxTokens: 20 }, {});

const [url, request] = fetchMock.mock.calls[0]!;
expect(url).toBe('https://infernetprotocol.com/v1/chat/completions');
expect(request.headers.authorization).toBe('Bearer ik_live_test');
expect(JSON.parse(request.body)).toEqual({
model: 'huihui_ai/qwen3.5-abliterated:9b',
messages: [
{ role: 'system', content: 'be brief' },
{ role: 'user', content: 'hello' },
],
p2p_only: true,
max_tokens: 20,
});
expect(result.text).toBe('hi');
});

it('requires a key and never repeats it in an error', async () => {
await expect(adapter.generate(ctx({}), 'hello', {}, {})).rejects.toThrow('C0MPUTE_API_KEY not in vault');
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: false, status: 503, text: async () => 'bad ik_live_test' }));
await expect(adapter.generate(ctx(), 'hello', {}, {})).rejects.toThrow('c0mpute 503: bad [redacted]');
});
});
69 changes: 69 additions & 0 deletions packages/ai/c0mpute/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { defineAi, tokenSetup } from '@profullstack/sh1pt-core';

interface Config {
baseUrl?: string;
}

const DEFAULT_BASE = 'https://infernetprotocol.com';
const DEFAULT_MODEL = 'huihui_ai/qwen3.5-abliterated:9b';

function redact(value: string, apiKey: string): string {
return apiKey ? value.split(apiKey).join('[redacted]') : value;
}

export default defineAi<Config>({
id: 'ai-c0mpute',
label: 'c0mpute',
defaultModel: DEFAULT_MODEL,
models: [DEFAULT_MODEL, 'huihui_ai/qwen3.5-abliterated:4b'],

async generate(ctx, prompt, opts, config) {
const apiKey = ctx.secret('C0MPUTE_API_KEY');
if (!apiKey) throw new Error('C0MPUTE_API_KEY not in vault');
const model = opts.model ?? DEFAULT_MODEL;
ctx.log(`c0mpute · model=${model} · ${prompt.length} chars in`);
if (ctx.dryRun) return { text: '[dry-run]', model };

const messages: Array<{ role: string; content: string }> = [];
if (opts.system) messages.push({ role: 'system', content: opts.system });
messages.push({ role: 'user', content: prompt });

const base = (config.baseUrl ?? DEFAULT_BASE).replace(/\/+$/, '');
const res = await fetch(`${base}/v1/chat/completions`, {
method: 'POST',
headers: {
authorization: `Bearer ${apiKey}`,
'content-type': 'application/json',
},
body: JSON.stringify({
model,
messages,
// Peer nodes only, never Infernet's billed hosted fallback.
p2p_only: true,
...(opts.maxTokens !== undefined ? { max_tokens: opts.maxTokens } : {}),
...(opts.temperature !== undefined ? { temperature: opts.temperature } : {}),
...opts.extra,
}),
// A job on the peer network can take a minute or more.
signal: AbortSignal.timeout(300_000),
});
if (!res.ok) throw new Error(`c0mpute ${res.status}: ${redact(await res.text(), apiKey).slice(0, 200)}`);
const data = (await res.json()) as {
choices: Array<{ message?: { content?: string } }>;
model: string;
};
// c0mpute reports no token counts.
return { text: data.choices[0]?.message?.content ?? '', model: data.model };
},

setup: tokenSetup<Config>({
secretKey: 'C0MPUTE_API_KEY',
label: 'c0mpute',
vendorDocUrl: 'https://infernetprotocol.com',
steps: [
'Sign in at https://infernetprotocol.com and create an account API key (ik_live_)',
'Copy the key, it is usually shown once',
'Paste below; sh1pt encrypts it in the vault',
],
}),
});
10 changes: 10 additions & 0 deletions packages/ai/c0mpute/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": [
"src/**/*"
]
}
2 changes: 1 addition & 1 deletion packages/cli/src/adapter-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const CATEGORIES: readonly AdapterCategory[] = [
adapters: [
'ai21', 'aionlabs', 'akashml', 'alibaba-cloud', 'amazon-bedrock',
'arcee', 'atlascloud', 'azure', 'baidu', 'baseten', 'cerebras',
'cheaperinference', 'chutes', 'clarifai', 'claude', 'cloudflare', 'cohere', 'deepinfra',
'c0mpute', 'cheaperinference', 'chutes', 'clarifai', 'claude', 'cloudflare', 'cohere', 'deepinfra',
'deepseek', 'featherless', 'fireworks', 'friendli', 'gemini',
'gmicloud', 'google-vertex', 'groq', 'inception', 'inceptron',
'infermatic', 'inflection', 'ionet', 'kimi', 'liquid', 'litellm', 'mancer',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ socialCmd
// keyed off provider API keys held in the vault.
const AI_PLATFORMS = [
// Real integrations
'claude', 'openai', 'qwen', 'gemini',
'c0mpute', 'claude', 'openai', 'qwen', 'gemini',
// BYOK stubs (OpenRouter-compatible providers — implementations land
// case-by-case; setup() collects the API key into the vault today)
'ai21', 'aionlabs', 'akashml', 'alibaba-cloud', 'amazon-bedrock', 'arcee',
Expand Down
34 changes: 24 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sites/sh1pt.com/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@opentelemetry/resources": "^3.0.0",
"@opentelemetry/sdk-logs": "^3.0.0",
"@profullstack/affiliates": "0.3.0",
"@profullstack/autoblog": "github:profullstack/autoblog#75e54af",
"@profullstack/autoblog": "0.5.0",
"@profullstack/coinpay-onboard": "0.4.0",
"@profullstack/footer": "latest",
"@profullstack/profile": "0.1.6",
Expand Down
Loading