@opengeni/api-router 0.5.3 → 0.5.4

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 (48) hide show
  1. package/dist/app.js +1 -1
  2. package/dist/{chunk-3HIA43CC.js → chunk-DO2G3JSB.js} +5184 -2195
  3. package/dist/chunk-DO2G3JSB.js.map +1 -0
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +297 -54
  6. package/dist/index.js.map +1 -1
  7. package/package.json +20 -20
  8. package/src/app.ts +415 -147
  9. package/src/auth/managed-auth.ts +32 -16
  10. package/src/http/auth.ts +8 -1
  11. package/src/http/common.ts +6 -2
  12. package/src/http/sse.ts +27 -6
  13. package/src/index.ts +196 -74
  14. package/src/integrations/oauth-client.ts +403 -120
  15. package/src/integrations/provider-domain.ts +4 -1
  16. package/src/mcp/documents.ts +173 -94
  17. package/src/mcp/server.ts +1517 -692
  18. package/src/mcp/session-view.ts +8 -2
  19. package/src/mcp/toolspace.ts +175 -84
  20. package/src/observability.ts +7 -1
  21. package/src/routes/api-keys.ts +39 -23
  22. package/src/routes/billing.ts +180 -65
  23. package/src/routes/capabilities.ts +17 -8
  24. package/src/routes/catalog-assets.ts +5 -2
  25. package/src/routes/codex.ts +244 -63
  26. package/src/routes/connections.ts +71 -33
  27. package/src/routes/documents.ts +242 -92
  28. package/src/routes/enrollments.ts +100 -70
  29. package/src/routes/environments.ts +205 -136
  30. package/src/routes/files.ts +164 -39
  31. package/src/routes/github.ts +123 -50
  32. package/src/routes/install.ts +9 -2
  33. package/src/routes/machines.ts +9 -8
  34. package/src/routes/packs.ts +141 -89
  35. package/src/routes/rigs.ts +189 -0
  36. package/src/routes/scheduled-tasks.ts +51 -9
  37. package/src/routes/sessions.ts +839 -329
  38. package/src/routes/social.ts +50 -38
  39. package/src/routes/workspace-capture.ts +238 -0
  40. package/src/routes/workspaces.ts +159 -13
  41. package/src/sandbox/access.ts +11 -3
  42. package/src/sandbox/auth-callout.ts +5 -1
  43. package/src/sandbox/channel-a.ts +104 -27
  44. package/src/sandbox/enrollment.ts +13 -3
  45. package/src/sandbox/machines.ts +68 -59
  46. package/src/sandbox/metrics-ingestion.ts +238 -17
  47. package/src/sandbox/viewer.ts +172 -46
  48. package/dist/chunk-3HIA43CC.js.map +0 -1
@@ -7,7 +7,10 @@ import { HTTPException } from "hono/http-exception";
7
7
  * domain silently breaks the enable-time connectionRef domain match.
8
8
  */
9
9
  export function canonicalProviderDomain(value: string): string {
10
- const canonical = value.trim().toLowerCase().replace(/^www\./, "");
10
+ const canonical = value
11
+ .trim()
12
+ .toLowerCase()
13
+ .replace(/^www\./, "");
11
14
  if (!canonical) {
12
15
  throw new HTTPException(400, { message: "providerDomain must not be empty" });
13
16
  }
@@ -4,11 +4,7 @@ import {
4
4
  searchDocuments,
5
5
  type DocumentServices,
6
6
  } from "@opengeni/documents";
7
- import {
8
- createKnowledgeMemory,
9
- listKnowledgeMemories,
10
- type Database,
11
- } from "@opengeni/db";
7
+ import { createKnowledgeMemory, listKnowledgeMemories, type Database } from "@opengeni/db";
12
8
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
13
9
  import * as z from "zod/v4";
14
10
 
@@ -17,7 +13,20 @@ const SearchInputSchema = {
17
13
  baseIds: z.array(z.string().uuid()).optional(),
18
14
  limit: z.number().int().positive().max(50).optional(),
19
15
  mode: z.enum(["hybrid", "vector", "keyword"]).optional(),
20
- sourceKinds: z.array(z.enum(["manual_upload", "meeting_transcript", "repository", "email", "chat", "document", "web", "other"])).optional(),
16
+ sourceKinds: z
17
+ .array(
18
+ z.enum([
19
+ "manual_upload",
20
+ "meeting_transcript",
21
+ "repository",
22
+ "email",
23
+ "chat",
24
+ "document",
25
+ "web",
26
+ "other",
27
+ ]),
28
+ )
29
+ .optional(),
21
30
  aclTags: z.array(z.string().min(1)).optional(),
22
31
  };
23
32
 
@@ -42,91 +51,142 @@ export function buildDocumentsMcpServer(
42
51
  version: "1.0.0",
43
52
  });
