coaiajs 0.1.0 → 0.1.1

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.
Files changed (181) hide show
  1. package/dist/mcp/config.d.ts +4 -0
  2. package/dist/mcp/config.d.ts.map +1 -0
  3. package/dist/mcp/config.js +52 -26
  4. package/dist/mcp/config.js.map +1 -0
  5. package/dist/mcp/prompts.d.ts +19 -0
  6. package/dist/mcp/prompts.d.ts.map +1 -0
  7. package/dist/mcp/prompts.js +111 -0
  8. package/dist/mcp/prompts.js.map +1 -0
  9. package/dist/mcp/resources.d.ts +5 -0
  10. package/dist/mcp/resources.d.ts.map +1 -0
  11. package/dist/mcp/resources.js +77 -0
  12. package/dist/mcp/resources.js.map +1 -0
  13. package/dist/mcp/server.d.ts.map +1 -0
  14. package/dist/mcp/server.js +164 -73
  15. package/dist/mcp/server.js.map +1 -0
  16. package/dist/mcp/tools/coaiapy-tools.d.ts.map +1 -0
  17. package/dist/mcp/tools/coaiapy-tools.js +1 -0
  18. package/dist/mcp/tools/coaiapy-tools.js.map +1 -0
  19. package/dist/mcp/tools/index.d.ts.map +1 -0
  20. package/dist/mcp/tools/index.js.map +1 -0
  21. package/dist/src/audio.d.ts.map +1 -0
  22. package/dist/src/audio.js.map +1 -0
  23. package/dist/src/cli-helpers.d.ts.map +1 -0
  24. package/dist/src/cli-helpers.js.map +1 -0
  25. package/dist/src/cli.d.ts.map +1 -0
  26. package/dist/src/cli.js.map +1 -0
  27. package/dist/src/config.d.ts.map +1 -0
  28. package/dist/src/config.js.map +1 -0
  29. package/dist/src/environment.d.ts.map +1 -0
  30. package/dist/src/environment.js.map +1 -0
  31. package/dist/src/github.d.ts.map +1 -0
  32. package/dist/src/github.js.map +1 -0
  33. package/dist/src/index.d.ts +13 -0
  34. package/dist/src/index.d.ts.map +1 -0
  35. package/dist/src/index.js +13 -0
  36. package/dist/src/index.js.map +1 -0
  37. package/dist/src/langfuse/client.d.ts.map +1 -0
  38. package/dist/src/langfuse/client.js.map +1 -0
  39. package/dist/src/langfuse/comments.d.ts.map +1 -0
  40. package/dist/src/langfuse/comments.js.map +1 -0
  41. package/dist/src/langfuse/datasets.d.ts.map +1 -0
  42. package/dist/src/langfuse/datasets.js.map +1 -0
  43. package/dist/src/langfuse/index.d.ts.map +1 -0
  44. package/dist/src/langfuse/index.js.map +1 -0
  45. package/dist/src/langfuse/media.d.ts.map +1 -0
  46. package/dist/src/langfuse/media.js.map +1 -0
  47. package/dist/src/langfuse/observations.d.ts.map +1 -0
  48. package/dist/src/langfuse/observations.js.map +1 -0
  49. package/dist/src/langfuse/prompts.d.ts.map +1 -0
  50. package/dist/src/langfuse/prompts.js.map +1 -0
  51. package/dist/src/langfuse/scores.d.ts.map +1 -0
  52. package/dist/src/langfuse/scores.js.map +1 -0
  53. package/dist/src/langfuse/traces.d.ts.map +1 -0
  54. package/dist/src/langfuse/traces.js.map +1 -0
  55. package/dist/src/llm.d.ts.map +1 -0
  56. package/dist/src/llm.js.map +1 -0
  57. package/dist/src/narrative/graph-manager.d.ts.map +1 -0
  58. package/dist/src/narrative/graph-manager.js.map +1 -0
  59. package/dist/src/narrative/index.d.ts +32 -1
  60. package/dist/src/narrative/index.d.ts.map +1 -0
  61. package/dist/src/narrative/index.js +97 -1
  62. package/dist/src/narrative/index.js.map +1 -0
  63. package/dist/src/narrative/markdown-export.d.ts.map +1 -0
  64. package/dist/src/narrative/markdown-export.js.map +1 -0
  65. package/dist/src/narrative/tool-definitions.d.ts.map +1 -0
  66. package/dist/src/narrative/tool-definitions.js.map +1 -0
  67. package/dist/src/narrative/tool-handlers.d.ts.map +1 -0
  68. package/dist/src/narrative/tool-handlers.js.map +1 -0
  69. package/dist/src/narrative/types.d.ts.map +1 -0
  70. package/dist/src/narrative/types.js.map +1 -0
  71. package/dist/src/narrative/validation.d.ts.map +1 -0
  72. package/dist/src/narrative/validation.js.map +1 -0
  73. package/dist/src/pde/index.d.ts +4 -0
  74. package/dist/src/pde/index.d.ts.map +1 -0
  75. package/dist/src/pde/index.js +19 -0
  76. package/dist/src/pde/index.js.map +1 -0
  77. package/dist/src/pde/mcp-handlers.d.ts.map +1 -0
  78. package/dist/src/pde/mcp-handlers.js.map +1 -0
  79. package/dist/src/pde/mcp-tools.d.ts.map +1 -0
  80. package/dist/src/pde/mcp-tools.js.map +1 -0
  81. package/dist/src/pde/session-manager.d.ts.map +1 -0
  82. package/dist/src/pde/session-manager.js.map +1 -0
  83. package/dist/src/pde/stc-mapper.d.ts.map +1 -0
  84. package/dist/src/pde/stc-mapper.js.map +1 -0
  85. package/dist/src/pipeline/index.d.ts.map +1 -0
  86. package/dist/src/pipeline/index.js.map +1 -0
  87. package/dist/src/pipeline/template-engine.d.ts.map +1 -0
  88. package/dist/src/pipeline/template-engine.js.map +1 -0
  89. package/dist/src/planning/index.d.ts +3 -0
  90. package/dist/src/planning/index.d.ts.map +1 -0
  91. package/dist/src/planning/index.js +13 -0
  92. package/dist/src/planning/index.js.map +1 -0
  93. package/dist/src/planning/mcp-handlers.d.ts.map +1 -0
  94. package/dist/src/planning/mcp-handlers.js.map +1 -0
  95. package/dist/src/planning/mcp-tools.d.ts.map +1 -0
  96. package/dist/src/planning/mcp-tools.js.map +1 -0
  97. package/dist/src/planning/plan-parser.d.ts.map +1 -0
  98. package/dist/src/planning/plan-parser.js.map +1 -0
  99. package/dist/src/redis.d.ts.map +1 -0
  100. package/dist/src/redis.js.map +1 -0
  101. package/dist/src/types.d.ts.map +1 -0
  102. package/dist/src/types.js.map +1 -0
  103. package/package.json +66 -1
  104. package/rispecs/00-coaiajs-platform.spec.md +18 -6
  105. package/rispecs/01-core-config.spec.md +7 -37
  106. package/rispecs/02-redis-module.spec.md +2 -1
  107. package/rispecs/03-langfuse-module.spec.md +7 -5
  108. package/rispecs/04-narrative-engine.spec.md +9 -9
  109. package/rispecs/05-pde-engine.spec.md +23 -23
  110. package/rispecs/06-planning-engine.spec.md +14 -13
  111. package/rispecs/07-pipeline-templates.spec.md +7 -7
  112. package/rispecs/08-cli-interface.spec.md +13 -25
  113. package/rispecs/09-mcp-server.spec.md +41 -44
  114. package/rispecs/10-audio-module.spec.md +3 -3
  115. package/rispecs/KINSHIP.md +4 -4
  116. package/rispecs/README.md +33 -7
  117. package/articles/academic/creative-orientation-vs-problem-solving.md +0 -177
  118. package/articles/academic/jsonl-knowledge-graphs-agent-memory.md +0 -142
  119. package/articles/academic/langfuse-observability-llm-pipelines.md +0 -144
  120. package/articles/academic/medicine-wheel-software-architecture.md +0 -163
  121. package/articles/academic/mmot-autonomous-agents.md +0 -156
  122. package/articles/academic/model-context-protocol-interagent.md +0 -161
  123. package/articles/academic/pde-prompt-decomposition.md +0 -186
  124. package/articles/academic/structural-tension-in-ai-agents.md +0 -134
  125. package/articles/reviews/mcp-protocol-design-review.md +0 -170
  126. package/articles/reviews/observability-ai-systems-review.md +0 -176
  127. package/articles/reviews/prompt-engineering-decomposition-review.md +0 -184
  128. package/articles/surveys/agent-orchestration-survey.md +0 -186
  129. package/articles/surveys/knowledge-graph-storage-survey.md +0 -204
  130. package/articles/surveys/structural-tension-methodology-survey.md +0 -154
  131. package/articles/technical/aws-sdk-v3-polly.md +0 -270
  132. package/articles/technical/commander-cli-framework.md +0 -262
  133. package/articles/technical/dotenv-config-patterns.md +0 -360
  134. package/articles/technical/ioredis-vs-redis.md +0 -142
  135. package/articles/technical/langfuse-js-sdk-vs-rest.md +0 -191
  136. package/articles/technical/mcp-sdk-typescript.md +0 -291
  137. package/articles/technical/octokit-github-api.md +0 -293
  138. package/articles/technical/openai-sdk-modern.md +0 -231
  139. package/articles/technical/yaml-parsing-node.md +0 -266
  140. package/articles/technical/zod-runtime-validation.md +0 -212
  141. package/mcp/config.ts +0 -196
  142. package/mcp/server.ts +0 -402
  143. package/mcp/tools/coaiapy-tools.ts +0 -364
  144. package/mcp/tools/index.ts +0 -4
  145. package/src/audio.ts +0 -76
  146. package/src/cli-helpers.ts +0 -86
  147. package/src/cli.ts +0 -1223
  148. package/src/config.ts +0 -172
  149. package/src/environment.ts +0 -171
  150. package/src/github.ts +0 -143
  151. package/src/langfuse/client.ts +0 -105
  152. package/src/langfuse/comments.ts +0 -52
  153. package/src/langfuse/datasets.ts +0 -178
  154. package/src/langfuse/index.ts +0 -33
  155. package/src/langfuse/media.ts +0 -193
  156. package/src/langfuse/observations.ts +0 -131
  157. package/src/langfuse/prompts.ts +0 -157
  158. package/src/langfuse/scores.ts +0 -456
  159. package/src/langfuse/traces.ts +0 -276
  160. package/src/llm.ts +0 -106
  161. package/src/narrative/graph-manager.ts +0 -1358
  162. package/src/narrative/index.ts +0 -32
  163. package/src/narrative/markdown-export.ts +0 -535
  164. package/src/narrative/tool-definitions.ts +0 -635
  165. package/src/narrative/tool-handlers.ts +0 -528
  166. package/src/narrative/types.ts +0 -9
  167. package/src/narrative/validation.ts +0 -179
  168. package/src/pde/index.ts +0 -8
  169. package/src/pde/mcp-handlers.ts +0 -359
  170. package/src/pde/mcp-tools.ts +0 -201
  171. package/src/pde/session-manager.ts +0 -248
  172. package/src/pde/stc-mapper.ts +0 -298
  173. package/src/pipeline/index.ts +0 -7
  174. package/src/pipeline/template-engine.ts +0 -398
  175. package/src/planning/index.ts +0 -13
  176. package/src/planning/mcp-handlers.ts +0 -369
  177. package/src/planning/mcp-tools.ts +0 -155
  178. package/src/planning/plan-parser.ts +0 -587
  179. package/src/redis.ts +0 -97
  180. package/src/types.ts +0 -280
  181. package/tsconfig.json +0 -26
