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
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
// coaiajs/mcp/tools/coaiapy-tools.ts — Tool definitions for coaiapy-equivalent tools
|
|
2
|
+
// Port of coaiapy-mcp/server.py tool schemas (20 tools)
|
|
3
|
+
|
|
4
|
+
import type { FeatureConfig } from '../config.js';
|
|
5
|
+
|
|
6
|
+
export interface ToolDefinition {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
inputSchema: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getCoaiapyToolDefinitions(featureConfig: FeatureConfig): ToolDefinition[] {
|
|
13
|
+
const tools: ToolDefinition[] = [];
|
|
14
|
+
|
|
15
|
+
// ─── Redis Tools ────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
if (featureConfig.isToolEnabled('coaia_tash')) {
|
|
18
|
+
tools.push({
|
|
19
|
+
name: 'coaia_tash',
|
|
20
|
+
description: 'Stash key-value pair to Redis',
|
|
21
|
+
inputSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
key: { type: 'string', description: 'Redis key' },
|
|
25
|
+
value: { type: 'string', description: 'Value to store' },
|
|
26
|
+
},
|
|
27
|
+
required: ['key', 'value'],
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (featureConfig.isToolEnabled('coaia_fetch')) {
|
|
33
|
+
tools.push({
|
|
34
|
+
name: 'coaia_fetch',
|
|
35
|
+
description: 'Fetch value from Redis by key',
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
key: { type: 'string', description: 'Redis key to fetch' },
|
|
40
|
+
},
|
|
41
|
+
required: ['key'],
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ─── Trace Tools ────────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
if (featureConfig.isToolEnabled('coaia_fuse_trace_create')) {
|
|
49
|
+
tools.push({
|
|
50
|
+
name: 'coaia_fuse_trace_create',
|
|
51
|
+
description: 'Create a Langfuse trace for observability tracking',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
trace_id: { type: 'string', description: 'Unique trace identifier' },
|
|
56
|
+
user_id: { type: 'string', description: 'User identifier' },
|
|
57
|
+
session_id: { type: 'string', description: 'Session identifier' },
|
|
58
|
+
name: { type: 'string', description: 'Trace name' },
|
|
59
|
+
metadata: { type: 'object', description: 'Metadata dictionary' },
|
|
60
|
+
input_data: { description: 'Input data' },
|
|
61
|
+
output_data: { description: 'Output data' },
|
|
62
|
+
},
|
|
63
|
+
required: ['trace_id'],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (featureConfig.isToolEnabled('coaia_fuse_add_observation')) {
|
|
69
|
+
tools.push({
|
|
70
|
+
name: 'coaia_fuse_add_observation',
|
|
71
|
+
description: 'Add an observation (event, span, or generation) to a trace',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
observation_id: { type: 'string', description: 'Unique observation identifier' },
|
|
76
|
+
trace_id: { type: 'string', description: 'Parent trace ID' },
|
|
77
|
+
name: { type: 'string', description: 'Observation name' },
|
|
78
|
+
observation_type: { type: 'string', enum: ['SPAN', 'EVENT', 'GENERATION'], description: 'Observation type' },
|
|
79
|
+
parent_id: { type: 'string', description: 'Parent observation ID for nesting' },
|
|
80
|
+
metadata: { type: 'object', description: 'Metadata' },
|
|
81
|
+
input_data: { description: 'Input data' },
|
|
82
|
+
output_data: { description: 'Output data' },
|
|
83
|
+
start_time: { type: 'string', description: 'Start timestamp (ISO 8601)' },
|
|
84
|
+
end_time: { type: 'string', description: 'End timestamp (ISO 8601)' },
|
|
85
|
+
},
|
|
86
|
+
required: ['observation_id', 'trace_id', 'name'],
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (featureConfig.isToolEnabled('coaia_fuse_trace_patch_output')) {
|
|
92
|
+
tools.push({
|
|
93
|
+
name: 'coaia_fuse_trace_patch_output',
|
|
94
|
+
description: 'Update the output field of an existing trace',
|
|
95
|
+
inputSchema: {
|
|
96
|
+
type: 'object',
|
|
97
|
+
properties: {
|
|
98
|
+
trace_id: { type: 'string', description: 'Trace ID to update' },
|
|
99
|
+
output_data: { description: 'New output data' },
|
|
100
|
+
},
|
|
101
|
+
required: ['trace_id', 'output_data'],
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (featureConfig.isToolEnabled('coaia_fuse_trace_get')) {
|
|
107
|
+
tools.push({
|
|
108
|
+
name: 'coaia_fuse_trace_get',
|
|
109
|
+
description: 'Get a specific trace by ID with all its observations',
|
|
110
|
+
inputSchema: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
trace_id: { type: 'string', description: 'Trace ID to fetch' },
|
|
114
|
+
json_output: { type: 'boolean', description: 'Return raw JSON instead of formatted tree' },
|
|
115
|
+
},
|
|
116
|
+
required: ['trace_id'],
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (featureConfig.isToolEnabled('coaia_fuse_trace_view')) {
|
|
122
|
+
tools.push({
|
|
123
|
+
name: 'coaia_fuse_trace_view',
|
|
124
|
+
description: 'View trace details with observations (alias for trace_get)',
|
|
125
|
+
inputSchema: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
properties: {
|
|
128
|
+
trace_id: { type: 'string', description: 'Trace ID' },
|
|
129
|
+
json_output: { type: 'boolean', description: 'Return raw JSON' },
|
|
130
|
+
},
|
|
131
|
+
required: ['trace_id'],
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (featureConfig.isToolEnabled('coaia_fuse_observation_get')) {
|
|
137
|
+
tools.push({
|
|
138
|
+
name: 'coaia_fuse_observation_get',
|
|
139
|
+
description: 'Get a specific observation by ID',
|
|
140
|
+
inputSchema: {
|
|
141
|
+
type: 'object',
|
|
142
|
+
properties: {
|
|
143
|
+
observation_id: { type: 'string', description: 'Observation ID' },
|
|
144
|
+
json_output: { type: 'boolean', description: 'Return raw JSON' },
|
|
145
|
+
},
|
|
146
|
+
required: ['observation_id'],
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (featureConfig.isToolEnabled('coaia_fuse_traces_list')) {
|
|
152
|
+
tools.push({
|
|
153
|
+
name: 'coaia_fuse_traces_list',
|
|
154
|
+
description: 'List traces with optional filtering by session, user, name, tags, and time range',
|
|
155
|
+
inputSchema: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
properties: {
|
|
158
|
+
session_id: { type: 'string', description: 'Filter by session ID' },
|
|
159
|
+
user_id: { type: 'string', description: 'Filter by user ID' },
|
|
160
|
+
name: { type: 'string', description: 'Filter by trace name' },
|
|
161
|
+
tags: { type: 'array', items: { type: 'string' }, description: 'Filter by tags' },
|
|
162
|
+
from_timestamp: { type: 'string', description: 'Filter from timestamp (ISO 8601)' },
|
|
163
|
+
to_timestamp: { type: 'string', description: 'Filter to timestamp (ISO 8601)' },
|
|
164
|
+
order_by: { type: 'string', description: 'Sort order' },
|
|
165
|
+
page: { type: 'integer', description: 'Page number', default: 1 },
|
|
166
|
+
limit: { type: 'integer', description: 'Items per page', default: 50 },
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (featureConfig.isToolEnabled('coaia_fuse_traces_session_view')) {
|
|
173
|
+
tools.push({
|
|
174
|
+
name: 'coaia_fuse_traces_session_view',
|
|
175
|
+
description: 'View all traces for a specific session',
|
|
176
|
+
inputSchema: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
session_id: { type: 'string', description: 'Session ID to view traces for' },
|
|
180
|
+
json_output: { type: 'boolean', description: 'Return raw JSON' },
|
|
181
|
+
},
|
|
182
|
+
required: ['session_id'],
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ─── Prompts Tools ──────────────────────────────────────────────
|
|
188
|
+
|
|
189
|
+
if (featureConfig.isToolEnabled('coaia_fuse_prompts_list')) {
|
|
190
|
+
tools.push({
|
|
191
|
+
name: 'coaia_fuse_prompts_list',
|
|
192
|
+
description: 'List all Langfuse prompts',
|
|
193
|
+
inputSchema: { type: 'object', properties: {} },
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (featureConfig.isToolEnabled('coaia_fuse_prompts_get')) {
|
|
198
|
+
tools.push({
|
|
199
|
+
name: 'coaia_fuse_prompts_get',
|
|
200
|
+
description: 'Get a specific Langfuse prompt by name',
|
|
201
|
+
inputSchema: {
|
|
202
|
+
type: 'object',
|
|
203
|
+
properties: {
|
|
204
|
+
name: { type: 'string', description: 'Prompt name' },
|
|
205
|
+
label: { type: 'string', description: 'Optional deployment label' },
|
|
206
|
+
},
|
|
207
|
+
required: ['name'],
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ─── Dataset Tools ──────────────────────────────────────────────
|
|
213
|
+
|
|
214
|
+
if (featureConfig.isToolEnabled('coaia_fuse_datasets_list')) {
|
|
215
|
+
tools.push({
|
|
216
|
+
name: 'coaia_fuse_datasets_list',
|
|
217
|
+
description: 'List all Langfuse datasets',
|
|
218
|
+
inputSchema: { type: 'object', properties: {} },
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (featureConfig.isToolEnabled('coaia_fuse_datasets_get')) {
|
|
223
|
+
tools.push({
|
|
224
|
+
name: 'coaia_fuse_datasets_get',
|
|
225
|
+
description: 'Get a specific dataset by name with its items',
|
|
226
|
+
inputSchema: {
|
|
227
|
+
type: 'object',
|
|
228
|
+
properties: {
|
|
229
|
+
name: { type: 'string', description: 'Dataset name' },
|
|
230
|
+
},
|
|
231
|
+
required: ['name'],
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ─── Score Config Tools ─────────────────────────────────────────
|
|
237
|
+
|
|
238
|
+
if (featureConfig.isToolEnabled('coaia_fuse_score_configs_list')) {
|
|
239
|
+
tools.push({
|
|
240
|
+
name: 'coaia_fuse_score_configs_list',
|
|
241
|
+
description: 'List all Langfuse score configurations',
|
|
242
|
+
inputSchema: { type: 'object', properties: {} },
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (featureConfig.isToolEnabled('coaia_fuse_score_configs_get')) {
|
|
247
|
+
tools.push({
|
|
248
|
+
name: 'coaia_fuse_score_configs_get',
|
|
249
|
+
description: 'Get specific Langfuse score configuration',
|
|
250
|
+
inputSchema: {
|
|
251
|
+
type: 'object',
|
|
252
|
+
properties: {
|
|
253
|
+
name_or_id: { type: 'string', description: 'Score config name or ID' },
|
|
254
|
+
},
|
|
255
|
+
required: ['name_or_id'],
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (featureConfig.isToolEnabled('coaia_fuse_score_apply')) {
|
|
261
|
+
tools.push({
|
|
262
|
+
name: 'coaia_fuse_score_apply',
|
|
263
|
+
description: 'Apply a score configuration to a trace or observation with validation',
|
|
264
|
+
inputSchema: {
|
|
265
|
+
type: 'object',
|
|
266
|
+
properties: {
|
|
267
|
+
config_name_or_id: { type: 'string', description: 'Name or ID of the score configuration' },
|
|
268
|
+
target_type: { type: 'string', enum: ['trace', 'session'], description: 'Target type' },
|
|
269
|
+
target_id: { type: 'string', description: 'ID of the trace or session' },
|
|
270
|
+
value: { description: 'Score value (validated against config)' },
|
|
271
|
+
observation_id: { type: 'string', description: 'Optional observation ID' },
|
|
272
|
+
comment: { type: 'string', description: 'Optional comment' },
|
|
273
|
+
},
|
|
274
|
+
required: ['config_name_or_id', 'target_type', 'target_id', 'value'],
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ─── Comment Tools ──────────────────────────────────────────────
|
|
280
|
+
|
|
281
|
+
if (featureConfig.isToolEnabled('coaia_fuse_comments_list')) {
|
|
282
|
+
tools.push({
|
|
283
|
+
name: 'coaia_fuse_comments_list',
|
|
284
|
+
description: 'List comments with optional filtering by object type/ID or author',
|
|
285
|
+
inputSchema: {
|
|
286
|
+
type: 'object',
|
|
287
|
+
properties: {
|
|
288
|
+
object_type: { type: 'string', description: 'Filter by object type (trace, observation, session, prompt)' },
|
|
289
|
+
object_id: { type: 'string', description: 'Filter by specific object ID' },
|
|
290
|
+
author_user_id: { type: 'string', description: 'Filter by author user ID' },
|
|
291
|
+
page: { type: 'integer', description: 'Page number', default: 1 },
|
|
292
|
+
limit: { type: 'integer', description: 'Items per page', default: 50 },
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (featureConfig.isToolEnabled('coaia_fuse_comments_get')) {
|
|
299
|
+
tools.push({
|
|
300
|
+
name: 'coaia_fuse_comments_get',
|
|
301
|
+
description: 'Get a specific comment by ID',
|
|
302
|
+
inputSchema: {
|
|
303
|
+
type: 'object',
|
|
304
|
+
properties: {
|
|
305
|
+
comment_id: { type: 'string', description: 'Comment ID' },
|
|
306
|
+
},
|
|
307
|
+
required: ['comment_id'],
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (featureConfig.isToolEnabled('coaia_fuse_comments_create')) {
|
|
313
|
+
tools.push({
|
|
314
|
+
name: 'coaia_fuse_comments_create',
|
|
315
|
+
description: 'Create a comment attached to an object (trace, observation, session, or prompt)',
|
|
316
|
+
inputSchema: {
|
|
317
|
+
type: 'object',
|
|
318
|
+
properties: {
|
|
319
|
+
text: { type: 'string', description: 'Comment text' },
|
|
320
|
+
object_type: { type: 'string', description: 'Object type (trace, observation, session, prompt)' },
|
|
321
|
+
object_id: { type: 'string', description: 'Object ID' },
|
|
322
|
+
author_user_id: { type: 'string', description: 'Author user ID' },
|
|
323
|
+
},
|
|
324
|
+
required: ['text', 'object_type', 'object_id'],
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ─── Media Tools (FULL only) ────────────────────────────────────
|
|
330
|
+
|
|
331
|
+
if (featureConfig.isToolEnabled('coaia_fuse_media_upload')) {
|
|
332
|
+
tools.push({
|
|
333
|
+
name: 'coaia_fuse_media_upload',
|
|
334
|
+
description: 'Upload a file and attach it to a Langfuse trace or observation. Supports images, video, audio, documents. Auto-detects MIME type.',
|
|
335
|
+
inputSchema: {
|
|
336
|
+
type: 'object',
|
|
337
|
+
properties: {
|
|
338
|
+
file_path: { type: 'string', description: 'Absolute path to the file to upload' },
|
|
339
|
+
trace_id: { type: 'string', description: 'Trace ID to attach media to' },
|
|
340
|
+
field: { type: 'string', enum: ['input', 'output', 'metadata'], description: 'Field to attach to', default: 'input' },
|
|
341
|
+
observation_id: { type: 'string', description: 'Optional observation ID' },
|
|
342
|
+
content_type: { type: 'string', description: 'MIME type override (auto-detected if omitted)' },
|
|
343
|
+
},
|
|
344
|
+
required: ['file_path', 'trace_id'],
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (featureConfig.isToolEnabled('coaia_fuse_media_get')) {
|
|
350
|
+
tools.push({
|
|
351
|
+
name: 'coaia_fuse_media_get',
|
|
352
|
+
description: 'Get media metadata by media ID',
|
|
353
|
+
inputSchema: {
|
|
354
|
+
type: 'object',
|
|
355
|
+
properties: {
|
|
356
|
+
media_id: { type: 'string', description: 'Media ID' },
|
|
357
|
+
},
|
|
358
|
+
required: ['media_id'],
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return tools;
|
|
364
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "coaiajs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "CoAIA unified TypeScript monorepo — CLI, MCP server, and library consolidating coaia-narrative, coaia-pde, coaia-planning, and coaiapy patterns into one package.",
|
|
6
|
+
"bin": {
|
|
7
|
+
"coaia": "./dist/src/cli.js",
|
|
8
|
+
"coaiajs-mcp": "./dist/mcp/server.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20.0.0"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc --watch",
|
|
16
|
+
"start": "node dist/src/cli.js",
|
|
17
|
+
"mcp": "node dist/mcp/server.js",
|
|
18
|
+
"test": "node --test",
|
|
19
|
+
"lint": "tsc --noEmit"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.25.0",
|
|
23
|
+
"ioredis": "^5.4.0",
|
|
24
|
+
"zod": "^3.23.0",
|
|
25
|
+
"commander": "^12.1.0",
|
|
26
|
+
"openai": "^4.70.0",
|
|
27
|
+
"@aws-sdk/client-polly": "^3.700.0",
|
|
28
|
+
"@octokit/rest": "^21.0.0",
|
|
29
|
+
"dotenv": "^16.4.0",
|
|
30
|
+
"js-yaml": "^4.1.0",
|
|
31
|
+
"langfuse": "^3.0.0",
|
|
32
|
+
"minimist": "^1.2.8",
|
|
33
|
+
"chalk": "^5.3.0",
|
|
34
|
+
"uuid": "^11.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.0.0",
|
|
38
|
+
"@types/js-yaml": "^4.0.9",
|
|
39
|
+
"@types/minimist": "^1.2.5",
|
|
40
|
+
"@types/uuid": "^10.0.0",
|
|
41
|
+
"typescript": "^5.7.0"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"coaia",
|
|
45
|
+
"structural-tension",
|
|
46
|
+
"mcp",
|
|
47
|
+
"narrative",
|
|
48
|
+
"pde",
|
|
49
|
+
"cli"
|
|
50
|
+
],
|
|
51
|
+
"license": "MIT"
|
|
52
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# 00 — CoAiA.js Platform
|
|
2
|
+
|
|
3
|
+
> Master specification for the unified TypeScript platform.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A unified TypeScript platform that consolidates coaiapy, coaia-narrative, coaia-pde, and coaia-planning into a single modern Node.js package with full CLI and MCP server parity.
|
|
8
|
+
|
|
9
|
+
Single `npm install coaiajs` provides:
|
|
10
|
+
- Unified CLI (`coaia`) with all commands
|
|
11
|
+
- Unified MCP server (`coaiajs-mcp`) with 64+ tools
|
|
12
|
+
- Shared type system and JSONL storage engine
|
|
13
|
+
- Modern Node.js 20+ (no Python 3.6 constraints)
|
|
14
|
+
|
|
15
|
+
## Structural Tension
|
|
16
|
+
|
|
17
|
+
**Current Reality:**
|
|
18
|
+
- Four separate repositories with overlapping type systems, duplicated JSONL logic, and fragmented MCP servers:
|
|
19
|
+
- coaiapy v0.4.5 (Python, ~28,700 LOC, 68 files) — config, Redis, Langfuse, pipeline, audio, GitHub, LLM
|
|
20
|
+
- coaia-narrative v0.12.0 (TypeScript, ~2,500 LOC) — JSONL graph, STC, narrative beats, MMOT, 27 MCP tools
|
|
21
|
+
- coaia-pde v0.1.1 (TypeScript, ~1,600 LOC) — PDE→STC transformation, 12 MCP tools
|
|
22
|
+
- coaia-planning v0.1.0 (TypeScript, ~1,400 LOC) — plan parsing, plan↔STC sync, 5 MCP tools
|
|
23
|
+
- coaiajs v0.1.0 exists with core modules implemented (config, redis, github, llm, audio, environment — ~1,042 LOC) and types unified (280 lines)
|
|
24
|
+
- Five sub-module directories (narrative, pde, planning, langfuse, pipeline) are empty stubs
|
|
25
|
+
- MCP server directory is scaffolded but empty
|
|
26
|
+
- CLI is referenced in package.json but has no implementation
|
|
27
|
+
- No tests exist
|
|
28
|
+
|
|
29
|
+
**Desired Outcome:**
|
|
30
|
+
Single `coaiajs` npm package providing:
|
|
31
|
+
- Unified CLI (`coaia`) with all commands
|
|
32
|
+
- Unified MCP server (`coaiajs-mcp`) with 64+ tools
|
|
33
|
+
- Shared type system and JSONL storage engine
|
|
34
|
+
- Modern Node.js 20+ (no Python 3.6 constraints)
|
|
35
|
+
|
|
36
|
+
## Components
|
|
37
|
+
|
|
38
|
+
- [01-core-config](./01-core-config.spec.md) — Configuration management
|
|
39
|
+
- [02-redis-module](./02-redis-module.spec.md) — Redis tash/fetch
|
|
40
|
+
- [03-langfuse-module](./03-langfuse-module.spec.md) — Langfuse observability
|
|
41
|
+
- [04-narrative-engine](./04-narrative-engine.spec.md) — JSONL knowledge graph, STC, narrative beats, MMOT
|
|
42
|
+
- [05-pde-engine](./05-pde-engine.spec.md) — PDE→STC transformation
|
|
43
|
+
- [06-planning-engine](./06-planning-engine.spec.md) — Plan parsing, plan↔STC sync
|
|
44
|
+
- [07-pipeline-templates](./07-pipeline-templates.spec.md) — Pipeline template engine
|
|
45
|
+
- [08-cli-interface](./08-cli-interface.spec.md) — Unified CLI
|
|
46
|
+
- [09-mcp-server](./09-mcp-server.spec.md) — Unified MCP server
|
|
47
|
+
- [10-audio-module](./10-audio-module.spec.md) — Audio transcription and synthesis
|
|
48
|
+
|
|
49
|
+
## Lineage
|
|
50
|
+
|
|
51
|
+
| Source | Version | What is inherited |
|
|
52
|
+
|--------|---------|-------------------|
|
|
53
|
+
| coaiapy | v0.4.5 (Python) | Core config, Redis, Langfuse, pipeline, environment, audio, GitHub, LLM |
|
|
54
|
+
| coaia-narrative | v0.12.0 (TypeScript) | JSONL graph, STC lifecycle, narrative beats, MMOT, CLI visualizer |
|
|
55
|
+
| coaia-pde | v0.1.1 (TypeScript) | PDE→STC transformation, session management, direction mapping |
|
|
56
|
+
| coaia-planning | v0.1.0 (TypeScript) | Plan parsing, plan↔STC sync, action step telescoping |
|
|
57
|
+
|
|
58
|
+
## Architectural Decisions
|
|
59
|
+
|
|
60
|
+
### ESM-Only Package
|
|
61
|
+
All imports use `.js` extensions. `"type": "module"` in package.json. No CommonJS fallback.
|
|
62
|
+
|
|
63
|
+
### Strict TypeScript
|
|
64
|
+
`strict: true`, no `any` without explicit justification. Zod for runtime validation at module boundaries.
|
|
65
|
+
|
|
66
|
+
### Lazy Client Initialization
|
|
67
|
+
Redis, OpenAI, Polly, Octokit, Langfuse clients are created on first use. Each module exports `resetClient()` for test isolation. No side effects at import time.
|
|
68
|
+
|
|
69
|
+
### Single Type Source
|
|
70
|
+
All types live in `src/types.ts`. Sub-modules import from there, never define their own parallel types. This is the union of all four parent type systems.
|
|
71
|
+
|
|
72
|
+
### Config Priority Chain
|
|
73
|
+
Environment variables → `.env` file → `coaia.json` → defaults. Deep merge for nested structures.
|
|
74
|
+
|
|
75
|
+
## MCP Tool Budget
|
|
76
|
+
|
|
77
|
+
| Module | Inherited tools | Target tools |
|
|
78
|
+
|--------|----------------|--------------|
|
|
79
|
+
| narrative-engine | 27 (coaia-narrative) | 28 |
|
|
80
|
+
| pde-engine | 12 (coaia-pde) | 12 |
|
|
81
|
+
| planning-engine | 5 (coaia-planning) | 6 |
|
|
82
|
+
| redis | 0 (new) | 5 |
|
|
83
|
+
| langfuse | 0 (new) | 8 |
|
|
84
|
+
| pipeline | 0 (new) | 3 |
|
|
85
|
+
| audio | 0 (new) | 2 |
|
|
86
|
+
| **Total** | **44** | **64** |
|
|
87
|
+
|
|
88
|
+
## Feature Gating
|
|
89
|
+
|
|
90
|
+
The MCP server supports three modes controlled by `COAIAJS_MCP_MODE`:
|
|
91
|
+
- **MINIMAL** — Core narrative tools only (STC, knowledge graph, MMOT)
|
|
92
|
+
- **STANDARD** — Narrative + PDE + planning + Redis
|
|
93
|
+
- **FULL** — All 64+ tools including Langfuse, pipeline, audio
|
|
94
|
+
|
|
95
|
+
## Quality Criteria
|
|
96
|
+
|
|
97
|
+
- ✅ Every coaiapy CLI command has a `coaia` subcommand equivalent
|
|
98
|
+
- ✅ Every MCP tool from parent projects is available in `coaiajs-mcp`
|
|
99
|
+
- ✅ Type system covers 100% of parent project types
|
|
100
|
+
- ✅ JSONL format is byte-compatible with coaia-narrative output
|
|
101
|
+
- ✅ Redis tash/fetch behavior identical to coaiapy
|
|
102
|
+
- ✅ Config loading produces identical results to coaiapy's read_config()
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# 01 — Core Config
|
|
2
|
+
|
|
3
|
+
> Configuration management system for all CoAiA modules.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A unified config loader that provides every CoAiA module with its settings through a single `getConfig()` call, merging environment variables, `.env` files, and `coaia.json` with deterministic priority.
|
|
8
|
+
|
|
9
|
+
## Structural Tension
|
|
10
|
+
|
|
11
|
+
**Current Reality:**
|
|
12
|
+
- `src/config.ts` is fully implemented (172 lines) with `readConfig()`, `getConfig()`, `mergeConfigs()`, `resetConfig()`, and a `config` Proxy for lazy access
|
|
13
|
+
- Supports env vars > .env > coaia.json > defaults priority chain
|
|
14
|
+
- Searches for `coaia.json` or `.coaia/config.json` in cwd and home directory
|
|
15
|
+
- Covers Redis (URL, host/port, Upstash), Langfuse, OpenAI, AWS, GitHub credentials
|
|
16
|
+
- Singleton pattern with lazy loading and proxy access
|
|
17
|
+
- Deep merge implementation for nested config objects
|
|
18
|
+
|
|
19
|
+
**Desired Outcome:**
|
|
20
|
+
Config system that handles all module configuration needs including:
|
|
21
|
+
- Everything currently implemented
|
|
22
|
+
- Langfuse extended config (dataset settings, prompt cache TTL)
|
|
23
|
+
- Pipeline template directory paths
|
|
24
|
+
- MCP server mode selection (MINIMAL/STANDARD/FULL)
|
|
25
|
+
- Narrative memory file path
|
|
26
|
+
- PDE working directory
|
|
27
|
+
- Plan sync settings
|
|
28
|
+
|
|
29
|
+
## CoaiaConfig Shape
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
interface CoaiaConfig {
|
|
33
|
+
// Redis
|
|
34
|
+
redis_url?: string;
|
|
35
|
+
redis_host?: string;
|
|
36
|
+
redis_port?: number;
|
|
37
|
+
|
|
38
|
+
// Langfuse
|
|
39
|
+
langfuse_secret_key?: string;
|
|
40
|
+
langfuse_public_key?: string;
|
|
41
|
+
langfuse_host?: string;
|
|
42
|
+
langfuse_dataset_name?: string;
|
|
43
|
+
langfuse_prompt_cache_ttl?: number;
|
|
44
|
+
|
|
45
|
+
// OpenAI
|
|
46
|
+
openai_api_key?: string;
|
|
47
|
+
openai_model?: string;
|
|
48
|
+
|
|
49
|
+
// AWS (Polly)
|
|
50
|
+
aws_access_key_id?: string;
|
|
51
|
+
aws_secret_access_key?: string;
|
|
52
|
+
aws_region?: string;
|
|
53
|
+
aws_polly_voice?: string;
|
|
54
|
+
|
|
55
|
+
// GitHub
|
|
56
|
+
github_token?: string;
|
|
57
|
+
|
|
58
|
+
// Narrative
|
|
59
|
+
memory_file_path?: string;
|
|
60
|
+
|
|
61
|
+
// PDE
|
|
62
|
+
pde_dir?: string;
|
|
63
|
+
|
|
64
|
+
// Pipeline
|
|
65
|
+
pipeline_template_dir?: string;
|
|
66
|
+
|
|
67
|
+
// MCP
|
|
68
|
+
mcp_mode?: 'MINIMAL' | 'STANDARD' | 'FULL';
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Config Resolution
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
1. process.env — highest priority, always wins
|
|
76
|
+
2. .env file — loaded via dotenv from cwd
|
|
77
|
+
3. coaia.json — searched in cwd, then ~/.coaia/config.json
|
|
78
|
+
4. defaults — hardcoded fallbacks (redis_host: 'localhost', redis_port: 6379, etc.)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Deep merge: nested objects are merged recursively. Arrays are replaced, not concatenated. `undefined` values do not overwrite existing values.
|
|
82
|
+
|
|
83
|
+
## Quality Criteria
|
|
84
|
+
|
|
85
|
+
- ✅ `getConfig()` returns identical results to coaiapy's `read_config()` for the same env/file state
|
|
86
|
+
- ✅ Config is loaded once and cached; `resetConfig()` clears the cache for testing
|
|
87
|
+
- ✅ `config` proxy provides `config.redis_url` shorthand without explicit `getConfig()` call
|
|
88
|
+
- ✅ Missing config keys return `undefined`, never throw
|
|
89
|
+
- ✅ Deep merge handles nested structures correctly
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# 02 — Redis Module
|
|
2
|
+
|
|
3
|
+
> Redis key-value store with tash/fetch convention.
|
|
4
|
+
|
|
5
|
+
## Desired Outcome
|
|
6
|
+
|
|
7
|
+
A thin Redis wrapper providing `tash(key, value, ttl?)` and `fetch(key)` with lazy ioredis connection, Upstash support, and pattern-based key operations — the universal CoAiA data persistence shorthand.
|
|
8
|
+
|
|
9
|
+
## Structural Tension
|
|
10
|
+
|
|
11
|
+
**Current Reality:**
|
|
12
|
+
- `src/redis.ts` is fully implemented (94 lines) with `tash()`, `fetch()`, `del()`, `keys()`, `exists()`, `disconnect()`, `resetClient()`
|
|
13
|
+
- Uses ioredis with lazy connection
|
|
14
|
+
- Supports direct URL, Upstash REST (`rediss://`) URLs, host/port fallback
|
|
15
|
+
- Key-value operations with optional TTL
|
|
16
|
+
- Parity with coaiapy's `tash/fetch` pattern achieved
|
|
17
|
+
|
|
18
|
+
**Desired Outcome:**
|
|
19
|
+
Redis module with everything currently implemented plus:
|
|
20
|
+
- Hash operations (`htash`/`hfetch`) for structured data
|
|
21
|
+
- Sorted set operations for time-series data (session logs, trace ordering)
|
|
22
|
+
- Pub/Sub support for inter-agent messaging
|
|
23
|
+
- Connection health check (`ping()`)
|
|
24
|
+
- MCP tool exposure (5 tools: tash, fetch, del, keys, exists)
|
|
25
|
+
|
|
26
|
+
## Core API
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
// Key-value (implemented)
|
|
30
|
+
tash(key: string, value: string, ttl?: number): Promise<void>
|
|
31
|
+
fetch(key: string): Promise<string | null>
|
|
32
|
+
del(key: string): Promise<number>
|
|
33
|
+
keys(pattern: string): Promise<string[]>
|
|
34
|
+
exists(key: string): Promise<boolean>
|
|
35
|
+
|
|
36
|
+
// Hash (desired)
|
|
37
|
+
htash(key: string, field: string, value: string): Promise<void>
|
|
38
|
+
hfetch(key: string, field?: string): Promise<Record<string, string> | string | null>
|
|
39
|
+
|
|
40
|
+
// Sorted set (desired)
|
|
41
|
+
zadd(key: string, score: number, member: string): Promise<void>
|
|
42
|
+
zrange(key: string, start: number, stop: number): Promise<string[]>
|
|
43
|
+
|
|
44
|
+
// Utility (desired)
|
|
45
|
+
ping(): Promise<boolean>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Connection Strategy
|
|
49
|
+
|
|
50
|
+
1. If `REDIS_URL` or config `redis_url` is set → use it directly
|
|
51
|
+
2. If URL starts with `rediss://` → enable TLS (Upstash pattern)
|
|
52
|
+
3. Otherwise → construct from `redis_host` (default: `localhost`) and `redis_port` (default: `6379`)
|
|
53
|
+
4. Connection is lazy — no connect until first operation
|
|
54
|
+
5. Reconnect automatically on transient failures (ioredis default behavior)
|
|
55
|
+
|
|
56
|
+
## Quality Criteria
|
|
57
|
+
|
|
58
|
+
- ✅ `tash('key', 'value')` behaves identically to coaiapy's `tash('key', 'value')`
|
|
59
|
+
- ✅ `tash('key', 'value', 300)` sets a 300-second TTL
|
|
60
|
+
- ✅ `fetch('nonexistent')` returns `null`, never throws
|
|
61
|
+
- ✅ Upstash URLs work without additional configuration
|
|
62
|
+
- ✅ `resetClient()` disconnects and clears for test isolation
|