44
53
 
45
- server.registerTool("list_document_bases", {
46
- description: "List document bases available for retrieval.",
47
- inputSchema: {},
48
- }, async () => ({
49
- content: [{ type: "text", text: JSON.stringify(await listDocumentBases(db, workspaceId)) }],
50
- }));
54
+ server.registerTool(
55
+ "list_document_bases",
56
+ {
57
+ description: "List document bases available for retrieval.",
58
+ inputSchema: {},
59
+ },
60
+ async () => ({
61
+ content: [{ type: "text", text: JSON.stringify(await listDocumentBases(db, workspaceId)) }],
62
+ }),
63
+ );
51
64
 
52
- server.registerTool("search_documents", {
53
- description: "Search indexed documents with hybrid, vector, or keyword retrieval.",
54
- inputSchema: SearchInputSchema,
55
- }, async (input) => searchContent(db, workspaceId, documentServices, input));
65
+ server.registerTool(
66
+ "search_documents",
67
+ {
68
+ description: "Search indexed documents with hybrid, vector, or keyword retrieval.",
69
+ inputSchema: SearchInputSchema,
70
+ },
71
+ async (input) => searchContent(db, workspaceId, documentServices, input),
72
+ );
56
73
 
57
- server.registerTool("knowledge_search", {
58
- description: "Search company knowledge sources with optional base, source-kind, ACL, and retrieval-mode filters.",
59
- inputSchema: SearchInputSchema,
60
- }, async (input) => searchContent(db, workspaceId, documentServices, input));
74
+ server.registerTool(
75
+ "knowledge_search",
76
+ {
77
+ description:
78
+ "Search company knowledge sources with optional base, source-kind, ACL, and retrieval-mode filters.",
79
+ inputSchema: SearchInputSchema,
80
+ },
81
+ async (input) => searchContent(db, workspaceId, documentServices, input),
82
+ );
61
83
 