package/src/config.ts DELETED
@@ -1,172 +0,0 @@
1
- // coaiajs/src/config.ts — Config management
2
- // Priority: env vars > .env > coaia.json > defaults
3
-
4
- import { readFileSync, existsSync } from 'node:fs';
5
- import { resolve, join } from 'node:path';
6
- import { homedir } from 'node:os';
7
- import dotenv from 'dotenv';
8
- import type { CoaiaConfig } from './types.js';
9
-
10
- const CONFIG_FILENAMES = ['coaia.json', '.coaia/config.json'];
11
-
12
- /** Search for an existing coaia.json config file. */
13
- export function findExistingConfig(): string | null {
14
- const searchDirs = [process.cwd(), homedir()];
15
-
16
- for (const dir of searchDirs) {
17
- for (const filename of CONFIG_FILENAMES) {
18
- const candidate = join(dir, filename);
19
- if (existsSync(candidate)) {
20
- return candidate;
21
- }
22
- }
23
- }
24
- return null;
25
- }
26
-
27
- /** Deep-merge two config objects; override wins on conflicts. */
28
- export function mergeConfigs(
29
- base: Partial<CoaiaConfig>,
30
- override: Partial<CoaiaConfig>,
31
- ): CoaiaConfig {
32
- const result: Record<string, unknown> = { ...base };
33
-
34
- for (const [key, val] of Object.entries(override)) {
35
- if (
36
- val !== null &&
37
- val !== undefined &&
38
- typeof val === 'object' &&
39
- !Array.isArray(val) &&
40
- typeof result[key] === 'object' &&
41
- result[key] !== null &&
42
- !Array.isArray(result[key])
43
- ) {
44
- result[key] = mergeConfigs(
45
- result[key] as Partial<CoaiaConfig>,
46
- val as Partial<CoaiaConfig>,
47
- );
48
- } else if (val !== undefined) {
49
- result[key] = val;
50
- }
51
- }
52
- return result as CoaiaConfig;
53
- }
54
-
55
- function loadJsonConfig(filePath: string): Partial<CoaiaConfig> {
56
- try {
57
- const raw = readFileSync(filePath, 'utf-8');
58
- return JSON.parse(raw) as Partial<CoaiaConfig>;
59
- } catch {
60
- return {};
61
- }
62
- }
63
-
64
- function envOverrides(): Partial<CoaiaConfig> {
65
- const cfg: Partial<CoaiaConfig> = {};
66
- const env = process.env;
67
-
68
- // Redis
69
- if (env['REDIS_URL'] || env['REDIS_HOST'] || env['UPSTASH_REDIS_REST_URL']) {
70
- cfg.redis = {
71
- url: env['REDIS_URL'],
72
- host: env['REDIS_HOST'],
73
- port: env['REDIS_PORT'] ? parseInt(env['REDIS_PORT'], 10) : undefined,
74
- password: env['REDIS_PASSWORD'],
75
- upstashUrl: env['UPSTASH_REDIS_REST_URL'],
76
- upstashToken: env['UPSTASH_REDIS_REST_TOKEN'],
77
- };
78
- }
79
-
80
- // Langfuse
81
- if (env['LANGFUSE_PUBLIC_KEY'] || env['LANGFUSE_SECRET_KEY']) {
82
- cfg.langfuse = {
83
- publicKey: env['LANGFUSE_PUBLIC_KEY'],
84
- secretKey: env['LANGFUSE_SECRET_KEY'],
85
- baseUrl: env['LANGFUSE_BASE_URL'] ?? env['LANGFUSE_HOST'],
86
- };
87
- }
88
-
89
- // OpenAI
90
- if (env['OPENAI_API_KEY']) {
91
- cfg.openai = {
92
- apiKey: env['OPENAI_API_KEY'],
93
- model: env['OPENAI_MODEL'] ?? env['LLM_MODEL'],
94
- };
95
- }
96
-
97
- // AWS
98
- if (env['AWS_ACCESS_KEY_ID']) {
99
- cfg.aws = {
100
- accessKeyId: env['AWS_ACCESS_KEY_ID'],
101
- secretAccessKey: env['AWS_SECRET_ACCESS_KEY'],
102
- region: env['AWS_REGION'] ?? env['AWS_DEFAULT_REGION'],
103
- };
104
- }
105
-
106
- // GitHub
107
- if (env['GITHUB_TOKEN'] || env['GH_TOKEN']) {
108
- cfg.github = {
109
- token: env['GITHUB_TOKEN'] ?? env['GH_TOKEN'],
110
- };
111
- }
112
-
113
- return cfg;
114
- }
115
-
116
- /**
117
- * Read and assemble the full CoaiaConfig.
118
- * Priority: env vars > .env file > coaia.json > defaults.
119
- */
120
- export function readConfig(envPath?: string): CoaiaConfig {
121
- // 1. Load .env (lowest priority file source)
122
- const dotenvPath = envPath ?? resolve(process.cwd(), '.env');
123
- if (existsSync(dotenvPath)) {
124
- dotenv.config({ path: dotenvPath });
125
- } else {
126
- dotenv.config(); // default search
127
- }
128
-
129
- // 2. Load coaia.json
130
- const configPath = findExistingConfig();
131
- const jsonConfig = configPath ? loadJsonConfig(configPath) : {};
132
-
133
- // 3. Env var overrides (highest priority)
134
- const envCfg = envOverrides();
135
-
136
- // 4. Merge: json < env
137
- return mergeConfigs(jsonConfig, envCfg);
138
- }
139
-
140
- /** Singleton config instance, lazily loaded on first access. */
141
- let _config: CoaiaConfig | null = null;
142
-
143
- export function getConfig(): CoaiaConfig {
144
- if (!_config) {
145
- _config = readConfig();
146
- }
147
- return _config;
148
- }
149
-
150
- /** Reset singleton (useful in tests). */
151
- export function resetConfig(): void {
152
- _config = null;
153
- }
154
-
155
- export const config = new Proxy({} as CoaiaConfig, {
156
- get(_target, prop: string) {
157
- return getConfig()[prop];
158
- },
159
- ownKeys() {
160
- return Object.keys(getConfig());
161
- },
162
- getOwnPropertyDescriptor(_target, prop: string) {
163
- const cfg = getConfig();
164
- if (prop in cfg) {
165
- return { configurable: true, enumerable: true, value: cfg[prop] };
166
- }
167
- return undefined;
168
- },
169
- has(_target, prop: string) {
170
- return prop in getConfig();
171
- },
172
- });
@@ -1,171 +0,0 @@
1
- // coaiajs/src/environment.ts — Environment management
2
- // Parity with coaiapy's environment.py
3
-
4
- import { readFileSync, writeFileSync, existsSync } from 'node:fs';
5
- import { resolve, join } from 'node:path';
6
- import { homedir } from 'node:os';
7
-
8
- const ENV_FILENAME = '.coaia-env';
9
-
10
- /** Well-known CoAIA environment variable names. */
11
- const KNOWN_VARS = [
12
- 'COAIA_TRACE_ID',
13
- 'COAIA_SESSION_ID',
14
- 'COAIA_USER_ID',
15
- 'COAIA_PROJECT_ID',
16
- 'COAIA_ENV',
17
- 'COAIA_LOG_LEVEL',
18
- 'COAIA_CONFIG_PATH',
19
- 'COAIA_REDIS_URL',
20
- 'COAIA_PDE_DIR',
21
- ] as const;
22
-
23
- export type KnownVar = (typeof KNOWN_VARS)[number];
24
-
25
- export interface EnvStore {
26
- [key: string]: string;
27
- }
28
-
29
- export class EnvironmentManager {
30
- private store: EnvStore = {};
31
- private filePath: string;
32
-
33
- constructor(dir?: string) {
34
- const baseDir = dir ?? process.cwd();
35
- this.filePath = resolve(baseDir, ENV_FILENAME);
36
- }
37
-
38
- /** Initialize environment — load from file if it exists. */
39
- init(): void {
40
- if (existsSync(this.filePath)) {
41
- this.load();
42
- }
43
- }
44
-
45
- /** List all environment variables in the store. */
46
- list(): EnvStore {
47
- return { ...this.store };
48
- }
49
-
50
- /** Get a single variable value. */
51
- get(key: string): string | undefined {
52
- // Check store first, fall back to process.env
53
- return this.store[key] ?? process.env[key];
54
- }
55
-
56
- /** Set an environment variable (in-memory + process.env). */
57
- set(key: string, value: string): void {
58
- this.store[key] = value;
59
- process.env[key] = value;
60
- }
61
-
62
- /** Remove a variable from the store and process.env. */
63
- unset(key: string): void {
64
- delete this.store[key];
65
- delete process.env[key];
66
- }
67
-
68
- /** Clear all stored variables. */
69
- clear(): void {
70
- for (const key of Object.keys(this.store)) {
71
- delete process.env[key];
72
- }
73
- this.store = {};
74
- }
75
-
76
- /**
77
- * Source variables into process.env (like `source .env`).
78
- * Applies all stored vars to process.env.
79
- */
80
- source(): void {
81
- for (const [key, value] of Object.entries(this.store)) {
82
- process.env[key] = value;
83
- }
84
- }
85
-
86
- /** Save the current store to .coaia-env (JSON format). */
87
- save(): void {
88
- writeFileSync(this.filePath, JSON.stringify(this.store, null, 2), 'utf-8');
89
- }
90
-
91
- /** Save as .env format. */
92
- saveAsEnv(outPath?: string): void {
93
- const target = outPath ?? this.filePath.replace(/\.coaia-env$/, '.coaia.env');
94
- const lines = Object.entries(this.store)
95
- .map(([k, v]) => `${k}=${v}`)
96
- .join('\n');
97
- writeFileSync(target, lines + '\n', 'utf-8');
98
- }
99
-
100
- /** Load from .coaia-env file. Supports JSON and .env formats. */
101
- private load(): void {
102
- const raw = readFileSync(this.filePath, 'utf-8').trim();
103
-
104
- // Try JSON first
105
- if (raw.startsWith('{')) {
106
- try {
107
- this.store = JSON.parse(raw) as EnvStore;
108
- return;
109
- } catch {
110
- // Fall through to .env parsing
111
- }
112
- }
113
-
114
- // Parse .env format: KEY=VALUE lines
115
- this.store = {};
116
- for (const line of raw.split('\n')) {
117
- const trimmed = line.trim();
118
- if (!trimmed || trimmed.startsWith('#')) continue;
119
- const eqIdx = trimmed.indexOf('=');
120
- if (eqIdx === -1) continue;
121
- const key = trimmed.slice(0, eqIdx).trim();
122
- let value = trimmed.slice(eqIdx + 1).trim();
123
- // Strip surrounding quotes
124
- if (
125
- (value.startsWith('"') && value.endsWith('"')) ||
126
- (value.startsWith("'") && value.endsWith("'"))
127
- ) {
128
- value = value.slice(1, -1);
129
- }
130
- this.store[key] = value;
131
- }
132
- }
133
-
134
- /** Get the file path being used. */
135
- getFilePath(): string {
136
- return this.filePath;
137
- }
138
-
139
- /** Get well-known CoAIA variables that are currently set. */
140
- getKnownVars(): Partial<Record<KnownVar, string>> {
141
- const result: Partial<Record<KnownVar, string>> = {};
142
- for (const key of KNOWN_VARS) {
143
- const val = this.get(key);
144
- if (val !== undefined) {
145
- result[key] = val;
146
- }
147
- }
148
- return result;
149
- }
150
- }
151
-
152
- /** Create a default EnvironmentManager for the current directory. */
153
- export function createEnvironment(dir?: string): EnvironmentManager {
154
- const mgr = new EnvironmentManager(dir);
155
- mgr.init();
156
- return mgr;
157
- }
158
-
159
- /** Find and load environment from cwd or home. */
160
- export function findEnvironment(): EnvironmentManager {
161
- const cwdPath = resolve(process.cwd(), ENV_FILENAME);
162
- if (existsSync(cwdPath)) {
163
- return createEnvironment(process.cwd());
164
- }
165
- const homePath = join(homedir(), ENV_FILENAME);
166
- if (existsSync(homePath)) {
167
- return createEnvironment(homedir());
168
- }
169
- // Return empty manager for cwd
170
- return new EnvironmentManager(process.cwd());
171
- }
package/src/github.ts DELETED
@@ -1,143 +0,0 @@
1
- // coaiajs/src/github.ts — GitHub module
2
- // Parity with coaiapy's cogh.py using @octokit/rest
3
-
4
- import { Octokit } from '@octokit/rest';
5
- import { getConfig } from './config.js';
6
-
7
- let _client: Octokit | null = null;
8
-
9
- function getOctokit(): Octokit {
10
- if (!_client) {
11
- const cfg = getConfig();
12
- _client = new Octokit({
13
- auth: cfg.github?.token ?? process.env['GITHUB_TOKEN'] ?? process.env['GH_TOKEN'],
14
- });
15
- }
16
- return _client;
17
- }
18
-
19
- /** Reset client (testing). */
20
- export function resetClient(): void {
21
- _client = null;
22
- }
23
-
24
- export interface Issue {
25
- number: number;
26
- title: string;
27
- state: string;
28
- body: string | null;
29
- labels: Array<{ name: string }>;
30
- assignees: Array<{ login: string }>;
31
- created_at: string;
32
- updated_at: string;
33
- html_url: string;
34
- user: { login: string } | null;
35
- }
36
-
37
- export interface IssueComment {
38
- id: number;
39
- body: string;
40
- user: { login: string } | null;
41
- created_at: string;
42
- }
43
-
44
- /**
45
- * List issues for a repository.
46
- * Parity with coaiapy's cogh list_issues.
47
- */
48
- export async function listIssues(
49
- owner: string,
50
- repo: string,
51
- options?: {
52
- state?: 'open' | 'closed' | 'all';
53
- labels?: string;
54
- per_page?: number;
55
- page?: number;
56
- },
57
- ): Promise<Issue[]> {
58
- const client = getOctokit();
59
-
60
- const response = await client.issues.listForRepo({
61
- owner,
62
- repo,
63
- state: options?.state ?? 'open',
64
- labels: options?.labels,
65
- per_page: options?.per_page ?? 30,
66
- page: options?.page ?? 1,
67
- });
68
-
69
- return response.data.map(mapIssue);
70
- }
71
-
72
- /**
73
- * Get a single issue by number.
74
- */
75
- export async function getIssue(
76
- owner: string,
77
- repo: string,
78
- issueNumber: number,
79
- ): Promise<Issue> {
80
- const client = getOctokit();
81
-
82
- const response = await client.issues.get({
83
- owner,
84
- repo,
85
- issue_number: issueNumber,
86
- });
87
-
88
- return mapIssue(response.data);
89
- }
90
-
91
- /**
92
- * Get comments for an issue.
93
- */
94
- export async function getIssueComments(
95
- owner: string,
96
- repo: string,
97
- issueNumber: number,
98
- ): Promise<IssueComment[]> {
99
- const client = getOctokit();
100
-
101
- const response = await client.issues.listComments({
102
- owner,
103
- repo,
104
- issue_number: issueNumber,
105
- });
106
-
107
- return response.data.map((c) => ({
108
- id: c.id,
109
- body: c.body ?? '',
110
- user: c.user ? { login: c.user.login } : null,
111
- created_at: c.created_at,
112
- }));
113
- }
114
-
115
- function mapIssue(data: Record<string, unknown>): Issue {
116
- const d = data as {
117
- number: number;
118
- title: string;
119
- state: string;
120
- body: string | null;
121
- labels: Array<{ name?: string } | string>;
122
- assignees: Array<{ login: string }> | null;
123
- created_at: string;
124
- updated_at: string;
125
- html_url: string;
126
- user: { login: string } | null;
127
- };
128
-
129
- return {
130
- number: d.number,
131
- title: d.title,
132
- state: d.state,
133
- body: d.body,
134
- labels: (d.labels ?? []).map((l) =>
135
- typeof l === 'string' ? { name: l } : { name: l.name ?? '' },
136
- ),
137
- assignees: (d.assignees ?? []).map((a) => ({ login: a.login })),
138
- created_at: d.created_at,
139
- updated_at: d.updated_at,
140
- html_url: d.html_url,
141
- user: d.user ? { login: d.user.login } : null,
142
- };
143
- }
@@ -1,105 +0,0 @@
1
- // coaiajs/src/langfuse/client.ts — Langfuse REST client
2
- // Parity with cofuse.py's direct REST approach (no SDK dependency for API calls)
3
-
4
- import { getConfig } from '../config.js';
5
-
6
- export interface IngestionEvent {
7
- id: string;
8
- timestamp: string;
9
- type: 'trace-create' | 'observation-create' | 'score-create' | 'sdk-log';
10
- body: Record<string, unknown>;
11
- }
12
-
13
- export interface LangfuseClientConfig {
14
- publicKey?: string;
15
- secretKey?: string;
16
- baseUrl?: string;
17
- }
18
-
19
- export class LangfuseClient {
20
- private publicKey: string;
21
- private secretKey: string;
22
- private baseUrl: string;
23
-
24
- constructor(config?: LangfuseClientConfig) {
25
- const appConfig = getConfig();
26
- this.publicKey = config?.publicKey ?? appConfig.langfuse?.publicKey ?? '';
27
- this.secretKey = config?.secretKey ?? appConfig.langfuse?.secretKey ?? '';
28
- this.baseUrl = (config?.baseUrl ?? appConfig.langfuse?.baseUrl ?? 'https://cloud.langfuse.com').replace(/\/+$/, '');
29
- }
30
-
31
- private getAuthHeader(): string {
32
- const credentials = Buffer.from(`${this.publicKey}:${this.secretKey}`).toString('base64');
33
- return `Basic ${credentials}`;
34
- }
35
-
36
- async request<T = unknown>(method: string, path: string, body?: unknown): Promise<T> {
37
- const url = `${this.baseUrl}${path}`;
38
- const headers: Record<string, string> = {
39
- 'Authorization': this.getAuthHeader(),
40
- 'Content-Type': 'application/json',
41
- };
42
-
43
- const init: RequestInit = { method, headers };
44
- if (body !== undefined) {
45
- init.body = JSON.stringify(body);
46
- }
47
-
48
- const response = await fetch(url, init);
49
- const text = await response.text();
50
-
51
- if (!response.ok) {
52
- let detail: string;
53
- try {
54
- detail = JSON.stringify(JSON.parse(text), null, 2);
55
- } catch {
56
- detail = text;
57
- }
58
- throw new LangfuseApiError(
59
- `Langfuse API error ${response.status}: ${detail}`,
60
- response.status,
61
- detail,
62
- );
63
- }
64
-
65
- if (!text) return undefined as T;
66
- return JSON.parse(text) as T;
67
- }
68
-
69
- async ingest(events: IngestionEvent[]): Promise<void> {
70
- await this.request('POST', '/api/public/ingestion', { batch: events });
71
- }
72
-
73
- getBaseUrl(): string {
74
- return this.baseUrl;
75
- }
76
- }
77
-
78
- export class LangfuseApiError extends Error {
79
- constructor(
80
- message: string,
81
- public readonly statusCode: number,
82
- public readonly detail: string,
83
- ) {
84
- super(message);
85
- this.name = 'LangfuseApiError';
86
- }
87
- }
88
-
89
- // Singleton with lazy init
90
- let _client: LangfuseClient | null = null;
91
-
92
- export function getClient(config?: LangfuseClientConfig): LangfuseClient {
93
- if (!_client) {
94
- _client = new LangfuseClient(config);
95
- }
96
- return _client;
97
- }
98
-
99
- export function resetClient(): void {
100
- _client = null;
101
- }
102
-
103
- export function nowISO(): string {
104
- return new Date().toISOString();
105
- }
@@ -1,52 +0,0 @@
1
- // coaiajs/src/langfuse/comments.ts — Comment operations
2
- // Port of cofuse.py comment functions
3
-
4
- import { getClient } from './client.js';
5
-
6
- export interface CommentFilters {
7
- objectType?: string;
8
- objectId?: string;
9
- authorUserId?: string;
10
- page?: number;
11
- limit?: number;
12
- }
13
-
14
- export async function listComments(filters: CommentFilters): Promise<string> {
15
- const client = getClient();
16
- const params = new URLSearchParams();
17
-
18
- if (filters.objectType) params.set('objectType', filters.objectType);
19
- if (filters.objectId) params.set('objectId', filters.objectId);
20
- if (filters.authorUserId) params.set('authorUserId', filters.authorUserId);
21
- params.set('page', String(filters.page ?? 1));
22
- params.set('limit', String(filters.limit ?? 50));
23
-
24
- const qs = params.toString();
25
- const result = await client.request<unknown>('GET', `/api/public/comments?${qs}`);
26
- return JSON.stringify(result, null, 2);
27
- }
28
-
29
- export async function getComment(commentId: string): Promise<string> {
30
- const client = getClient();
31
- const result = await client.request<unknown>('GET', `/api/public/comments/${commentId}`);
32
- return JSON.stringify(result, null, 2);
33
- }
34
-
35
- export async function createComment(params: {
36
- text: string;
37
- objectType: string;
38
- objectId: string;
39
- authorUserId?: string;
40
- }): Promise<string> {
41
- const client = getClient();
42
- const data: Record<string, unknown> = {
43
- content: params.text,
44
- objectType: params.objectType,
45
- objectId: params.objectId,
46
- };
47
-
48
- if (params.authorUserId) data.authorUserId = params.authorUserId;
49
-
50
- const result = await client.request<unknown>('POST', '/api/public/comments', data);
51
- return JSON.stringify(result, null, 2);
52
- }