coaiajs 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/CLAUDE.md +56 -0
- package/KINSHIP.md +63 -0
- package/README.md +148 -0
- package/articles/academic/creative-orientation-vs-problem-solving.md +177 -0
- package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +142 -0
- package/articles/academic/langfuse-observability-llm-pipelines.md +144 -0
- package/articles/academic/medicine-wheel-software-architecture.md +163 -0
- package/articles/academic/mmot-autonomous-agents.md +156 -0
- package/articles/academic/model-context-protocol-interagent.md +161 -0
- package/articles/academic/pde-prompt-decomposition.md +186 -0
- package/articles/academic/structural-tension-in-ai-agents.md +134 -0
- package/articles/reviews/mcp-protocol-design-review.md +170 -0
- package/articles/reviews/observability-ai-systems-review.md +176 -0
- package/articles/reviews/prompt-engineering-decomposition-review.md +184 -0
- package/articles/surveys/agent-orchestration-survey.md +186 -0
- package/articles/surveys/knowledge-graph-storage-survey.md +204 -0
- package/articles/surveys/structural-tension-methodology-survey.md +154 -0
- package/articles/technical/aws-sdk-v3-polly.md +270 -0
- package/articles/technical/commander-cli-framework.md +262 -0
- package/articles/technical/dotenv-config-patterns.md +360 -0
- package/articles/technical/ioredis-vs-redis.md +142 -0
- package/articles/technical/langfuse-js-sdk-vs-rest.md +191 -0
- package/articles/technical/mcp-sdk-typescript.md +291 -0
- package/articles/technical/octokit-github-api.md +293 -0
- package/articles/technical/openai-sdk-modern.md +231 -0
- package/articles/technical/yaml-parsing-node.md +266 -0
- package/articles/technical/zod-runtime-validation.md +212 -0
- package/dist/mcp/config.d.ts +14 -0
- package/dist/mcp/config.js +185 -0
- package/dist/mcp/server.d.ts +3 -0
- package/dist/mcp/server.js +324 -0
- package/dist/mcp/tools/coaiapy-tools.d.ts +8 -0
- package/dist/mcp/tools/coaiapy-tools.js +326 -0
- package/dist/mcp/tools/index.d.ts +3 -0
- package/dist/mcp/tools/index.js +3 -0
- package/dist/src/audio.d.ts +12 -0
- package/dist/src/audio.js +57 -0
- package/dist/src/cli-helpers.d.ts +9 -0
- package/dist/src/cli-helpers.js +78 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +1086 -0
- package/dist/src/config.d.ts +15 -0
- package/dist/src/config.js +145 -0
- package/dist/src/environment.d.ts +44 -0
- package/dist/src/environment.js +146 -0
- package/dist/src/github.d.ts +47 -0
- package/dist/src/github.js +79 -0
- package/dist/src/langfuse/client.d.ts +30 -0
- package/dist/src/langfuse/client.js +75 -0
- package/dist/src/langfuse/comments.d.ts +16 -0
- package/dist/src/langfuse/comments.js +36 -0
- package/dist/src/langfuse/datasets.d.ts +19 -0
- package/dist/src/langfuse/datasets.js +140 -0
- package/dist/src/langfuse/index.d.ts +13 -0
- package/dist/src/langfuse/index.js +10 -0
- package/dist/src/langfuse/media.d.ts +11 -0
- package/dist/src/langfuse/media.js +167 -0
- package/dist/src/langfuse/observations.d.ts +18 -0
- package/dist/src/langfuse/observations.js +113 -0
- package/dist/src/langfuse/prompts.d.ts +14 -0
- package/dist/src/langfuse/prompts.js +127 -0
- package/dist/src/langfuse/scores.d.ts +54 -0
- package/dist/src/langfuse/scores.js +366 -0
- package/dist/src/langfuse/traces.d.ts +29 -0
- package/dist/src/langfuse/traces.js +225 -0
- package/dist/src/llm.d.ts +23 -0
- package/dist/src/llm.js +76 -0
- package/dist/src/narrative/graph-manager.d.ts +106 -0
- package/dist/src/narrative/graph-manager.js +915 -0
- package/dist/src/narrative/index.d.ts +9 -0
- package/dist/src/narrative/index.js +7 -0
- package/dist/src/narrative/markdown-export.d.ts +21 -0
- package/dist/src/narrative/markdown-export.js +383 -0
- package/dist/src/narrative/tool-definitions.d.ts +21 -0
- package/dist/src/narrative/tool-definitions.js +588 -0
- package/dist/src/narrative/tool-handlers.d.ts +11 -0
- package/dist/src/narrative/tool-handlers.js +462 -0
- package/dist/src/narrative/types.d.ts +2 -0
- package/dist/src/narrative/types.js +2 -0
- package/dist/src/narrative/validation.d.ts +29 -0
- package/dist/src/narrative/validation.js +144 -0
- package/dist/src/pde/index.d.ts +8 -0
- package/dist/src/pde/index.js +8 -0
- package/dist/src/pde/mcp-handlers.d.ts +7 -0
- package/dist/src/pde/mcp-handlers.js +300 -0
- package/dist/src/pde/mcp-tools.d.ts +15 -0
- package/dist/src/pde/mcp-tools.js +191 -0
- package/dist/src/pde/session-manager.d.ts +32 -0
- package/dist/src/pde/session-manager.js +205 -0
- package/dist/src/pde/stc-mapper.d.ts +26 -0
- package/dist/src/pde/stc-mapper.js +234 -0
- package/dist/src/pipeline/index.d.ts +2 -0
- package/dist/src/pipeline/index.js +3 -0
- package/dist/src/pipeline/template-engine.d.ts +20 -0
- package/dist/src/pipeline/template-engine.js +361 -0
- package/dist/src/planning/index.d.ts +7 -0
- package/dist/src/planning/index.js +7 -0
- package/dist/src/planning/mcp-handlers.d.ts +7 -0
- package/dist/src/planning/mcp-handlers.js +310 -0
- package/dist/src/planning/mcp-tools.d.ts +15 -0
- package/dist/src/planning/mcp-tools.js +145 -0
- package/dist/src/planning/plan-parser.d.ts +35 -0
- package/dist/src/planning/plan-parser.js +506 -0
- package/dist/src/redis.d.ts +21 -0
- package/dist/src/redis.js +78 -0
- package/dist/src/types.d.ts +244 -0
- package/dist/src/types.js +8 -0
- package/mcp/config.ts +196 -0
- package/mcp/server.ts +402 -0
- package/mcp/tools/coaiapy-tools.ts +364 -0
- package/mcp/tools/index.ts +4 -0
- package/package.json +52 -0
- package/rispecs/00-coaiajs-platform.spec.md +102 -0
- package/rispecs/01-core-config.spec.md +89 -0
- package/rispecs/02-redis-module.spec.md +62 -0
- package/rispecs/03-langfuse-module.spec.md +101 -0
- package/rispecs/04-narrative-engine.spec.md +185 -0
- package/rispecs/05-pde-engine.spec.md +112 -0
- package/rispecs/06-planning-engine.spec.md +128 -0
- package/rispecs/07-pipeline-templates.spec.md +97 -0
- package/rispecs/08-cli-interface.spec.md +134 -0
- package/rispecs/09-mcp-server.spec.md +140 -0
- package/rispecs/10-audio-module.spec.md +63 -0
- package/rispecs/KINSHIP.md +56 -0
- package/rispecs/README.md +100 -0
- package/src/audio.ts +76 -0
- package/src/cli-helpers.ts +86 -0
- package/src/cli.ts +1223 -0
- package/src/config.ts +172 -0
- package/src/environment.ts +171 -0
- package/src/github.ts +143 -0
- package/src/langfuse/client.ts +105 -0
- package/src/langfuse/comments.ts +52 -0
- package/src/langfuse/datasets.ts +178 -0
- package/src/langfuse/index.ts +33 -0
- package/src/langfuse/media.ts +193 -0
- package/src/langfuse/observations.ts +131 -0
- package/src/langfuse/prompts.ts +157 -0
- package/src/langfuse/scores.ts +456 -0
- package/src/langfuse/traces.ts +276 -0
- package/src/llm.ts +106 -0
- package/src/narrative/graph-manager.ts +1358 -0
- package/src/narrative/index.ts +32 -0
- package/src/narrative/markdown-export.ts +535 -0
- package/src/narrative/tool-definitions.ts +635 -0
- package/src/narrative/tool-handlers.ts +528 -0
- package/src/narrative/types.ts +9 -0
- package/src/narrative/validation.ts +179 -0
- package/src/pde/index.ts +8 -0
- package/src/pde/mcp-handlers.ts +359 -0
- package/src/pde/mcp-tools.ts +201 -0
- package/src/pde/session-manager.ts +248 -0
- package/src/pde/stc-mapper.ts +298 -0
- package/src/pipeline/index.ts +7 -0
- package/src/pipeline/template-engine.ts +398 -0
- package/src/planning/index.ts +13 -0
- package/src/planning/mcp-handlers.ts +369 -0
- package/src/planning/mcp-tools.ts +155 -0
- package/src/planning/plan-parser.ts +587 -0
- package/src/redis.ts +97 -0
- package/src/types.ts +280 -0
- package/tsconfig.json +26 -0
package/dist/src/llm.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// coaiajs/src/llm.ts — LLM module
|
|
2
|
+
// Parity with coaiapy's OpenAI functions
|
|
3
|
+
import OpenAI from 'openai';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { getConfig } from './config.js';
|
|
6
|
+
let _client = null;
|
|
7
|
+
function getClient() {
|
|
8
|
+
if (!_client) {
|
|
9
|
+
const cfg = getConfig();
|
|
10
|
+
_client = new OpenAI({
|
|
11
|
+
apiKey: cfg.openai?.apiKey ?? process.env['OPENAI_API_KEY'],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return _client;
|
|
15
|
+
}
|
|
16
|
+
/** Reset client (testing). */
|
|
17
|
+
export function resetClient() {
|
|
18
|
+
_client = null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Send a chat completion request.
|
|
22
|
+
* Minimal wrapper matching coaiapy's `llm()` function.
|
|
23
|
+
*/
|
|
24
|
+
export async function llm(user, system, temperature) {
|
|
25
|
+
const client = getClient();
|
|
26
|
+
const cfg = getConfig();
|
|
27
|
+
const model = cfg.openai?.model ?? 'gpt-4o';
|
|
28
|
+
const messages = [];
|
|
29
|
+
if (system) {
|
|
30
|
+
messages.push({ role: 'system', content: system });
|
|
31
|
+
}
|
|
32
|
+
messages.push({ role: 'user', content: user });
|
|
33
|
+
const response = await client.chat.completions.create({
|
|
34
|
+
model,
|
|
35
|
+
messages,
|
|
36
|
+
temperature: temperature ?? 0.7,
|
|
37
|
+
});
|
|
38
|
+
return response.choices[0]?.message?.content ?? '';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Transcribe audio using Whisper API.
|
|
42
|
+
* Parity with coaiapy's transcription functions.
|
|
43
|
+
*/
|
|
44
|
+
export async function transcribeAudio(filePath) {
|
|
45
|
+
const client = getClient();
|
|
46
|
+
const file = new File([readFileSync(filePath)], filePath.split('/').pop() ?? 'audio.wav', { type: 'audio/wav' });
|
|
47
|
+
const response = await client.audio.transcriptions.create({
|
|
48
|
+
model: 'whisper-1',
|
|
49
|
+
file,
|
|
50
|
+
});
|
|
51
|
+
return response.text;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Generate an image using DALL-E.
|
|
55
|
+
* Returns the URL of the generated image.
|
|
56
|
+
*/
|
|
57
|
+
export async function generateImage(prompt, size) {
|
|
58
|
+
const client = getClient();
|
|
59
|
+
const validSize = (size ?? '1024x1024');
|
|
60
|
+
const response = await client.images.generate({
|
|
61
|
+
model: 'dall-e-3',
|
|
62
|
+
prompt,
|
|
63
|
+
n: 1,
|
|
64
|
+
size: validSize,
|
|
65
|
+
});
|
|
66
|
+
return response.data?.[0]?.url ?? '';
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Abstract process: config-driven LLM call with a named process.
|
|
70
|
+
* Looks up system prompt by processName in config or uses a default.
|
|
71
|
+
*/
|
|
72
|
+
export async function abstractProcess(processName, input) {
|
|
73
|
+
const systemPrompt = `You are executing the "${processName}" process. Follow the process instructions precisely and produce the expected output format.`;
|
|
74
|
+
return llm(input, systemPrompt);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=llm.js.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KnowledgeGraphManager — JSONL-backed knowledge graph engine
|
|
3
|
+
*
|
|
4
|
+
* Ported from coaia-narrative/src/graph-manager.ts (1294 lines).
|
|
5
|
+
* Implements structural tension charts, narrative beats, MMOT evaluation,
|
|
6
|
+
* and general-purpose entity/relation CRUD over a JSONL file.
|
|
7
|
+
*/
|
|
8
|
+
import type { Entity, Relation, KnowledgeGraph } from '../types.js';
|
|
9
|
+
export declare class KnowledgeGraphManager {
|
|
10
|
+
private memoryFilePath;
|
|
11
|
+
constructor(memoryFilePath: string);
|
|
12
|
+
private loadGraph;
|
|
13
|
+
private saveGraph;
|
|
14
|
+
createEntities(entities: Entity[]): Promise<Entity[]>;
|
|
15
|
+
createRelations(relations: Relation[]): Promise<Relation[]>;
|
|
16
|
+
addObservations(observations: {
|
|
17
|
+
entityName: string;
|
|
18
|
+
contents: string[];
|
|
19
|
+
}[]): Promise<{
|
|
20
|
+
entityName: string;
|
|
21
|
+
addedObservations: string[];
|
|
22
|
+
}[]>;
|
|
23
|
+
deleteEntities(entityNames: string[]): Promise<void>;
|
|
24
|
+
deleteObservations(deletions: {
|
|
25
|
+
entityName: string;
|
|
26
|
+
observations: string[];
|
|
27
|
+
}[]): Promise<void>;
|
|
28
|
+
deleteRelations(relations: Relation[]): Promise<void>;
|
|
29
|
+
readGraph(): Promise<KnowledgeGraph>;
|
|
30
|
+
searchNodes(query: string): Promise<KnowledgeGraph>;
|
|
31
|
+
openNodes(names: string[]): Promise<KnowledgeGraph>;
|
|
32
|
+
getChartDetails(chartId: string): Promise<KnowledgeGraph | null>;
|
|
33
|
+
getActionStepDetails(actionStepName: string): Promise<KnowledgeGraph | null>;
|
|
34
|
+
createStructuralTensionChart(desiredOutcome: string, currentReality: string, dueDate: string, actionSteps?: string[], elementsOfPerformance?: Array<{
|
|
35
|
+
description: string;
|
|
36
|
+
type: 'DESIGN' | 'EXECUTION';
|
|
37
|
+
}>): Promise<{
|
|
38
|
+
chartId: string;
|
|
39
|
+
entities: Entity[];
|
|
40
|
+
relations: Relation[];
|
|
41
|
+
}>;
|
|
42
|
+
telescopeActionStep(actionStepName: string, newCurrentReality: string, initialActionSteps?: string[]): Promise<{
|
|
43
|
+
chartId: string;
|
|
44
|
+
parentChart: string;
|
|
45
|
+
}>;
|
|
46
|
+
markActionStepComplete(actionStepName: string): Promise<void>;
|
|
47
|
+
getChartProgress(chartId: string, preloadedGraph?: KnowledgeGraph): Promise<{
|
|
48
|
+
chartId: string;
|
|
49
|
+
progress: number;
|
|
50
|
+
completedActions: number;
|
|
51
|
+
totalActions: number;
|
|
52
|
+
nextAction?: string;
|
|
53
|
+
dueDate?: string;
|
|
54
|
+
}>;
|
|
55
|
+
listActiveCharts(): Promise<Array<{
|
|
56
|
+
chartId: string;
|
|
57
|
+
desiredOutcome: string;
|
|
58
|
+
dueDate?: string;
|
|
59
|
+
progress: number;
|
|
60
|
+
completedActions: number;
|
|
61
|
+
totalActions: number;
|
|
62
|
+
level: number;
|
|
63
|
+
parentChart?: string;
|
|
64
|
+
}>>;
|
|
65
|
+
updateActionProgress(actionStepName: string, progressObservation: string, updateCurrentReality?: boolean): Promise<void>;
|
|
66
|
+
updateCurrentReality(chartId: string, newObservations: string[]): Promise<void>;
|
|
67
|
+
updateDesiredOutcome(chartId: string, newDesiredOutcome: string): Promise<void>;
|
|
68
|
+
performMmotEvaluation(chartId: string, phase?: string, assessment?: string, direction?: 'South' | 'East' | 'West' | 'North', correctiveActions?: string[], updateReality?: boolean): Promise<{
|
|
69
|
+
guidance: string;
|
|
70
|
+
evaluationStored: boolean;
|
|
71
|
+
beatEmitted: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
createNarrativeBeat(parentChartId: string, title: string, act: number, type_dramatic: string, universes: string[], description: string, prose: string, lessons: string[], assessRelationalAlignment?: boolean, initiateFourDirectionsInquiry?: boolean, _filePath?: string): Promise<{
|
|
74
|
+
entity: Entity;
|
|
75
|
+
beatName: string;
|
|
76
|
+
}>;
|
|
77
|
+
telescopeNarrativeBeat(parentBeatName: string, newCurrentReality: string, initialSubBeats?: Array<{
|
|
78
|
+
title: string;
|
|
79
|
+
type_dramatic: string;
|
|
80
|
+
description: string;
|
|
81
|
+
prose: string;
|
|
82
|
+
lessons: string[];
|
|
83
|
+
}>): Promise<{
|
|
84
|
+
parentBeat: Entity;
|
|
85
|
+
subBeats: Entity[];
|
|
86
|
+
}>;
|
|
87
|
+
listNarrativeBeats(parentChartId?: string): Promise<Entity[]>;
|
|
88
|
+
addActionStep(parentChartId: string, actionStepTitle: string, dueDate?: string, currentReality?: string, performanceElements?: Array<{
|
|
89
|
+
description: string;
|
|
90
|
+
type: 'DESIGN' | 'EXECUTION';
|
|
91
|
+
}>): Promise<{
|
|
92
|
+
chartId: string;
|
|
93
|
+
actionStepName: string;
|
|
94
|
+
}>;
|
|
95
|
+
manageActionStep(parentReference: string, actionDescription: string, currentReality?: string, initialActionSteps?: string[], dueDate?: string, performanceElements?: Array<{
|
|
96
|
+
description: string;
|
|
97
|
+
type: 'DESIGN' | 'EXECUTION';
|
|
98
|
+
}>): Promise<{
|
|
99
|
+
chartId: string;
|
|
100
|
+
actionStepName: string;
|
|
101
|
+
}>;
|
|
102
|
+
removeActionStep(parentChartId: string, actionStepName: string): Promise<void>;
|
|
103
|
+
private extractCurrentRealityFromContext;
|
|
104
|
+
private distributeActionStepDates;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=graph-manager.d.ts.map
|