62
- server.registerTool("fetch_document_chunk", {
63
- description: "Fetch one indexed document chunk by id.",
64
- inputSchema: {
65
- chunkId: z.string().uuid(),
84
+ server.registerTool(
85
+ "fetch_document_chunk",
86
+ {
87
+ description: "Fetch one indexed document chunk by id.",
88
+ inputSchema: {
89
+ chunkId: z.string().uuid(),
90
+ },
66
91
  },
67
- }, async ({ chunkId }) => {
68
- const found = await getDocumentChunk(db, workspaceId, chunkId);
69
- return {
70
- content: [{ type: "text", text: found ? JSON.stringify(found) : `chunk not found: ${chunkId}` }],
71
- isError: !found,
72
- };
73
- });
92
+ async ({ chunkId }) => {
93
+ const found = await getDocumentChunk(db, workspaceId, chunkId);
94
+ return {
95
+ content: [
96
+ { type: "text", text: found ? JSON.stringify(found) : `chunk not found: ${chunkId}` },
97
+ ],
98
+ isError: !found,
99
+ };
100
+ },
101
+ );
74
102
 
75
- server.registerTool("knowledge_fetch", {
76
- description: "Fetch one knowledge source chunk by id.",
77
- inputSchema: {
78
- chunkId: z.string().uuid(),
103
+ server.registerTool(
104
+ "knowledge_fetch",
105
+ {
106
+ description: "Fetch one knowledge source chunk by id.",
107
+ inputSchema: {
108
+ chunkId: z.string().uuid(),
109
+ },
79
110
  },
80
- }, async ({ chunkId }) => {
81
- const found = await getDocumentChunk(db, workspaceId, chunkId);
82
- return {
83
- content: [{ type: "text", text: found ? JSON.stringify(found) : `chunk not found: ${chunkId}` }],
84
- isError: !found,
85
- };
86
- });
111
+ async ({ chunkId }) => {
112
+ const found = await getDocumentChunk(db, workspaceId, chunkId);
113
+ return {
114
+ content: [
115
+ { type: "text", text: found ? JSON.stringify(found) : `chunk not found: ${chunkId}` },
116
+ ],
117
+ isError: !found,
118
+ };
119
+ },
120
+ );
87
121
 
88
- server.registerTool("memory_search", {
89
- description: "Search approved company memory records.",
90
- inputSchema: {
91
- query: z.string().min(1).optional(),
92
- kind: MemoryKindSchema.optional(),
93
- scope: z.string().min(1).optional(),
94
- limit: z.number().int().positive().max(100).optional(),
122
+ server.registerTool(
123
+ "memory_search",
124
+ {
125
+ description: "Search approved company memory records.",
126
+ inputSchema: {
127
+ query: z.string().min(1).optional(),
128
+ kind: MemoryKindSchema.optional(),
129
+ scope: z.string().min(1).optional(),
130
+ limit: z.number().int().positive().max(100).optional(),
131
+ },
95
132
  },
96
- }, async ({ query, kind, scope, limit }) => ({
97
- content: [{ type: "text", text: JSON.stringify(await listKnowledgeMemories(db, workspaceId, {
98
- ...(query ? { query } : {}),
99
- status: "approved",
100
- ...(kind ? { kind } : {}),
101
- ...(scope ? { scope } : {}),
102
- ...(limit ? { limit } : {}),
103
- })) }],
104
- }));
133
+ async ({ query, kind, scope, limit }) => ({
134
+ content: [
135
+ {
136
+ type: "text",
137
+ text: JSON.stringify(
138
+ await listKnowledgeMemories(db, workspaceId, {
139
+ ...(query ? { query } : {}),
140
+ status: ["active", "approved"],
141
+ ...(kind ? { kind } : {}),
142
+ ...(scope ? { scope } : {}),
143
+ ...(limit ? { limit } : {}),
144
+ }),
145
+ ),
146
+ },
147
+ ],
148
+ }),
149
+ );
105
150
 
106
- server.registerTool("memory_propose", {
107
- description: "Propose a company memory record for human review.",
108
- inputSchema: {
109
- text: z.string().min(1),
110
- kind: MemoryKindSchema.optional(),
111
- scope: z.string().min(1).optional(),
112
- sourceRefs: z.array(SourceRefSchema).optional(),
113
- confidence: z.number().min(0).max(1).optional(),
114
- metadata: z.record(z.string(), z.unknown()).optional(),
151
+ server.registerTool(
152
+ "memory_propose",
153
+ {
154
+ description: "Propose a company memory record for human review.",
155
+ inputSchema: {
156
+ text: z.string().min(1),
157
+ kind: MemoryKindSchema.optional(),
158
+ scope: z.string().min(1).optional(),
159
+ sourceRefs: z.array(SourceRefSchema).optional(),
160
+ confidence: z.number().min(0).max(1).optional(),
161
+ metadata: z.record(z.string(), z.unknown()).optional(),
162
+ },
115
163
  },
116
- }, async ({ text, kind, scope, sourceRefs, confidence, metadata }) => ({
117
- content: [{ type: "text", text: JSON.stringify(await createKnowledgeMemory(db, {
118
- accountId,
119
- workspaceId,
120
- status: "proposed",
121
- kind: kind ?? "semantic",
122
- scope: scope ?? "workspace",
123
- text,
124
- sourceRefs: sourceRefs?.map((sourceRef) => ({ ...sourceRef, metadata: sourceRef.metadata ?? {} })) ?? [],
125
- confidence: confidence ?? 0.5,
126
- metadata: metadata ?? {},
127
- createdBySessionId: options.createdBySessionId,
128
- })) }],
129
- }));
164
+ async ({ text, kind, scope, sourceRefs, confidence, metadata }) => ({
165
+ content: [
166
+ {
167
+ type: "text",
168
+ text: JSON.stringify(
169
+ await createKnowledgeMemory(db, {
170
+ accountId,
171
+ workspaceId,
172
+ status: "proposed",
173
+ kind: kind ?? "semantic",
174
+ scope: scope ?? "workspace",
175
+ text,
176
+ sourceRefs:
177
+ sourceRefs?.map((sourceRef) => ({
178
+ ...sourceRef,
179
+ metadata: sourceRef.metadata ?? {},
180
+ })) ?? [],
181
+ confidence: confidence ?? 0.5,
182
+ metadata: metadata ?? {},
183
+ createdBySessionId: options.createdBySessionId,
184
+ }),
185
+ ),
186
+ },
187
+ ],
188
+ }),
189
+ );
130
190
 
131
191
  return server;
132
192
  }
@@ -140,22 +200,41 @@ async function searchContent(
140
200
  baseIds?: string[] | undefined;
141
201
  limit?: number | undefined;
142
202
  mode?: "hybrid" | "vector" | "keyword" | undefined;
143
- sourceKinds?: Array<"manual_upload" | "meeting_transcript" | "repository" | "email" | "chat" | "document" | "web" | "other"> | undefined;
203
+ sourceKinds?:
204
+ | Array<
205
+ | "manual_upload"
206
+ | "meeting_transcript"
207
+ | "repository"
208
+ | "email"
209
+ | "chat"
210
+ | "document"
211
+ | "web"
212
+ | "other"
213
+ >
214
+ | undefined;
144
215
  aclTags?: string[] | undefined;
145
216
  },
146
217
  ) {
147
218
  return {
148
- content: [{
149
- type: "text" as const,
150
- text: JSON.stringify(await searchDocuments(db, {
151
- workspaceId,
152
- query: input.query,
153
- ...(input.baseIds ? { baseIds: input.baseIds } : {}),
154
- ...(input.limit ? { limit: input.limit } : {}),
155
- ...(input.mode ? { mode: input.mode } : {}),
156
- ...(input.sourceKinds ? { sourceKinds: input.sourceKinds } : {}),
157
- ...(input.aclTags ? { aclTags: input.aclTags } : {}),
158
- }, documentServices)),
159
- }],
219
+ content: [
220
+ {
221
+ type: "text" as const,
222
+ text: JSON.stringify(
223
+ await searchDocuments(
224
+ db,
225
+ {
226
+ workspaceId,
227
+ query: input.query,
228
+ ...(input.baseIds ? { baseIds: input.baseIds } : {}),
229
+ ...(input.limit ? { limit: input.limit } : {}),
230
+ ...(input.mode ? { mode: input.mode } : {}),
231
+ ...(input.sourceKinds ? { sourceKinds: input.sourceKinds } : {}),
232
+ ...(input.aclTags ? { aclTags: input.aclTags } : {}),
233
+ },
234
+ documentServices,
235
+ ),
236
+ ),
237
+ },
238
+ ],
160
239
  };
161
240
  }