@shrkcrft/ai 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/ai-provider.d.ts +18 -0
- package/dist/ai-provider.d.ts.map +1 -0
- package/dist/ai-provider.js +9 -0
- package/dist/ai-request.d.ts +33 -0
- package/dist/ai-request.d.ts.map +1 -0
- package/dist/ai-request.js +6 -0
- package/dist/claude/claude-cli-adapter.d.ts +17 -0
- package/dist/claude/claude-cli-adapter.d.ts.map +1 -0
- package/dist/claude/claude-cli-adapter.js +52 -0
- package/dist/claude/claude-provider.d.ts +15 -0
- package/dist/claude/claude-provider.d.ts.map +1 -0
- package/dist/claude/claude-provider.js +65 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/prompt/prompt-builder.d.ts +9 -0
- package/dist/prompt/prompt-builder.d.ts.map +1 -0
- package/dist/prompt/prompt-builder.js +19 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SharkCraft contributors
|
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @shrkcrft/ai
|
|
2
|
+
|
|
3
|
+
SharkCraft AI provider abstraction: Claude HTTP + Claude CLI adapters.
|
|
4
|
+
|
|
5
|
+
Part of [SharkCraft](https://github.com/shrkcrft/sharkcraft) — a deterministic, local-first toolkit that gives AI coding agents durable project context. See the main repo for documentation, examples, and the `shrk` CLI.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @shrkcrft/ai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Result, AppError } from '@shrkcrft/core';
|
|
2
|
+
import type { IAiProviderConfig, IAiRequest, IAiResponse } from './ai-request.js';
|
|
3
|
+
export interface IAiProvider {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
configure(config: IAiProviderConfig): void;
|
|
7
|
+
isReady(): boolean;
|
|
8
|
+
send(request: IAiRequest): Promise<Result<IAiResponse, AppError>>;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class AbstractAiProvider implements IAiProvider {
|
|
11
|
+
abstract readonly id: string;
|
|
12
|
+
abstract readonly name: string;
|
|
13
|
+
protected config: IAiProviderConfig;
|
|
14
|
+
configure(config: IAiProviderConfig): void;
|
|
15
|
+
isReady(): boolean;
|
|
16
|
+
abstract send(request: IAiRequest): Promise<Result<IAiResponse, AppError>>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ai-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-provider.d.ts","sourceRoot":"","sources":["../src/ai-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAElF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC3C,OAAO,IAAI,OAAO,CAAC;IACnB,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;CACnE;AAED,8BAAsB,kBAAmB,YAAW,WAAW;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAM;IAEzC,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAI1C,OAAO,IAAI,OAAO;IAIlB,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;CAC3E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare enum AiMessageRole {
|
|
2
|
+
System = "system",
|
|
3
|
+
User = "user",
|
|
4
|
+
Assistant = "assistant"
|
|
5
|
+
}
|
|
6
|
+
export interface IAiMessage {
|
|
7
|
+
role: AiMessageRole;
|
|
8
|
+
content: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IAiRequest {
|
|
11
|
+
messages: readonly IAiMessage[];
|
|
12
|
+
model?: string;
|
|
13
|
+
maxTokens?: number;
|
|
14
|
+
temperature?: number;
|
|
15
|
+
context?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface IAiResponse {
|
|
18
|
+
content: string;
|
|
19
|
+
model: string;
|
|
20
|
+
finishReason?: string;
|
|
21
|
+
usage?: {
|
|
22
|
+
inputTokens?: number;
|
|
23
|
+
outputTokens?: number;
|
|
24
|
+
};
|
|
25
|
+
raw?: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface IAiProviderConfig {
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
baseUrl?: string;
|
|
30
|
+
model?: string;
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ai-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-request.d.ts","sourceRoot":"","sources":["../src/ai-request.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,SAAS,cAAc;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AppError, type Result } from '@shrkcrft/core';
|
|
2
|
+
import { AbstractAiProvider } from '../ai-provider.js';
|
|
3
|
+
import type { IAiRequest, IAiResponse } from '../ai-request.js';
|
|
4
|
+
/**
|
|
5
|
+
* Optional adapter that shells out to a local `claude` CLI binary.
|
|
6
|
+
* It assumes the binary supports `--print --output-format=text`. If it does not,
|
|
7
|
+
* isReady() returns false and send() returns an actionable error.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ClaudeCliAdapter extends AbstractAiProvider {
|
|
10
|
+
readonly id = "claude-cli";
|
|
11
|
+
readonly name = "Claude (local CLI)";
|
|
12
|
+
private readonly cliPath;
|
|
13
|
+
constructor(cliPath?: string);
|
|
14
|
+
isReady(): boolean;
|
|
15
|
+
send(request: IAiRequest): Promise<Result<IAiResponse, AppError>>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=claude-cli-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-cli-adapter.d.ts","sourceRoot":"","sources":["../../src/claude/claude-cli-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEhG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,kBAAkB;IACtD,QAAQ,CAAC,EAAE,gBAAgB;IAC3B,QAAQ,CAAC,IAAI,wBAAwB;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,SAAW;IAK9B,OAAO,IAAI,OAAO;IAKZ,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;CAgDxE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AppErrorImpl, ERROR_CODES, err, ok } from '@shrkcrft/core';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { AbstractAiProvider } from "../ai-provider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Optional adapter that shells out to a local `claude` CLI binary.
|
|
6
|
+
* It assumes the binary supports `--print --output-format=text`. If it does not,
|
|
7
|
+
* isReady() returns false and send() returns an actionable error.
|
|
8
|
+
*/
|
|
9
|
+
export class ClaudeCliAdapter extends AbstractAiProvider {
|
|
10
|
+
id = 'claude-cli';
|
|
11
|
+
name = 'Claude (local CLI)';
|
|
12
|
+
cliPath;
|
|
13
|
+
constructor(cliPath = 'claude') {
|
|
14
|
+
super();
|
|
15
|
+
this.cliPath = cliPath;
|
|
16
|
+
}
|
|
17
|
+
isReady() {
|
|
18
|
+
// Best-effort. The actual check happens during send().
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
async send(request) {
|
|
22
|
+
const prompt = request.messages.map((m) => `[${m.role}] ${m.content}`).join('\n\n');
|
|
23
|
+
return await new Promise((resolve) => {
|
|
24
|
+
try {
|
|
25
|
+
const proc = spawn(this.cliPath, ['--print', '--output-format=text'], {
|
|
26
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
27
|
+
});
|
|
28
|
+
let stdout = '';
|
|
29
|
+
let stderr = '';
|
|
30
|
+
proc.stdout.on('data', (b) => (stdout += b.toString('utf8')));
|
|
31
|
+
proc.stderr.on('data', (b) => (stderr += b.toString('utf8')));
|
|
32
|
+
proc.on('error', (e) => {
|
|
33
|
+
resolve(err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `Failed to spawn claude CLI at "${this.cliPath}": ${e.message}`, { suggestion: 'Install Claude Code or pass a different cliPath', cause: e })));
|
|
34
|
+
});
|
|
35
|
+
proc.on('close', (code) => {
|
|
36
|
+
if (code === 0) {
|
|
37
|
+
resolve(ok({ content: stdout.trim(), model: 'claude-cli' }));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resolve(err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `claude CLI exited with ${code}: ${stderr.slice(0, 500)}`)));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
proc.stdin.end(prompt);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
resolve(err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `Failed to invoke claude CLI: ${e.message}`, {
|
|
47
|
+
cause: e,
|
|
48
|
+
})));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AppError, type Result } from '@shrkcrft/core';
|
|
2
|
+
import { AbstractAiProvider } from '../ai-provider.js';
|
|
3
|
+
import type { IAiRequest, IAiResponse } from '../ai-request.js';
|
|
4
|
+
/**
|
|
5
|
+
* Reference HTTP adapter for Anthropic's Claude Messages API.
|
|
6
|
+
* Kept dependency-free: uses fetch() directly. If ANTHROPIC_API_KEY is missing,
|
|
7
|
+
* isReady() returns false and send() reports an actionable error.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ClaudeProvider extends AbstractAiProvider {
|
|
10
|
+
readonly id = "claude";
|
|
11
|
+
readonly name = "Anthropic Claude (HTTP)";
|
|
12
|
+
isReady(): boolean;
|
|
13
|
+
send(request: IAiRequest): Promise<Result<IAiResponse, AppError>>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=claude-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-provider.d.ts","sourceRoot":"","sources":["../../src/claude/claude-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;IACpD,QAAQ,CAAC,EAAE,YAAY;IACvB,QAAQ,CAAC,IAAI,6BAA6B;IAE1C,OAAO,IAAI,OAAO;IAIZ,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;CAmExE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AppErrorImpl, ERROR_CODES, err, ok } from '@shrkcrft/core';
|
|
2
|
+
import { AbstractAiProvider } from "../ai-provider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reference HTTP adapter for Anthropic's Claude Messages API.
|
|
5
|
+
* Kept dependency-free: uses fetch() directly. If ANTHROPIC_API_KEY is missing,
|
|
6
|
+
* isReady() returns false and send() reports an actionable error.
|
|
7
|
+
*/
|
|
8
|
+
export class ClaudeProvider extends AbstractAiProvider {
|
|
9
|
+
id = 'claude';
|
|
10
|
+
name = 'Anthropic Claude (HTTP)';
|
|
11
|
+
isReady() {
|
|
12
|
+
return Boolean(this.config.apiKey ?? process.env.ANTHROPIC_API_KEY);
|
|
13
|
+
}
|
|
14
|
+
async send(request) {
|
|
15
|
+
const apiKey = this.config.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
16
|
+
if (!apiKey) {
|
|
17
|
+
return err(new AppErrorImpl(ERROR_CODES.INVALID_INPUT, 'ANTHROPIC_API_KEY is not set — cannot reach Claude', { suggestion: 'export ANTHROPIC_API_KEY=...' }));
|
|
18
|
+
}
|
|
19
|
+
const baseUrl = this.config.baseUrl ?? 'https://api.anthropic.com';
|
|
20
|
+
const model = request.model ?? this.config.model ?? 'claude-sonnet-4-6';
|
|
21
|
+
const maxTokens = request.maxTokens ?? 1024;
|
|
22
|
+
const messages = request.messages
|
|
23
|
+
.filter((m) => m.role !== 'system')
|
|
24
|
+
.map((m) => ({ role: m.role, content: m.content }));
|
|
25
|
+
const system = request.messages
|
|
26
|
+
.filter((m) => m.role === 'system')
|
|
27
|
+
.map((m) => m.content)
|
|
28
|
+
.join('\n\n') || undefined;
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(`${baseUrl}/v1/messages`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'content-type': 'application/json',
|
|
34
|
+
'x-api-key': apiKey,
|
|
35
|
+
'anthropic-version': '2023-06-01',
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({ model, max_tokens: maxTokens, messages, system }),
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) {
|
|
40
|
+
const text = await res.text();
|
|
41
|
+
return err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `Claude API ${res.status}: ${text.slice(0, 500)}`));
|
|
42
|
+
}
|
|
43
|
+
const json = (await res.json());
|
|
44
|
+
const text = (json.content ?? [])
|
|
45
|
+
.filter((b) => b.type === 'text' && typeof b.text === 'string')
|
|
46
|
+
.map((b) => b.text)
|
|
47
|
+
.join('');
|
|
48
|
+
return ok({
|
|
49
|
+
content: text,
|
|
50
|
+
model: json.model ?? model,
|
|
51
|
+
finishReason: json.stop_reason,
|
|
52
|
+
usage: {
|
|
53
|
+
inputTokens: json.usage?.input_tokens,
|
|
54
|
+
outputTokens: json.usage?.output_tokens,
|
|
55
|
+
},
|
|
56
|
+
raw: json,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
return err(new AppErrorImpl(ERROR_CODES.IO_ERROR, `Failed to call Claude: ${e.message}`, {
|
|
61
|
+
cause: e,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IAiMessage } from '../ai-request.js';
|
|
2
|
+
export interface BuildPromptInput {
|
|
3
|
+
systemPreamble?: string;
|
|
4
|
+
context?: string;
|
|
5
|
+
task: string;
|
|
6
|
+
userMessage?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildPromptMessages(input: BuildPromptInput): IAiMessage[];
|
|
9
|
+
//# sourceMappingURL=prompt-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-builder.d.ts","sourceRoot":"","sources":["../../src/prompt/prompt-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,UAAU,EAAE,CAkBzE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AiMessageRole } from "../ai-request.js";
|
|
2
|
+
export function buildPromptMessages(input) {
|
|
3
|
+
const messages = [];
|
|
4
|
+
const systemParts = [];
|
|
5
|
+
if (input.systemPreamble)
|
|
6
|
+
systemParts.push(input.systemPreamble.trim());
|
|
7
|
+
if (input.context) {
|
|
8
|
+
systemParts.push('## Repository context\n\nUse this context as authoritative ground truth.\n\n' +
|
|
9
|
+
input.context.trim());
|
|
10
|
+
}
|
|
11
|
+
if (systemParts.length) {
|
|
12
|
+
messages.push({ role: AiMessageRole.System, content: systemParts.join('\n\n') });
|
|
13
|
+
}
|
|
14
|
+
const userContent = input.userMessage
|
|
15
|
+
? `${input.task}\n\n${input.userMessage}`
|
|
16
|
+
: input.task;
|
|
17
|
+
messages.push({ role: AiMessageRole.User, content: userContent });
|
|
18
|
+
return messages;
|
|
19
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shrkcrft/ai",
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
|
+
"description": "SharkCraft AI provider abstraction: Claude HTTP + Claude CLI adapters.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "SharkCraft contributors",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"bun": "./src/index.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/shrkcrft/sharkcraft.git",
|
|
26
|
+
"directory": "packages/ai"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/shrkcrft/sharkcraft",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/shrkcrft/sharkcraft/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"sharkcraft",
|
|
34
|
+
"ai",
|
|
35
|
+
"claude",
|
|
36
|
+
"anthropic"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"bun": ">=1.1.0",
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@shrkcrft/core": "^0.1.0-alpha.2",
|
|
47
|
+
"@shrkcrft/context": "^0.1.0-alpha.2"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|