rhachet 1.17.0 → 1.18.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/dist/_topublish/rhachet-brain-anthropic/src/atoms/genBrainAtom.d.ts +19 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/atoms/genBrainAtom.js +95 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/atoms/genBrainAtom.js.map +1 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/index.d.ts +14 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/index.js +27 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/index.js.map +1 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/repls/genBrainRepl.d.ts +19 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/repls/genBrainRepl.js +137 -0
- package/dist/_topublish/rhachet-brain-anthropic/src/repls/genBrainRepl.js.map +1 -0
- package/dist/_topublish/rhachet-brain-openai/src/atoms/genBrainAtom.d.ts +19 -0
- package/dist/_topublish/rhachet-brain-openai/src/atoms/genBrainAtom.js +86 -0
- package/dist/_topublish/rhachet-brain-openai/src/atoms/genBrainAtom.js.map +1 -0
- package/dist/_topublish/rhachet-brain-openai/src/index.d.ts +14 -0
- package/dist/_topublish/rhachet-brain-openai/src/index.js +27 -0
- package/dist/_topublish/rhachet-brain-openai/src/index.js.map +1 -0
- package/dist/_topublish/rhachet-brain-openai/src/repls/genBrainRepl.d.ts +19 -0
- package/dist/_topublish/rhachet-brain-openai/src/repls/genBrainRepl.js +97 -0
- package/dist/_topublish/rhachet-brain-openai/src/repls/genBrainRepl.js.map +1 -0
- package/dist/contract/sdk.d.ts +2 -0
- package/dist/contract/sdk.js +5 -1
- package/dist/contract/sdk.js.map +1 -1
- package/dist/domain.objects/BrainAtom.d.ts +54 -0
- package/dist/domain.objects/BrainAtom.js +9 -0
- package/dist/domain.objects/BrainAtom.js.map +1 -0
- package/dist/domain.objects/BrainAtomPlugs.d.ts +17 -0
- package/dist/domain.objects/BrainAtomPlugs.js +8 -0
- package/dist/domain.objects/BrainAtomPlugs.js.map +1 -0
- package/dist/domain.objects/BrainRepl.d.ts +74 -0
- package/dist/domain.objects/BrainRepl.js +9 -0
- package/dist/domain.objects/BrainRepl.js.map +1 -0
- package/dist/domain.objects/BrainReplPlugs.d.ts +34 -0
- package/dist/domain.objects/BrainReplPlugs.js +8 -0
- package/dist/domain.objects/BrainReplPlugs.js.map +1 -0
- package/dist/domain.objects/ContextBrain.d.ts +73 -0
- package/dist/domain.objects/ContextBrain.js +8 -0
- package/dist/domain.objects/ContextBrain.js.map +1 -0
- package/dist/domain.objects/index.d.ts +3 -0
- package/dist/domain.objects/index.js +3 -0
- package/dist/domain.objects/index.js.map +1 -1
- package/dist/domain.operations/brainAtom/askViaBrainAtom.d.ts +22 -0
- package/dist/domain.operations/brainAtom/askViaBrainAtom.js +19 -0
- package/dist/domain.operations/brainAtom/askViaBrainAtom.js.map +1 -0
- package/dist/domain.operations/brainRepl/actViaBrainRepl.d.ts +26 -0
- package/dist/domain.operations/brainRepl/actViaBrainRepl.js +23 -0
- package/dist/domain.operations/brainRepl/actViaBrainRepl.js.map +1 -0
- package/dist/domain.operations/brainRepl/askViaBrainRepl.d.ts +26 -0
- package/dist/domain.operations/brainRepl/askViaBrainRepl.js +23 -0
- package/dist/domain.operations/brainRepl/askViaBrainRepl.js.map +1 -0
- package/dist/domain.operations/briefs/castBriefsToPrompt.d.ts +13 -0
- package/dist/domain.operations/briefs/castBriefsToPrompt.js +21 -0
- package/dist/domain.operations/briefs/castBriefsToPrompt.js.map +1 -0
- package/dist/domain.operations/context/findBrainAtomByRef.d.ts +10 -0
- package/dist/domain.operations/context/findBrainAtomByRef.js +23 -0
- package/dist/domain.operations/context/findBrainAtomByRef.js.map +1 -0
- package/dist/domain.operations/context/findBrainReplByRef.d.ts +10 -0
- package/dist/domain.operations/context/findBrainReplByRef.js +23 -0
- package/dist/domain.operations/context/findBrainReplByRef.js.map +1 -0
- package/dist/domain.operations/context/genContextBrain.d.ts +14 -0
- package/dist/domain.operations/context/genContextBrain.js +51 -0
- package/dist/domain.operations/context/genContextBrain.js.map +1 -0
- package/dist/domain.operations/schema/castZodToJsonSchema.d.ts +14 -0
- package/dist/domain.operations/schema/castZodToJsonSchema.js +23 -0
- package/dist/domain.operations/schema/castZodToJsonSchema.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrainAtom } from '../../../../domain.objects/BrainAtom';
|
|
2
|
+
/**
|
|
3
|
+
* .what = supported claude atom slugs
|
|
4
|
+
* .why = enables type-safe slug specification with model variants
|
|
5
|
+
*/
|
|
6
|
+
type ClaudeAtomSlug = 'claude/haiku' | 'claude/haiku/v3.5' | 'claude/haiku/v4.5' | 'claude/sonnet' | 'claude/sonnet/v4' | 'claude/sonnet/v4.5' | 'claude/opus' | 'claude/opus/v4' | 'claude/opus/v4.5';
|
|
7
|
+
/**
|
|
8
|
+
* .what = factory to generate claude brain atom instances
|
|
9
|
+
* .why = enables model variant selection via slug (e.g., haiku for speed, opus for quality)
|
|
10
|
+
*
|
|
11
|
+
* .example
|
|
12
|
+
* genBrainAtom({ slug: 'claude/haiku' }) // fast + cheap
|
|
13
|
+
* genBrainAtom({ slug: 'claude/sonnet' }) // balanced
|
|
14
|
+
* genBrainAtom({ slug: 'claude/opus/v4.5' }) // highest quality
|
|
15
|
+
*/
|
|
16
|
+
export declare const genBrainAtom: (input: {
|
|
17
|
+
slug: ClaudeAtomSlug;
|
|
18
|
+
}) => BrainAtom;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.genBrainAtom = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const BrainAtom_1 = require("../../../../domain.objects/BrainAtom");
|
|
9
|
+
const castBriefsToPrompt_1 = require("../../../../domain.operations/briefs/castBriefsToPrompt");
|
|
10
|
+
/**
|
|
11
|
+
* .what = model configuration by slug
|
|
12
|
+
* .why = maps slugs to API model names and descriptions
|
|
13
|
+
*/
|
|
14
|
+
const CONFIG_BY_SLUG = {
|
|
15
|
+
'claude/haiku': {
|
|
16
|
+
model: 'claude-haiku-4-5-20251001',
|
|
17
|
+
description: 'claude haiku 4.5 - fastest and most cost-effective',
|
|
18
|
+
},
|
|
19
|
+
'claude/haiku/v3.5': {
|
|
20
|
+
model: 'claude-3-5-haiku-20241022',
|
|
21
|
+
description: 'claude haiku 3.5 - fast and cost-effective',
|
|
22
|
+
},
|
|
23
|
+
'claude/haiku/v4.5': {
|
|
24
|
+
model: 'claude-haiku-4-5-20251001',
|
|
25
|
+
description: 'claude haiku 4.5 - fastest and most cost-effective',
|
|
26
|
+
},
|
|
27
|
+
'claude/sonnet': {
|
|
28
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
29
|
+
description: 'claude sonnet 4.5 - balanced performance and capability',
|
|
30
|
+
},
|
|
31
|
+
'claude/sonnet/v4': {
|
|
32
|
+
model: 'claude-sonnet-4-20250514',
|
|
33
|
+
description: 'claude sonnet 4 - balanced performance and capability',
|
|
34
|
+
},
|
|
35
|
+
'claude/sonnet/v4.5': {
|
|
36
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
37
|
+
description: 'claude sonnet 4.5 - balanced performance and capability',
|
|
38
|
+
},
|
|
39
|
+
'claude/opus': {
|
|
40
|
+
model: 'claude-opus-4-5-20251101',
|
|
41
|
+
description: 'claude opus 4.5 - most capable for complex reasoning',
|
|
42
|
+
},
|
|
43
|
+
'claude/opus/v4': {
|
|
44
|
+
model: 'claude-opus-4-20250514',
|
|
45
|
+
description: 'claude opus 4 - highly capable for complex reasoning',
|
|
46
|
+
},
|
|
47
|
+
'claude/opus/v4.5': {
|
|
48
|
+
model: 'claude-opus-4-5-20251101',
|
|
49
|
+
description: 'claude opus 4.5 - most capable for complex reasoning',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* .what = factory to generate claude brain atom instances
|
|
54
|
+
* .why = enables model variant selection via slug (e.g., haiku for speed, opus for quality)
|
|
55
|
+
*
|
|
56
|
+
* .example
|
|
57
|
+
* genBrainAtom({ slug: 'claude/haiku' }) // fast + cheap
|
|
58
|
+
* genBrainAtom({ slug: 'claude/sonnet' }) // balanced
|
|
59
|
+
* genBrainAtom({ slug: 'claude/opus/v4.5' }) // highest quality
|
|
60
|
+
*/
|
|
61
|
+
const genBrainAtom = (input) => {
|
|
62
|
+
const config = CONFIG_BY_SLUG[input.slug];
|
|
63
|
+
return new BrainAtom_1.BrainAtom({
|
|
64
|
+
repo: 'anthropic',
|
|
65
|
+
slug: input.slug,
|
|
66
|
+
description: config.description,
|
|
67
|
+
/**
|
|
68
|
+
* .what = stateless inference (no tool use)
|
|
69
|
+
* .why = provides direct model access for reasoning tasks
|
|
70
|
+
*/
|
|
71
|
+
ask: async (askInput, context) => {
|
|
72
|
+
// compose system prompt from briefs
|
|
73
|
+
const systemPrompt = askInput.role.briefs
|
|
74
|
+
? await (0, castBriefsToPrompt_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
|
|
75
|
+
: undefined;
|
|
76
|
+
// get anthropic client from context or create new one
|
|
77
|
+
const anthropic = context?.anthropic ??
|
|
78
|
+
new sdk_1.default({ apiKey: process.env.ANTHROPIC_API_KEY });
|
|
79
|
+
// call anthropic api
|
|
80
|
+
const response = await anthropic.messages.create({
|
|
81
|
+
model: config.model,
|
|
82
|
+
max_tokens: 16384,
|
|
83
|
+
system: systemPrompt,
|
|
84
|
+
messages: [{ role: 'user', content: askInput.prompt }],
|
|
85
|
+
});
|
|
86
|
+
// extract text content from response
|
|
87
|
+
const textBlock = response.content.find((block) => block.type === 'text');
|
|
88
|
+
const content = textBlock?.text ?? '';
|
|
89
|
+
// parse output via schema
|
|
90
|
+
return askInput.schema.output.parse({ content });
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
exports.genBrainAtom = genBrainAtom;
|
|
95
|
+
//# sourceMappingURL=genBrainAtom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genBrainAtom.js","sourceRoot":"","sources":["../../../../../src/_topublish/rhachet-brain-anthropic/src/atoms/genBrainAtom.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAM1C,6DAA0D;AAC1D,yFAAsF;AAiBtF;;;GAGG;AACH,MAAM,cAAc,GAGhB;IACF,cAAc,EAAE;QACd,KAAK,EAAE,2BAA2B;QAClC,WAAW,EAAE,oDAAoD;KAClE;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,2BAA2B;QAClC,WAAW,EAAE,4CAA4C;KAC1D;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,2BAA2B;QAClC,WAAW,EAAE,oDAAoD;KAClE;IACD,eAAe,EAAE;QACf,KAAK,EAAE,4BAA4B;QACnC,WAAW,EAAE,yDAAyD;KACvE;IACD,kBAAkB,EAAE;QAClB,KAAK,EAAE,0BAA0B;QACjC,WAAW,EAAE,uDAAuD;KACrE;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,4BAA4B;QACnC,WAAW,EAAE,yDAAyD;KACvE;IACD,aAAa,EAAE;QACb,KAAK,EAAE,0BAA0B;QACjC,WAAW,EAAE,sDAAsD;KACpE;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,wBAAwB;QAC/B,WAAW,EAAE,sDAAsD;KACpE;IACD,kBAAkB,EAAE;QAClB,KAAK,EAAE,0BAA0B;QACjC,WAAW,EAAE,sDAAsD;KACpE;CACF,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAa,EAAE;IACzE,MAAM,MAAM,GAAG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AAC,CAAC;AACL,CAAC,CAAC;AAhDW,QAAA,YAAY,gBAgDvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BrainAtom } from '../../../domain.objects/BrainAtom';
|
|
2
|
+
import type { BrainRepl } from '../../../domain.objects/BrainRepl';
|
|
3
|
+
/**
|
|
4
|
+
* .what = returns all brain atoms provided by anthropic
|
|
5
|
+
* .why = enables consumers to register anthropic atoms with genContextBrain
|
|
6
|
+
*/
|
|
7
|
+
export declare const getBrainAtomsByAnthropic: () => BrainAtom[];
|
|
8
|
+
/**
|
|
9
|
+
* .what = returns all brain repls provided by anthropic
|
|
10
|
+
* .why = enables consumers to register anthropic repls with genContextBrain
|
|
11
|
+
*/
|
|
12
|
+
export declare const getBrainReplsByAnthropic: () => BrainRepl[];
|
|
13
|
+
export { genBrainAtom } from './atoms/genBrainAtom';
|
|
14
|
+
export { genBrainRepl } from './repls/genBrainRepl';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genBrainRepl = exports.genBrainAtom = exports.getBrainReplsByAnthropic = exports.getBrainAtomsByAnthropic = void 0;
|
|
4
|
+
const genBrainAtom_1 = require("./atoms/genBrainAtom");
|
|
5
|
+
const genBrainRepl_1 = require("./repls/genBrainRepl");
|
|
6
|
+
/**
|
|
7
|
+
* .what = returns all brain atoms provided by anthropic
|
|
8
|
+
* .why = enables consumers to register anthropic atoms with genContextBrain
|
|
9
|
+
*/
|
|
10
|
+
const getBrainAtomsByAnthropic = () => {
|
|
11
|
+
return [(0, genBrainAtom_1.genBrainAtom)({ slug: 'claude/opus' })];
|
|
12
|
+
};
|
|
13
|
+
exports.getBrainAtomsByAnthropic = getBrainAtomsByAnthropic;
|
|
14
|
+
/**
|
|
15
|
+
* .what = returns all brain repls provided by anthropic
|
|
16
|
+
* .why = enables consumers to register anthropic repls with genContextBrain
|
|
17
|
+
*/
|
|
18
|
+
const getBrainReplsByAnthropic = () => {
|
|
19
|
+
return [(0, genBrainRepl_1.genBrainRepl)({ slug: 'claude/code' })];
|
|
20
|
+
};
|
|
21
|
+
exports.getBrainReplsByAnthropic = getBrainReplsByAnthropic;
|
|
22
|
+
// re-export factories for direct access
|
|
23
|
+
var genBrainAtom_2 = require("./atoms/genBrainAtom");
|
|
24
|
+
Object.defineProperty(exports, "genBrainAtom", { enumerable: true, get: function () { return genBrainAtom_2.genBrainAtom; } });
|
|
25
|
+
var genBrainRepl_2 = require("./repls/genBrainRepl");
|
|
26
|
+
Object.defineProperty(exports, "genBrainRepl", { enumerable: true, get: function () { return genBrainRepl_2.genBrainRepl; } });
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/_topublish/rhachet-brain-anthropic/src/index.ts"],"names":[],"mappings":";;;AAGA,uDAAoD;AACpD,uDAAoD;AAEpD;;;GAGG;AACI,MAAM,wBAAwB,GAAG,GAAgB,EAAE;IACxD,OAAO,CAAC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC;AAEF;;;GAGG;AACI,MAAM,wBAAwB,GAAG,GAAgB,EAAE;IACxD,OAAO,CAAC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC;AAEF,wCAAwC;AACxC,qDAAoD;AAA3C,4GAAA,YAAY,OAAA;AACrB,qDAAoD;AAA3C,4GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrainRepl } from '../../../../domain.objects/BrainRepl';
|
|
2
|
+
/**
|
|
3
|
+
* .what = supported claude code repl slugs
|
|
4
|
+
* .why = enables type-safe slug specification with model variants
|
|
5
|
+
*/
|
|
6
|
+
type ClaudeCodeSlug = 'claude/code' | 'claude/code/haiku' | 'claude/code/haiku/v4.5' | 'claude/code/sonnet' | 'claude/code/sonnet/v4' | 'claude/code/sonnet/v4.5' | 'claude/code/opus' | 'claude/code/opus/v4.5';
|
|
7
|
+
/**
|
|
8
|
+
* .what = factory to generate claude code brain repl instances
|
|
9
|
+
* .why = enables model variant selection via slug (e.g., haiku for speed, opus for quality)
|
|
10
|
+
*
|
|
11
|
+
* .example
|
|
12
|
+
* genBrainRepl({ slug: 'claude/code' }) // default model
|
|
13
|
+
* genBrainRepl({ slug: 'claude/code/haiku' }) // fast + cheap
|
|
14
|
+
* genBrainRepl({ slug: 'claude/code/opus/v4.5' }) // highest quality
|
|
15
|
+
*/
|
|
16
|
+
export declare const genBrainRepl: (input: {
|
|
17
|
+
slug: ClaudeCodeSlug;
|
|
18
|
+
}) => BrainRepl;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genBrainRepl = void 0;
|
|
4
|
+
const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
|
|
5
|
+
const BrainRepl_1 = require("../../../../domain.objects/BrainRepl");
|
|
6
|
+
const castBriefsToPrompt_1 = require("../../../../domain.operations/briefs/castBriefsToPrompt");
|
|
7
|
+
const castZodToJsonSchema_1 = require("../../../../domain.operations/schema/castZodToJsonSchema");
|
|
8
|
+
/**
|
|
9
|
+
* .what = maps slug to anthropic model identifier
|
|
10
|
+
* .why = translates friendly slugs to API model names
|
|
11
|
+
*/
|
|
12
|
+
const MODEL_BY_SLUG = {
|
|
13
|
+
'claude/code': undefined, // use SDK default
|
|
14
|
+
'claude/code/haiku': 'claude-haiku-4-5-20251001',
|
|
15
|
+
'claude/code/haiku/v4.5': 'claude-haiku-4-5-20251001',
|
|
16
|
+
'claude/code/sonnet': 'claude-sonnet-4-5-20250929',
|
|
17
|
+
'claude/code/sonnet/v4': 'claude-sonnet-4-20250514',
|
|
18
|
+
'claude/code/sonnet/v4.5': 'claude-sonnet-4-5-20250929',
|
|
19
|
+
'claude/code/opus': 'claude-opus-4-20250514',
|
|
20
|
+
'claude/code/opus/v4.5': 'claude-opus-4-5-20251101',
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* .what = tools disallowed for readonly ask operations
|
|
24
|
+
* .why = prevents mutations during research/analysis tasks
|
|
25
|
+
*/
|
|
26
|
+
const TOOLS_DISALLOWED_FOR_ASK = [
|
|
27
|
+
'Edit',
|
|
28
|
+
'Write',
|
|
29
|
+
'Bash',
|
|
30
|
+
'NotebookEdit',
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* .what = tools allowed for read+write act operations
|
|
34
|
+
* .why = enables full agentic capabilities for code changes
|
|
35
|
+
*/
|
|
36
|
+
const TOOLS_ALLOWED_FOR_ACT = [
|
|
37
|
+
'Read',
|
|
38
|
+
'Edit',
|
|
39
|
+
'Write',
|
|
40
|
+
'Bash',
|
|
41
|
+
'Glob',
|
|
42
|
+
'Grep',
|
|
43
|
+
'Task',
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* .what = extracts final result from claude-agent-sdk query async generator
|
|
47
|
+
* .why = query() returns an async iterator, need to consume to get result
|
|
48
|
+
*
|
|
49
|
+
* .note = when outputFormat is used, result may be in structured_output field
|
|
50
|
+
*/
|
|
51
|
+
const extractResultFromQuery = async (queryIterator) => {
|
|
52
|
+
let result;
|
|
53
|
+
let structuredOutput;
|
|
54
|
+
for await (const message of queryIterator) {
|
|
55
|
+
// check for result message with success subtype
|
|
56
|
+
if (message.type === 'result' && message.subtype === 'success') {
|
|
57
|
+
result = message.result;
|
|
58
|
+
structuredOutput = message.structured_output;
|
|
59
|
+
}
|
|
60
|
+
// throw on error subtypes
|
|
61
|
+
if (message.type === 'result' && message.subtype !== 'success') {
|
|
62
|
+
throw new Error(`claude-agent-sdk query failed: ${message.subtype}, errors: ${message.errors?.join(', ') ?? 'unknown'}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// prefer structured_output when available (used with outputFormat)
|
|
66
|
+
if (structuredOutput !== undefined)
|
|
67
|
+
return structuredOutput;
|
|
68
|
+
// fall back to parsing result as JSON
|
|
69
|
+
if (result !== undefined)
|
|
70
|
+
return JSON.parse(result);
|
|
71
|
+
throw new Error('no result message received from claude-agent-sdk');
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* .what = invokes claude-agent-sdk query with specified mode
|
|
75
|
+
* .why = dedupes shared logic between ask (readonly) and act (read+write)
|
|
76
|
+
*/
|
|
77
|
+
const invokeQuery = async (input) => {
|
|
78
|
+
// compose system prompt from briefs
|
|
79
|
+
const systemPrompt = input.role.briefs
|
|
80
|
+
? await (0, castBriefsToPrompt_1.castBriefsToPrompt)({ briefs: input.role.briefs })
|
|
81
|
+
: undefined;
|
|
82
|
+
// convert zod schema to json schema for native structured output
|
|
83
|
+
const jsonSchema = (0, castZodToJsonSchema_1.castZodToJsonSchema)({
|
|
84
|
+
schema: input.schema.output,
|
|
85
|
+
target: 'claude',
|
|
86
|
+
});
|
|
87
|
+
// build tool constraints based on mode
|
|
88
|
+
const toolConstraints = input.mode === 'ask'
|
|
89
|
+
? { disallowedTools: [...TOOLS_DISALLOWED_FOR_ASK] }
|
|
90
|
+
: { allowedTools: [...TOOLS_ALLOWED_FOR_ACT] };
|
|
91
|
+
// invoke claude-agent-sdk query
|
|
92
|
+
const queryIterator = (0, claude_agent_sdk_1.query)({
|
|
93
|
+
prompt: input.prompt,
|
|
94
|
+
options: {
|
|
95
|
+
systemPrompt,
|
|
96
|
+
model: input.model,
|
|
97
|
+
...toolConstraints,
|
|
98
|
+
outputFormat: {
|
|
99
|
+
type: 'json_schema',
|
|
100
|
+
schema: jsonSchema,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
// extract final result from async iterator
|
|
105
|
+
const result = await extractResultFromQuery(queryIterator);
|
|
106
|
+
// parse output via schema for runtime validation
|
|
107
|
+
return input.schema.output.parse(result);
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* .what = factory to generate claude code brain repl instances
|
|
111
|
+
* .why = enables model variant selection via slug (e.g., haiku for speed, opus for quality)
|
|
112
|
+
*
|
|
113
|
+
* .example
|
|
114
|
+
* genBrainRepl({ slug: 'claude/code' }) // default model
|
|
115
|
+
* genBrainRepl({ slug: 'claude/code/haiku' }) // fast + cheap
|
|
116
|
+
* genBrainRepl({ slug: 'claude/code/opus/v4.5' }) // highest quality
|
|
117
|
+
*/
|
|
118
|
+
const genBrainRepl = (input) => {
|
|
119
|
+
const model = MODEL_BY_SLUG[input.slug];
|
|
120
|
+
return new BrainRepl_1.BrainRepl({
|
|
121
|
+
repo: 'anthropic',
|
|
122
|
+
slug: input.slug,
|
|
123
|
+
description: `claude code (${input.slug}) - agentic coding assistant with tool use`,
|
|
124
|
+
/**
|
|
125
|
+
* .what = readonly analysis (research, queries, code review)
|
|
126
|
+
* .why = provides safe, non-mutating agent interactions
|
|
127
|
+
*/
|
|
128
|
+
ask: async (askInput, _context) => invokeQuery({ mode: 'ask', model, ...askInput }),
|
|
129
|
+
/**
|
|
130
|
+
* .what = read+write actions (code changes, file edits)
|
|
131
|
+
* .why = provides full agentic capabilities with write access
|
|
132
|
+
*/
|
|
133
|
+
act: async (actInput, _context) => invokeQuery({ mode: 'act', model, ...actInput }),
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
exports.genBrainRepl = genBrainRepl;
|
|
137
|
+
//# sourceMappingURL=genBrainRepl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genBrainRepl.js","sourceRoot":"","sources":["../../../../../src/_topublish/rhachet-brain-anthropic/src/repls/genBrainRepl.ts"],"names":[],"mappings":";;;AAAA,qEAAuD;AAMvD,6DAA0D;AAC1D,yFAAsF;AACtF,2FAAwF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MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAa,EAAE;IACzE,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAExC,OAAO,IAAI,qBAAS,CAAC;QACnB,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,gBAAgB,KAAK,CAAC,IAAI,4CAA4C;QAEnF;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,QAAgB,EACE,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;QAEvE;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,QAAgB,EACE,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;KACxE,CAAC,CAAC;AACL,CAAC,CAAC;AAlCW,QAAA,YAAY,gBAkCvB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrainAtom } from '../../../../domain.objects/BrainAtom';
|
|
2
|
+
/**
|
|
3
|
+
* .what = supported openai atom slugs
|
|
4
|
+
* .why = enables type-safe slug specification with model variants
|
|
5
|
+
*/
|
|
6
|
+
type OpenAIAtomSlug = 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/gpt-4-turbo' | 'openai/o1' | 'openai/o1-mini' | 'openai/o1-preview';
|
|
7
|
+
/**
|
|
8
|
+
* .what = factory to generate openai brain atom instances
|
|
9
|
+
* .why = enables model variant selection via slug
|
|
10
|
+
*
|
|
11
|
+
* .example
|
|
12
|
+
* genBrainAtom({ slug: 'openai/gpt-4o' })
|
|
13
|
+
* genBrainAtom({ slug: 'openai/gpt-4o-mini' }) // fast + cheap
|
|
14
|
+
* genBrainAtom({ slug: 'openai/o1' }) // advanced reasoning
|
|
15
|
+
*/
|
|
16
|
+
export declare const genBrainAtom: (input: {
|
|
17
|
+
slug: OpenAIAtomSlug;
|
|
18
|
+
}) => BrainAtom;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.genBrainAtom = void 0;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
const BrainAtom_1 = require("../../../../domain.objects/BrainAtom");
|
|
9
|
+
const castBriefsToPrompt_1 = require("../../../../domain.operations/briefs/castBriefsToPrompt");
|
|
10
|
+
/**
|
|
11
|
+
* .what = model configuration by slug
|
|
12
|
+
* .why = maps slugs to API model names and descriptions
|
|
13
|
+
*/
|
|
14
|
+
const CONFIG_BY_SLUG = {
|
|
15
|
+
'openai/gpt-4o': {
|
|
16
|
+
model: 'gpt-4o',
|
|
17
|
+
description: 'gpt-4o - multimodal model for reasoning and vision',
|
|
18
|
+
},
|
|
19
|
+
'openai/gpt-4o-mini': {
|
|
20
|
+
model: 'gpt-4o-mini',
|
|
21
|
+
description: 'gpt-4o-mini - fast and cost-effective multimodal model',
|
|
22
|
+
},
|
|
23
|
+
'openai/gpt-4-turbo': {
|
|
24
|
+
model: 'gpt-4-turbo',
|
|
25
|
+
description: 'gpt-4-turbo - high capability with vision support',
|
|
26
|
+
},
|
|
27
|
+
'openai/o1': {
|
|
28
|
+
model: 'o1',
|
|
29
|
+
description: 'o1 - advanced reasoning model for complex problems',
|
|
30
|
+
},
|
|
31
|
+
'openai/o1-mini': {
|
|
32
|
+
model: 'o1-mini',
|
|
33
|
+
description: 'o1-mini - fast reasoning model for coding and math',
|
|
34
|
+
},
|
|
35
|
+
'openai/o1-preview': {
|
|
36
|
+
model: 'o1-preview',
|
|
37
|
+
description: 'o1-preview - preview of advanced reasoning capabilities',
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* .what = factory to generate openai brain atom instances
|
|
42
|
+
* .why = enables model variant selection via slug
|
|
43
|
+
*
|
|
44
|
+
* .example
|
|
45
|
+
* genBrainAtom({ slug: 'openai/gpt-4o' })
|
|
46
|
+
* genBrainAtom({ slug: 'openai/gpt-4o-mini' }) // fast + cheap
|
|
47
|
+
* genBrainAtom({ slug: 'openai/o1' }) // advanced reasoning
|
|
48
|
+
*/
|
|
49
|
+
const genBrainAtom = (input) => {
|
|
50
|
+
const config = CONFIG_BY_SLUG[input.slug];
|
|
51
|
+
return new BrainAtom_1.BrainAtom({
|
|
52
|
+
repo: 'openai',
|
|
53
|
+
slug: input.slug,
|
|
54
|
+
description: config.description,
|
|
55
|
+
/**
|
|
56
|
+
* .what = stateless inference (no tool use)
|
|
57
|
+
* .why = provides direct model access for reasoning tasks
|
|
58
|
+
*/
|
|
59
|
+
ask: async (askInput, context) => {
|
|
60
|
+
// compose system prompt from briefs
|
|
61
|
+
const systemPrompt = askInput.role.briefs
|
|
62
|
+
? await (0, castBriefsToPrompt_1.castBriefsToPrompt)({ briefs: askInput.role.briefs })
|
|
63
|
+
: undefined;
|
|
64
|
+
// get openai client from context or create new one
|
|
65
|
+
const openai = context?.openai ??
|
|
66
|
+
new openai_1.default({ apiKey: process.env.OPENAI_API_KEY });
|
|
67
|
+
// build messages array
|
|
68
|
+
const messages = [];
|
|
69
|
+
if (systemPrompt) {
|
|
70
|
+
messages.push({ role: 'system', content: systemPrompt });
|
|
71
|
+
}
|
|
72
|
+
messages.push({ role: 'user', content: askInput.prompt });
|
|
73
|
+
// call openai api
|
|
74
|
+
const response = await openai.chat.completions.create({
|
|
75
|
+
model: config.model,
|
|
76
|
+
messages,
|
|
77
|
+
});
|
|
78
|
+
// extract content from response
|
|
79
|
+
const content = response.choices[0]?.message?.content ?? '';
|
|
80
|
+
// parse output via schema
|
|
81
|
+
return askInput.schema.output.parse({ content });
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
exports.genBrainAtom = genBrainAtom;
|
|
86
|
+
//# sourceMappingURL=genBrainAtom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genBrainAtom.js","sourceRoot":"","sources":["../../../../../src/_topublish/rhachet-brain-openai/src/atoms/genBrainAtom.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAM5B,6DAA0D;AAC1D,yFAAsF;AActF;;;GAGG;AACH,MAAM,cAAc,GAGhB;IACF,eAAe,EAAE;QACf,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,oDAAoD;KAClE;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,wDAAwD;KACtE;IACD,oBAAoB,EAAE;QACpB,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,mDAAmD;KACjE;IACD,WAAW,EAAE;QACX,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,oDAAoD;KAClE;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,oDAAoD;KAClE;IACD,mBAAmB,EAAE;QACnB,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,yDAAyD;KACvE;CACF,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAa,EAAE;IACzE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE1C,OAAO,IAAI,qBAAS,CAAC;QACnB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,MAAM,CAAC,WAAW;QAE/B;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,OAAe,EACG,EAAE;YACpB,oCA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BrainRepl';
|
|
3
|
+
/**
|
|
4
|
+
* .what = returns all brain atoms provided by openai
|
|
5
|
+
* .why = enables consumers to register openai atoms with genContextBrain
|
|
6
|
+
*/
|
|
7
|
+
export declare const getBrainAtomsByOpenAI: () => BrainAtom[];
|
|
8
|
+
/**
|
|
9
|
+
* .what = returns all brain repls provided by openai
|
|
10
|
+
* .why = enables consumers to register openai repls with genContextBrain
|
|
11
|
+
*/
|
|
12
|
+
export declare const getBrainReplsByOpenAI: () => BrainRepl[];
|
|
13
|
+
export { genBrainAtom } from './atoms/genBrainAtom';
|
|
14
|
+
export { genBrainRepl } from './repls/genBrainRepl';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genBrainRepl = exports.genBrainAtom = exports.getBrainReplsByOpenAI = exports.getBrainAtomsByOpenAI = void 0;
|
|
4
|
+
const genBrainAtom_1 = require("./atoms/genBrainAtom");
|
|
5
|
+
const genBrainRepl_1 = require("./repls/genBrainRepl");
|
|
6
|
+
/**
|
|
7
|
+
* .what = returns all brain atoms provided by openai
|
|
8
|
+
* .why = enables consumers to register openai atoms with genContextBrain
|
|
9
|
+
*/
|
|
10
|
+
const getBrainAtomsByOpenAI = () => {
|
|
11
|
+
return [(0, genBrainAtom_1.genBrainAtom)({ slug: 'openai/gpt-4o' })];
|
|
12
|
+
};
|
|
13
|
+
exports.getBrainAtomsByOpenAI = getBrainAtomsByOpenAI;
|
|
14
|
+
/**
|
|
15
|
+
* .what = returns all brain repls provided by openai
|
|
16
|
+
* .why = enables consumers to register openai repls with genContextBrain
|
|
17
|
+
*/
|
|
18
|
+
const getBrainReplsByOpenAI = () => {
|
|
19
|
+
return [(0, genBrainRepl_1.genBrainRepl)({ slug: 'openai/codex' })];
|
|
20
|
+
};
|
|
21
|
+
exports.getBrainReplsByOpenAI = getBrainReplsByOpenAI;
|
|
22
|
+
// re-export factories for direct access
|
|
23
|
+
var genBrainAtom_2 = require("./atoms/genBrainAtom");
|
|
24
|
+
Object.defineProperty(exports, "genBrainAtom", { enumerable: true, get: function () { return genBrainAtom_2.genBrainAtom; } });
|
|
25
|
+
var genBrainRepl_2 = require("./repls/genBrainRepl");
|
|
26
|
+
Object.defineProperty(exports, "genBrainRepl", { enumerable: true, get: function () { return genBrainRepl_2.genBrainRepl; } });
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/_topublish/rhachet-brain-openai/src/index.ts"],"names":[],"mappings":";;;AAGA,uDAAoD;AACpD,uDAAoD;AAEpD;;;GAGG;AACI,MAAM,qBAAqB,GAAG,GAAgB,EAAE;IACrD,OAAO,CAAC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC;AAEF;;;GAGG;AACI,MAAM,qBAAqB,GAAG,GAAgB,EAAE;IACrD,OAAO,CAAC,IAAA,2BAAY,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAFW,QAAA,qBAAqB,yBAEhC;AAEF,wCAAwC;AACxC,qDAAoD;AAA3C,4GAAA,YAAY,OAAA;AACrB,qDAAoD;AAA3C,4GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrainRepl } from '../../../../domain.objects/BrainRepl';
|
|
2
|
+
/**
|
|
3
|
+
* .what = supported openai codex repl slugs
|
|
4
|
+
* .why = enables type-safe slug specification with model variants
|
|
5
|
+
*/
|
|
6
|
+
type CodexSlug = 'openai/codex' | 'openai/codex/max' | 'openai/codex/mini' | 'openai/codex/5.2';
|
|
7
|
+
/**
|
|
8
|
+
* .what = factory to generate openai codex brain repl instances
|
|
9
|
+
* .why = enables model variant selection via slug
|
|
10
|
+
*
|
|
11
|
+
* .example
|
|
12
|
+
* genBrainRepl({ slug: 'openai/codex' }) // default model
|
|
13
|
+
* genBrainRepl({ slug: 'openai/codex/mini' }) // fast + cheap
|
|
14
|
+
* genBrainRepl({ slug: 'openai/codex/5.2' }) // most advanced
|
|
15
|
+
*/
|
|
16
|
+
export declare const genBrainRepl: (input: {
|
|
17
|
+
slug: CodexSlug;
|
|
18
|
+
}) => BrainRepl;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genBrainRepl = void 0;
|
|
4
|
+
const codex_sdk_1 = require("@openai/codex-sdk");
|
|
5
|
+
const BrainRepl_1 = require("../../../../domain.objects/BrainRepl");
|
|
6
|
+
const castBriefsToPrompt_1 = require("../../../../domain.operations/briefs/castBriefsToPrompt");
|
|
7
|
+
const castZodToJsonSchema_1 = require("../../../../domain.operations/schema/castZodToJsonSchema");
|
|
8
|
+
/**
|
|
9
|
+
* .what = model configuration by slug
|
|
10
|
+
* .why = maps slugs to API model names and descriptions
|
|
11
|
+
*/
|
|
12
|
+
const CONFIG_BY_SLUG = {
|
|
13
|
+
'openai/codex': {
|
|
14
|
+
model: undefined, // use SDK default (gpt-5.1-codex-max)
|
|
15
|
+
description: 'codex - agentic coding assistant (default model)',
|
|
16
|
+
},
|
|
17
|
+
'openai/codex/max': {
|
|
18
|
+
model: 'gpt-5.1-codex-max',
|
|
19
|
+
description: 'codex max - optimized for long-horizon agentic coding',
|
|
20
|
+
},
|
|
21
|
+
'openai/codex/mini': {
|
|
22
|
+
model: 'gpt-5.1-codex-mini',
|
|
23
|
+
description: 'codex mini - fast and cost-effective',
|
|
24
|
+
},
|
|
25
|
+
'openai/codex/5.2': {
|
|
26
|
+
model: 'gpt-5.2-codex',
|
|
27
|
+
description: 'codex 5.2 - most advanced agentic coding model',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* .what = composes full prompt with optional system context
|
|
32
|
+
* .why = codex-sdk ThreadOptions doesn't have systemPrompt, must prepend to user prompt
|
|
33
|
+
*/
|
|
34
|
+
const composePromptWithSystem = (userPrompt, systemPrompt) => {
|
|
35
|
+
if (!systemPrompt)
|
|
36
|
+
return userPrompt;
|
|
37
|
+
return `${systemPrompt}\n\n---\n\n${userPrompt}`;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* .what = invokes codex sdk with specified sandbox mode
|
|
41
|
+
* .why = dedupes shared logic between ask (read-only) and act (workspace-write)
|
|
42
|
+
*/
|
|
43
|
+
const invokeCodex = async (input) => {
|
|
44
|
+
// compose system prompt from briefs
|
|
45
|
+
const systemPrompt = input.role.briefs
|
|
46
|
+
? await (0, castBriefsToPrompt_1.castBriefsToPrompt)({ briefs: input.role.briefs })
|
|
47
|
+
: undefined;
|
|
48
|
+
// convert zod schema to json schema for native enforcement
|
|
49
|
+
const outputSchema = (0, castZodToJsonSchema_1.castZodToJsonSchema)({
|
|
50
|
+
schema: input.schema.output,
|
|
51
|
+
target: 'openai',
|
|
52
|
+
});
|
|
53
|
+
// create codex client
|
|
54
|
+
const codex = new codex_sdk_1.Codex({
|
|
55
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
56
|
+
});
|
|
57
|
+
// start thread with sandbox mode based on operation type
|
|
58
|
+
const sandboxMode = input.mode === 'ask' ? 'read-only' : 'workspace-write';
|
|
59
|
+
const thread = codex.startThread({
|
|
60
|
+
model: input.model,
|
|
61
|
+
sandboxMode,
|
|
62
|
+
});
|
|
63
|
+
// compose full prompt and run
|
|
64
|
+
const fullPrompt = composePromptWithSystem(input.prompt, systemPrompt);
|
|
65
|
+
const response = await thread.run(fullPrompt, { outputSchema });
|
|
66
|
+
// parse output via schema for runtime validation
|
|
67
|
+
return input.schema.output.parse(JSON.parse(response.finalResponse));
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* .what = factory to generate openai codex brain repl instances
|
|
71
|
+
* .why = enables model variant selection via slug
|
|
72
|
+
*
|
|
73
|
+
* .example
|
|
74
|
+
* genBrainRepl({ slug: 'openai/codex' }) // default model
|
|
75
|
+
* genBrainRepl({ slug: 'openai/codex/mini' }) // fast + cheap
|
|
76
|
+
* genBrainRepl({ slug: 'openai/codex/5.2' }) // most advanced
|
|
77
|
+
*/
|
|
78
|
+
const genBrainRepl = (input) => {
|
|
79
|
+
const config = CONFIG_BY_SLUG[input.slug];
|
|
80
|
+
return new BrainRepl_1.BrainRepl({
|
|
81
|
+
repo: 'openai',
|
|
82
|
+
slug: input.slug,
|
|
83
|
+
description: config.description,
|
|
84
|
+
/**
|
|
85
|
+
* .what = readonly analysis (research, queries, code review)
|
|
86
|
+
* .why = provides safe, non-mutating agent interactions via read-only sandbox
|
|
87
|
+
*/
|
|
88
|
+
ask: async (askInput, _context) => invokeCodex({ mode: 'ask', model: config.model, ...askInput }),
|
|
89
|
+
/**
|
|
90
|
+
* .what = read+write actions (code changes, file edits)
|
|
91
|
+
* .why = provides full agentic capabilities via workspace-write sandbox
|
|
92
|
+
*/
|
|
93
|
+
act: async (actInput, _context) => invokeCodex({ mode: 'act', model: config.model, ...actInput }),
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
exports.genBrainRepl = genBrainRepl;
|
|
97
|
+
//# sourceMappingURL=genBrainRepl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genBrainRepl.js","sourceRoot":"","sources":["../../../../../src/_topublish/rhachet-brain-openai/src/repls/genBrainRepl.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAM1C,6DAA0D;AAC1D,yFAAsF;AACtF,2FAAwF;AAYxF;;;GAGG;AACH,MAAM,cAAc,GAGhB;IACF,cAAc,EAAE;QACd,KAAK,EAAE,SAAS,EAAE,sCAAsC;QACxD,WAAW,EAAE,kDAAkD;KAChE;IACD,kBAAkB,EAAE;QAClB,KAAK,EAAE,mBAAmB;QAC1B,WAA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K,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;IAEhE,iDAAiD;IACjD,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAa,EAAE;IACpE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE1C,OAAO,IAAI,qBAAS,CAAC;QACnB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,MAAM,CAAC,WAAW;QAE/B;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,QAAgB,EACE,EAAE,CACpB,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;QAEhE;;;WAGG;QACH,GAAG,EAAE,KAAK,EACR,QAIC,EACD,QAAgB,EACE,EAAE,CACpB,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;KACjE,CAAC,CAAC;AACL,CAAC,CAAC;AApCW,QAAA,YAAY,gBAoCvB"}
|
package/dist/contract/sdk.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { withImmute } from 'domain-objects';
|
|
2
2
|
export * from '../domain.objects';
|
|
3
|
+
export { castBriefsToPrompt } from '../domain.operations/briefs/castBriefsToPrompt';
|
|
4
|
+
export { genContextBrain } from '../domain.operations/context/genContextBrain';
|
|
3
5
|
export { genContextStitchTrail } from '../domain.operations/context/genContextStitchTrail';
|
|
4
6
|
export { enrollThread } from '../domain.operations/role/enrollThread';
|
|
5
7
|
export { genRoleSkill } from '../domain.operations/role/genRoleSkill';
|