@cslug/ai 0.11.1 → 0.12.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/package.json +7 -7
- package/src/ai-provider.ts +9 -1
- package/src/generators.ts +20 -0
- package/src/index.ts +1 -0
- package/stubs/agent.stub +11 -0
- package/stubs/tool.stub +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cslug/ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Agents and tools, structured output, prompts, streaming; Anthropic and OpenAI-compatible providers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"bun": ">=1.3.14"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@cslug/core": "0.
|
|
33
|
-
"@cslug/validation": "0.
|
|
34
|
-
"@cslug/queue": "0.
|
|
35
|
-
"@cslug/http": "0.
|
|
36
|
-
"@cslug/database": "0.
|
|
37
|
-
"@cslug/search": "0.
|
|
32
|
+
"@cslug/core": "0.12.0",
|
|
33
|
+
"@cslug/validation": "0.12.0",
|
|
34
|
+
"@cslug/queue": "0.12.0",
|
|
35
|
+
"@cslug/http": "0.12.0",
|
|
36
|
+
"@cslug/database": "0.12.0",
|
|
37
|
+
"@cslug/search": "0.12.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@cslug/queue": {
|
package/src/ai-provider.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { databaseStore } from './conversation-store'
|
|
|
9
9
|
import { Conversations } from './conversations'
|
|
10
10
|
import { embedderFor, type TextEmbedder } from './embedders'
|
|
11
11
|
import { setFakeEmbedder } from './fake'
|
|
12
|
+
import { MakeAgentCommand, MakeToolCommand } from './generators'
|
|
12
13
|
import { asMcpTools, discoverTools, handleMcp, type McpCaller, type McpReply, mcpTools } from './mcp'
|
|
13
14
|
import type { SearchableIndex } from './search-tools'
|
|
14
15
|
|
|
@@ -99,7 +100,14 @@ export class AiRecordCommand extends Command {
|
|
|
99
100
|
*/
|
|
100
101
|
export class AiProvider extends ServiceProvider {
|
|
101
102
|
register() {
|
|
102
|
-
this.commands([
|
|
103
|
+
this.commands([
|
|
104
|
+
AiPromptsCommand,
|
|
105
|
+
AiRecordCommand,
|
|
106
|
+
AiEvalCommand,
|
|
107
|
+
McpServeCommand,
|
|
108
|
+
MakeAgentCommand,
|
|
109
|
+
MakeToolCommand,
|
|
110
|
+
])
|
|
103
111
|
this.app.singleton(
|
|
104
112
|
Ai,
|
|
105
113
|
(c) => new Ai(this.app, this.app.config<AiConfig | undefined>('ai') ?? {}, c.resolve(Logger)),
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { defineGenerator } from '@cslug/core'
|
|
3
|
+
|
|
4
|
+
const STUBS = join(import.meta.dir, '../stubs')
|
|
5
|
+
|
|
6
|
+
/** `cslug make:agent OfferExtractor` → `app/agents/offer-extractor-agent.ts`. */
|
|
7
|
+
export const MakeAgentCommand = defineGenerator({
|
|
8
|
+
kind: 'agent',
|
|
9
|
+
description: 'Create an AI agent',
|
|
10
|
+
stubs: STUBS,
|
|
11
|
+
files: (n) => [{ stub: 'agent.stub', target: `app/agents/${n.file}.ts` }],
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
/** `cslug make:tool FindOperators` → `app/tools/find-operators-tool.ts` (its model-facing name: find_operators). */
|
|
15
|
+
export const MakeToolCommand = defineGenerator({
|
|
16
|
+
kind: 'tool',
|
|
17
|
+
description: 'Create an AI tool',
|
|
18
|
+
stubs: STUBS,
|
|
19
|
+
files: (n) => [{ stub: 'tool.stub', target: `app/tools/${n.file}.ts` }],
|
|
20
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ export {
|
|
|
54
54
|
VoyageEmbedder,
|
|
55
55
|
} from './embedders'
|
|
56
56
|
export { AiFake, type AiFixture, type AiRun, FIXTURES_DIR, installAiFake, setFakeEmbedder } from './fake'
|
|
57
|
+
export { MakeAgentCommand, MakeToolCommand } from './generators'
|
|
57
58
|
export {
|
|
58
59
|
asMcpTools,
|
|
59
60
|
discoverTools,
|
package/stubs/agent.stub
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { inject } from '@cslug/core'
|
|
2
|
+
import { Agent } from '@cslug/ai'
|
|
3
|
+
import { v } from '@cslug/validation'
|
|
4
|
+
|
|
5
|
+
@inject()
|
|
6
|
+
export class {{ class }} extends Agent {
|
|
7
|
+
model = 'fast' // a role from config/ai.ts (models), or a model id
|
|
8
|
+
instructions = 'You are a helpful assistant.' // or prompt('{{ kebab }}') for resources/prompts/{{ kebab }}.md
|
|
9
|
+
output = v.object({ answer: v.string() }) // remove for plain text
|
|
10
|
+
// tools = [SomethingTool]
|
|
11
|
+
}
|
package/stubs/tool.stub
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { inject } from '@cslug/core'
|
|
2
|
+
import { Tool } from '@cslug/ai'
|
|
3
|
+
import { v } from '@cslug/validation'
|
|
4
|
+
|
|
5
|
+
@inject()
|
|
6
|
+
export class {{ class }} extends Tool {
|
|
7
|
+
name = '{{ snake }}'
|
|
8
|
+
description = 'What this tool does, and when the model should use it.'
|
|
9
|
+
input = v.object({ id: v.string() })
|
|
10
|
+
|
|
11
|
+
async handle({ id }: v.infer<this['input']>) {
|
|
12
|
+
return { id }
|
|
13
|
+
}
|
|
14
|
+
}
|