@grackle-ai/plugin-core 0.96.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codespace-handlers.d.ts +6 -0
- package/dist/codespace-handlers.d.ts.map +1 -0
- package/dist/codespace-handlers.js +66 -0
- package/dist/codespace-handlers.js.map +1 -0
- package/dist/cron-phase.d.ts +46 -0
- package/dist/cron-phase.d.ts.map +1 -0
- package/dist/cron-phase.js +88 -0
- package/dist/cron-phase.js.map +1 -0
- package/dist/dispatch-phase.d.ts +46 -0
- package/dist/dispatch-phase.d.ts.map +1 -0
- package/dist/dispatch-phase.js +99 -0
- package/dist/dispatch-phase.js.map +1 -0
- package/dist/environment-handlers.d.ts +16 -0
- package/dist/environment-handlers.d.ts.map +1 -0
- package/dist/environment-handlers.js +255 -0
- package/dist/environment-handlers.js.map +1 -0
- package/dist/environment-reconciliation.d.ts +35 -0
- package/dist/environment-reconciliation.d.ts.map +1 -0
- package/dist/environment-reconciliation.js +74 -0
- package/dist/environment-reconciliation.js.map +1 -0
- package/dist/escalation-handlers.d.ts +8 -0
- package/dist/escalation-handlers.d.ts.map +1 -0
- package/dist/escalation-handlers.js +60 -0
- package/dist/escalation-handlers.js.map +1 -0
- package/dist/finding-handlers.d.ts +8 -0
- package/dist/finding-handlers.d.ts.map +1 -0
- package/dist/finding-handlers.js +38 -0
- package/dist/finding-handlers.js.map +1 -0
- package/dist/grpc-proto-converters.d.ts +31 -0
- package/dist/grpc-proto-converters.d.ts.map +1 -0
- package/dist/grpc-proto-converters.js +222 -0
- package/dist/grpc-proto-converters.js.map +1 -0
- package/dist/grpc-service.d.ts +21 -0
- package/dist/grpc-service.d.ts.map +1 -0
- package/dist/grpc-service.js +50 -0
- package/dist/grpc-service.js.map +1 -0
- package/dist/grpc-shared.d.ts +22 -0
- package/dist/grpc-shared.d.ts.map +1 -0
- package/dist/grpc-shared.js +68 -0
- package/dist/grpc-shared.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge-handlers.d.ts +12 -0
- package/dist/knowledge-handlers.d.ts.map +1 -0
- package/dist/knowledge-handlers.js +149 -0
- package/dist/knowledge-handlers.js.map +1 -0
- package/dist/lifecycle-cleanup.d.ts +13 -0
- package/dist/lifecycle-cleanup.d.ts.map +1 -0
- package/dist/lifecycle-cleanup.js +35 -0
- package/dist/lifecycle-cleanup.js.map +1 -0
- package/dist/lifecycle.d.ts +28 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +132 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/orphan-phase.d.ts +27 -0
- package/dist/orphan-phase.d.ts.map +1 -0
- package/dist/orphan-phase.js +69 -0
- package/dist/orphan-phase.js.map +1 -0
- package/dist/persona-handlers.d.ts +12 -0
- package/dist/persona-handlers.d.ts.map +1 -0
- package/dist/persona-handlers.js +156 -0
- package/dist/persona-handlers.js.map +1 -0
- package/dist/root-task-boot.d.ts +67 -0
- package/dist/root-task-boot.d.ts.map +1 -0
- package/dist/root-task-boot.js +234 -0
- package/dist/root-task-boot.js.map +1 -0
- package/dist/schedule-expression.d.ts +43 -0
- package/dist/schedule-expression.d.ts.map +1 -0
- package/dist/schedule-expression.js +105 -0
- package/dist/schedule-expression.js.map +1 -0
- package/dist/schedule-handlers.d.ts +12 -0
- package/dist/schedule-handlers.d.ts.map +1 -0
- package/dist/schedule-handlers.js +122 -0
- package/dist/schedule-handlers.js.map +1 -0
- package/dist/session-handlers.d.ts +40 -0
- package/dist/session-handlers.d.ts.map +1 -0
- package/dist/session-handlers.js +610 -0
- package/dist/session-handlers.js.map +1 -0
- package/dist/settings-handlers.d.ts +10 -0
- package/dist/settings-handlers.d.ts.map +1 -0
- package/dist/settings-handlers.js +80 -0
- package/dist/settings-handlers.js.map +1 -0
- package/dist/signals/escalation-auto.d.ts +20 -0
- package/dist/signals/escalation-auto.d.ts.map +1 -0
- package/dist/signals/escalation-auto.js +126 -0
- package/dist/signals/escalation-auto.js.map +1 -0
- package/dist/signals/orphan-reparent.d.ts +31 -0
- package/dist/signals/orphan-reparent.d.ts.map +1 -0
- package/dist/signals/orphan-reparent.js +175 -0
- package/dist/signals/orphan-reparent.js.map +1 -0
- package/dist/signals/sigchld.d.ts +12 -0
- package/dist/signals/sigchld.d.ts.map +1 -0
- package/dist/signals/sigchld.js +177 -0
- package/dist/signals/sigchld.js.map +1 -0
- package/dist/task-handlers.d.ts +22 -0
- package/dist/task-handlers.d.ts.map +1 -0
- package/dist/task-handlers.js +517 -0
- package/dist/task-handlers.js.map +1 -0
- package/dist/test-utils/integration-setup.d.ts +11 -0
- package/dist/test-utils/integration-setup.d.ts.map +1 -0
- package/dist/test-utils/integration-setup.js +26 -0
- package/dist/test-utils/integration-setup.js.map +1 -0
- package/dist/test-utils/mock-database.d.ts +152 -0
- package/dist/test-utils/mock-database.d.ts.map +1 -0
- package/dist/test-utils/mock-database.js +169 -0
- package/dist/test-utils/mock-database.js.map +1 -0
- package/dist/token-handlers.d.ts +12 -0
- package/dist/token-handlers.d.ts.map +1 -0
- package/dist/token-handlers.js +85 -0
- package/dist/token-handlers.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/utils/format-gh-error.d.ts +6 -0
- package/dist/utils/format-gh-error.d.ts.map +1 -0
- package/dist/utils/format-gh-error.js +30 -0
- package/dist/utils/format-gh-error.js.map +1 -0
- package/dist/workspace-handlers.d.ts +16 -0
- package/dist/workspace-handlers.d.ts.map +1 -0
- package/dist/workspace-handlers.js +146 -0
- package/dist/workspace-handlers.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { create } from "@bufbuild/protobuf";
|
|
2
|
+
import { grackle } from "@grackle-ai/common";
|
|
3
|
+
import { workspaceStatusToEnum, taskStatusToEnum, } from "@grackle-ai/common";
|
|
4
|
+
import { taskStore, workspaceEnvironmentLinkStore, safeParseJsonArray } from "@grackle-ai/database";
|
|
5
|
+
/** Convert an environment database row to its proto representation. */
|
|
6
|
+
export function envRowToProto(row) {
|
|
7
|
+
return create(grackle.EnvironmentSchema, {
|
|
8
|
+
id: row.id,
|
|
9
|
+
displayName: row.displayName,
|
|
10
|
+
adapterType: row.adapterType,
|
|
11
|
+
adapterConfig: row.adapterConfig,
|
|
12
|
+
bootstrapped: row.bootstrapped,
|
|
13
|
+
status: row.status,
|
|
14
|
+
lastSeen: row.lastSeen || "",
|
|
15
|
+
envInfo: row.envInfo || "",
|
|
16
|
+
createdAt: row.createdAt,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** Convert a session database row to its proto representation. */
|
|
20
|
+
export function sessionRowToProto(row) {
|
|
21
|
+
return create(grackle.SessionSchema, {
|
|
22
|
+
id: row.id,
|
|
23
|
+
environmentId: row.environmentId,
|
|
24
|
+
runtime: row.runtime,
|
|
25
|
+
runtimeSessionId: row.runtimeSessionId ?? "",
|
|
26
|
+
prompt: row.prompt,
|
|
27
|
+
model: row.model,
|
|
28
|
+
status: row.status,
|
|
29
|
+
logPath: row.logPath ?? "",
|
|
30
|
+
turns: row.turns,
|
|
31
|
+
startedAt: row.startedAt,
|
|
32
|
+
suspendedAt: row.suspendedAt ?? "",
|
|
33
|
+
endedAt: row.endedAt ?? "",
|
|
34
|
+
error: row.error ?? "",
|
|
35
|
+
taskId: row.taskId,
|
|
36
|
+
personaId: row.personaId,
|
|
37
|
+
inputTokens: row.inputTokens,
|
|
38
|
+
outputTokens: row.outputTokens,
|
|
39
|
+
costUsd: row.costUsd,
|
|
40
|
+
endReason: row.endReason ?? "",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert a workspace database row to its proto representation.
|
|
45
|
+
* When converting many workspaces (e.g. listWorkspaces), pass a pre-fetched
|
|
46
|
+
* linkedEnvMap to avoid N+1 queries. When omitted, falls back to a per-row query.
|
|
47
|
+
*/
|
|
48
|
+
export function workspaceRowToProto(row, linkedEnvMap) {
|
|
49
|
+
const linkedIds = linkedEnvMap
|
|
50
|
+
? (linkedEnvMap.get(row.id) ?? [])
|
|
51
|
+
: workspaceEnvironmentLinkStore.getLinkedEnvironmentIds(row.id);
|
|
52
|
+
return create(grackle.WorkspaceSchema, {
|
|
53
|
+
id: row.id,
|
|
54
|
+
name: row.name,
|
|
55
|
+
description: row.description,
|
|
56
|
+
repoUrl: row.repoUrl,
|
|
57
|
+
environmentId: row.environmentId,
|
|
58
|
+
status: workspaceStatusToEnum(row.status),
|
|
59
|
+
createdAt: row.createdAt,
|
|
60
|
+
updatedAt: row.updatedAt,
|
|
61
|
+
useWorktrees: row.useWorktrees,
|
|
62
|
+
workingDirectory: row.workingDirectory,
|
|
63
|
+
defaultPersonaId: row.defaultPersonaId,
|
|
64
|
+
linkedEnvironmentIds: linkedIds,
|
|
65
|
+
tokenBudget: row.tokenBudget,
|
|
66
|
+
costBudgetMillicents: row.costBudgetMillicents,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Convert a task database row to its proto representation. */
|
|
70
|
+
export function taskRowToProto(row, childIds, computedStatus, latestSessionId) {
|
|
71
|
+
return create(grackle.TaskSchema, {
|
|
72
|
+
id: row.id,
|
|
73
|
+
workspaceId: row.workspaceId ?? undefined,
|
|
74
|
+
title: row.title,
|
|
75
|
+
description: row.description,
|
|
76
|
+
status: taskStatusToEnum(computedStatus ?? row.status),
|
|
77
|
+
branch: row.branch,
|
|
78
|
+
latestSessionId: latestSessionId ?? "",
|
|
79
|
+
dependsOn: safeParseJsonArray(row.dependsOn),
|
|
80
|
+
startedAt: row.startedAt ?? "",
|
|
81
|
+
completedAt: row.completedAt ?? "",
|
|
82
|
+
createdAt: row.createdAt,
|
|
83
|
+
updatedAt: row.updatedAt,
|
|
84
|
+
sortOrder: row.sortOrder,
|
|
85
|
+
parentTaskId: row.parentTaskId,
|
|
86
|
+
depth: row.depth,
|
|
87
|
+
childTaskIds: childIds ?? taskStore.getChildren(row.id).map((c) => c.id),
|
|
88
|
+
canDecompose: row.canDecompose,
|
|
89
|
+
defaultPersonaId: row.defaultPersonaId,
|
|
90
|
+
workpad: row.workpad,
|
|
91
|
+
scheduleId: row.scheduleId,
|
|
92
|
+
tokenBudget: row.tokenBudget,
|
|
93
|
+
costBudgetMillicents: row.costBudgetMillicents,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Convert a schedule database row to its proto representation. */
|
|
97
|
+
export function scheduleRowToProto(row) {
|
|
98
|
+
return create(grackle.ScheduleSchema, {
|
|
99
|
+
id: row.id,
|
|
100
|
+
title: row.title,
|
|
101
|
+
description: row.description,
|
|
102
|
+
scheduleExpression: row.scheduleExpression,
|
|
103
|
+
personaId: row.personaId,
|
|
104
|
+
environmentId: row.environmentId,
|
|
105
|
+
workspaceId: row.workspaceId,
|
|
106
|
+
parentTaskId: row.parentTaskId,
|
|
107
|
+
enabled: row.enabled,
|
|
108
|
+
lastRunAt: row.lastRunAt ?? "",
|
|
109
|
+
nextRunAt: row.nextRunAt ?? "",
|
|
110
|
+
runCount: row.runCount,
|
|
111
|
+
createdAt: row.createdAt,
|
|
112
|
+
updatedAt: row.updatedAt,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** Convert a finding database row to its proto representation. */
|
|
116
|
+
export function findingRowToProto(row) {
|
|
117
|
+
return create(grackle.FindingSchema, {
|
|
118
|
+
...row,
|
|
119
|
+
tags: safeParseJsonArray(row.tags),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** Convert an escalation database row to its proto representation. */
|
|
123
|
+
export function escalationRowToProto(row) {
|
|
124
|
+
return create(grackle.EscalationSchema, {
|
|
125
|
+
id: row.id,
|
|
126
|
+
workspaceId: row.workspaceId,
|
|
127
|
+
taskId: row.taskId,
|
|
128
|
+
title: row.title,
|
|
129
|
+
message: row.message,
|
|
130
|
+
source: row.source,
|
|
131
|
+
urgency: row.urgency,
|
|
132
|
+
status: row.status,
|
|
133
|
+
createdAt: row.createdAt,
|
|
134
|
+
deliveredAt: row.deliveredAt ?? "",
|
|
135
|
+
acknowledgedAt: row.acknowledgedAt ?? "",
|
|
136
|
+
taskUrl: row.taskUrl,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/** Safely parse a JSON string, returning the fallback value on failure. */
|
|
140
|
+
export function safeParseJson(value, fallback) {
|
|
141
|
+
if (!value) {
|
|
142
|
+
return fallback;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
return JSON.parse(value);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return fallback;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Convert a persona database row to a Persona proto message. */
|
|
152
|
+
export function personaRowToProto(row) {
|
|
153
|
+
const toolConfig = safeParseJson(row.toolConfig, {});
|
|
154
|
+
const mcpServers = safeParseJson(row.mcpServers, []);
|
|
155
|
+
return create(grackle.PersonaSchema, {
|
|
156
|
+
id: row.id,
|
|
157
|
+
name: row.name,
|
|
158
|
+
description: row.description,
|
|
159
|
+
systemPrompt: row.systemPrompt,
|
|
160
|
+
toolConfig: create(grackle.ToolConfigSchema, {
|
|
161
|
+
allowedTools: Array.isArray(toolConfig.allowedTools)
|
|
162
|
+
? toolConfig.allowedTools.filter((t) => typeof t === "string")
|
|
163
|
+
: [],
|
|
164
|
+
disallowedTools: Array.isArray(toolConfig.disallowedTools)
|
|
165
|
+
? toolConfig.disallowedTools.filter((t) => typeof t === "string")
|
|
166
|
+
: [],
|
|
167
|
+
}),
|
|
168
|
+
runtime: row.runtime,
|
|
169
|
+
model: row.model,
|
|
170
|
+
maxTurns: row.maxTurns,
|
|
171
|
+
mcpServers: mcpServers
|
|
172
|
+
.filter((s) =>
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- typeof null === "object", JSON.parse can return null
|
|
174
|
+
s !== null &&
|
|
175
|
+
typeof s === "object" &&
|
|
176
|
+
typeof s.name === "string" &&
|
|
177
|
+
typeof s.command === "string")
|
|
178
|
+
.map((s) => create(grackle.McpServerConfigSchema, {
|
|
179
|
+
name: s.name,
|
|
180
|
+
command: s.command,
|
|
181
|
+
args: Array.isArray(s.args)
|
|
182
|
+
? s.args.filter((a) => typeof a === "string")
|
|
183
|
+
: [],
|
|
184
|
+
tools: Array.isArray(s.tools)
|
|
185
|
+
? s.tools.filter((t) => typeof t === "string")
|
|
186
|
+
: [],
|
|
187
|
+
})),
|
|
188
|
+
createdAt: row.createdAt,
|
|
189
|
+
updatedAt: row.updatedAt,
|
|
190
|
+
type: row.type || "agent",
|
|
191
|
+
script: row.script || "",
|
|
192
|
+
allowedMcpTools: safeParseJson(row.allowedMcpTools, []).filter((t) => typeof t === "string"),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/** Convert a KnowledgeNode to its proto representation. */
|
|
196
|
+
export function knowledgeNodeToProto(node) {
|
|
197
|
+
return create(grackle.KnowledgeNodeProtoSchema, {
|
|
198
|
+
id: node.id,
|
|
199
|
+
kind: node.kind,
|
|
200
|
+
workspaceId: node.workspaceId,
|
|
201
|
+
createdAt: node.createdAt,
|
|
202
|
+
updatedAt: node.updatedAt,
|
|
203
|
+
sourceType: node.kind === "reference" ? node.sourceType : "",
|
|
204
|
+
sourceId: node.kind === "reference" ? node.sourceId : "",
|
|
205
|
+
label: node.kind === "reference" ? node.label : "",
|
|
206
|
+
category: node.kind === "native" ? node.category : "",
|
|
207
|
+
title: node.kind === "native" ? node.title : "",
|
|
208
|
+
content: node.kind === "native" ? node.content : "",
|
|
209
|
+
tags: node.kind === "native" ? node.tags : [],
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** Convert a KnowledgeEdge to its proto representation. */
|
|
213
|
+
export function knowledgeEdgeToProto(edge) {
|
|
214
|
+
return create(grackle.KnowledgeEdgeProtoSchema, {
|
|
215
|
+
fromId: edge.fromId,
|
|
216
|
+
toId: edge.toId,
|
|
217
|
+
type: edge.type,
|
|
218
|
+
metadataJson: edge.metadata ? JSON.stringify(edge.metadata) : "",
|
|
219
|
+
createdAt: edge.createdAt,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=grpc-proto-converters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-proto-converters.js","sourceRoot":"","sources":["../src/grpc-proto-converters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAkB,SAAS,EAA8D,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGhL,uEAAuE;AACvE,MAAM,UAAU,aAAa,CAAC,GAAmB;IAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE;QACvC,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;QAC1B,SAAS,EAAE,GAAG,CAAC,SAAS;KACzB,CAAC,CAAC;AACL,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,GAAe;IAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE;QACnC,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,gBAAg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AE,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QAC/C,OAAO,EAAE,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACnD,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;KAC9C,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,oBAAoB,CAAC,IAAmB;IACtD,OAAO,MAAM,CAAC,OAAO,CAAC,wBAAwB,EAAE;QAC9C,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;QAChE,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC handler aggregator — creates a ServiceCollector pre-loaded with all
|
|
3
|
+
* built-in Grackle handler groups.
|
|
4
|
+
*
|
|
5
|
+
* Previously in `@grackle-ai/core/grpc-service.ts`, moved here because all
|
|
6
|
+
* handler modules now live in `@grackle-ai/plugin-core`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type ServiceCollector } from "@grackle-ai/core";
|
|
11
|
+
import type { ConnectRouter } from "@connectrpc/connect";
|
|
12
|
+
/**
|
|
13
|
+
* Create a `ServiceCollector` pre-loaded with all built-in Grackle handler groups.
|
|
14
|
+
*
|
|
15
|
+
* Use this when you need access to the collector itself (e.g., for testing or
|
|
16
|
+
* to add plugin-contributed handlers before calling `buildRoutes()`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function createDefaultCollector(): ServiceCollector;
|
|
19
|
+
/** Register all Grackle gRPC service handlers on the given ConnectRPC router. */
|
|
20
|
+
export declare function registerGrackleRoutes(router: ConnectRouter): void;
|
|
21
|
+
//# sourceMappingURL=grpc-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-service.d.ts","sourceRoot":"","sources":["../src/grpc-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAczD;;;;;GAKG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAezD;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAEjE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC handler aggregator — creates a ServiceCollector pre-loaded with all
|
|
3
|
+
* built-in Grackle handler groups.
|
|
4
|
+
*
|
|
5
|
+
* Previously in `@grackle-ai/core/grpc-service.ts`, moved here because all
|
|
6
|
+
* handler modules now live in `@grackle-ai/plugin-core`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { grackle } from "@grackle-ai/common";
|
|
11
|
+
import { createServiceCollector } from "@grackle-ai/core";
|
|
12
|
+
import * as environments from "./environment-handlers.js";
|
|
13
|
+
import * as sessions from "./session-handlers.js";
|
|
14
|
+
import * as tasks from "./task-handlers.js";
|
|
15
|
+
import * as workspaces from "./workspace-handlers.js";
|
|
16
|
+
import * as personas from "./persona-handlers.js";
|
|
17
|
+
import * as schedules from "./schedule-handlers.js";
|
|
18
|
+
import * as tokens from "./token-handlers.js";
|
|
19
|
+
import * as findings from "./finding-handlers.js";
|
|
20
|
+
import * as escalations from "./escalation-handlers.js";
|
|
21
|
+
import * as codespaces from "./codespace-handlers.js";
|
|
22
|
+
import * as knowledge from "./knowledge-handlers.js";
|
|
23
|
+
import * as settings from "./settings-handlers.js";
|
|
24
|
+
/**
|
|
25
|
+
* Create a `ServiceCollector` pre-loaded with all built-in Grackle handler groups.
|
|
26
|
+
*
|
|
27
|
+
* Use this when you need access to the collector itself (e.g., for testing or
|
|
28
|
+
* to add plugin-contributed handlers before calling `buildRoutes()`).
|
|
29
|
+
*/
|
|
30
|
+
export function createDefaultCollector() {
|
|
31
|
+
const collector = createServiceCollector();
|
|
32
|
+
collector.addHandlers(grackle.Grackle, environments);
|
|
33
|
+
collector.addHandlers(grackle.Grackle, sessions);
|
|
34
|
+
collector.addHandlers(grackle.Grackle, tasks);
|
|
35
|
+
collector.addHandlers(grackle.Grackle, workspaces);
|
|
36
|
+
collector.addHandlers(grackle.Grackle, personas);
|
|
37
|
+
collector.addHandlers(grackle.Grackle, schedules);
|
|
38
|
+
collector.addHandlers(grackle.Grackle, tokens);
|
|
39
|
+
collector.addHandlers(grackle.Grackle, findings);
|
|
40
|
+
collector.addHandlers(grackle.Grackle, escalations);
|
|
41
|
+
collector.addHandlers(grackle.Grackle, codespaces);
|
|
42
|
+
collector.addHandlers(grackle.Grackle, knowledge);
|
|
43
|
+
collector.addHandlers(grackle.Grackle, settings);
|
|
44
|
+
return collector;
|
|
45
|
+
}
|
|
46
|
+
/** Register all Grackle gRPC service handlers on the given ConnectRPC router. */
|
|
47
|
+
export function registerGrackleRoutes(router) {
|
|
48
|
+
createDefaultCollector().buildRoutes()(router);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=grpc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-service.js","sourceRoot":"","sources":["../src/grpc-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MA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C,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACpD,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACnD,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAClD,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,qBAAqB,CAAC,MAAqB;IACzD,sBAAsB,EAAE,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC handler shared utilities.
|
|
3
|
+
*
|
|
4
|
+
* Utility functions (`toDialableHost`, `validatePipeInputs`, `resolveAncestorEnvironmentId`,
|
|
5
|
+
* `VALID_PIPE_MODES`) are defined in `@grackle-ai/core` and re-exported here for
|
|
6
|
+
* backward compatibility with existing plugin-core consumers.
|
|
7
|
+
*
|
|
8
|
+
* `killSessionAndCleanup` is plugin-core-specific (uses lifecycle streams, orphan
|
|
9
|
+
* reparent, and stream cleanup).
|
|
10
|
+
*/
|
|
11
|
+
import type { SessionRow } from "@grackle-ai/database";
|
|
12
|
+
import { toDialableHost, validatePipeInputs, resolveAncestorEnvironmentId, VALID_PIPE_MODES } from "@grackle-ai/core";
|
|
13
|
+
export { toDialableHost, validatePipeInputs, resolveAncestorEnvironmentId, VALID_PIPE_MODES };
|
|
14
|
+
/**
|
|
15
|
+
* Terminate a session and clean up all associated streams and subscriptions.
|
|
16
|
+
*
|
|
17
|
+
* If the session is already in a terminal state the status update is skipped,
|
|
18
|
+
* but lifecycle and subscription streams are always removed so stale handles
|
|
19
|
+
* do not accumulate.
|
|
20
|
+
*/
|
|
21
|
+
export declare function killSessionAndCleanup(session: SessionRow): void;
|
|
22
|
+
//# sourceMappingURL=grpc-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-shared.d.ts","sourceRoot":"","sources":["../src/grpc-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAGL,cAAc,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,gBAAgB,EACnF,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,CAAC;AAE9F;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAgD/D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gRPC handler shared utilities.
|
|
3
|
+
*
|
|
4
|
+
* Utility functions (`toDialableHost`, `validatePipeInputs`, `resolveAncestorEnvironmentId`,
|
|
5
|
+
* `VALID_PIPE_MODES`) are defined in `@grackle-ai/core` and re-exported here for
|
|
6
|
+
* backward compatibility with existing plugin-core consumers.
|
|
7
|
+
*
|
|
8
|
+
* `killSessionAndCleanup` is plugin-core-specific (uses lifecycle streams, orphan
|
|
9
|
+
* reparent, and stream cleanup).
|
|
10
|
+
*/
|
|
11
|
+
import { create } from "@bufbuild/protobuf";
|
|
12
|
+
import { grackle, powerline } from "@grackle-ai/common";
|
|
13
|
+
import { ROOT_TASK_ID, SESSION_STATUS, TERMINAL_SESSION_STATUSES, END_REASON, } from "@grackle-ai/common";
|
|
14
|
+
import { transferAllPipeSubscriptions } from "./signals/orphan-reparent.js";
|
|
15
|
+
import { sessionStore, taskStore } from "@grackle-ai/database";
|
|
16
|
+
import { adapterManager, streamHub, streamRegistry, cleanupLifecycleStream, logger, emit, toDialableHost, validatePipeInputs, resolveAncestorEnvironmentId, VALID_PIPE_MODES, } from "@grackle-ai/core";
|
|
17
|
+
// Re-export shared utilities from core so existing consumers don't break.
|
|
18
|
+
export { toDialableHost, validatePipeInputs, resolveAncestorEnvironmentId, VALID_PIPE_MODES };
|
|
19
|
+
/**
|
|
20
|
+
* Terminate a session and clean up all associated streams and subscriptions.
|
|
21
|
+
*
|
|
22
|
+
* If the session is already in a terminal state the status update is skipped,
|
|
23
|
+
* but lifecycle and subscription streams are always removed so stale handles
|
|
24
|
+
* do not accumulate.
|
|
25
|
+
*/
|
|
26
|
+
export function killSessionAndCleanup(session) {
|
|
27
|
+
if (!TERMINAL_SESSION_STATUSES.has(session.status)) {
|
|
28
|
+
sessionStore.updateSession(session.id, SESSION_STATUS.STOPPED, undefined, undefined, END_REASON.KILLED);
|
|
29
|
+
streamHub.publish(create(grackle.SessionEventSchema, {
|
|
30
|
+
sessionId: session.id,
|
|
31
|
+
type: grackle.EventType.STATUS,
|
|
32
|
+
timestamp: new Date().toISOString(),
|
|
33
|
+
content: END_REASON.KILLED,
|
|
34
|
+
raw: "",
|
|
35
|
+
}));
|
|
36
|
+
if (session.taskId) {
|
|
37
|
+
const task = taskStore.getTask(session.taskId);
|
|
38
|
+
if (task) {
|
|
39
|
+
emit("task.updated", { taskId: task.id, workspaceId: task.workspaceId || "" });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Forward kill to PowerLine so the agent process is actually terminated.
|
|
44
|
+
// The orphan callback also sends a kill, but that fires asynchronously
|
|
45
|
+
// after subscription cleanup — this ensures immediate process termination.
|
|
46
|
+
const conn = adapterManager.getConnection(session.environmentId);
|
|
47
|
+
if (conn) {
|
|
48
|
+
conn.client.kill(create(powerline.KillRequestSchema, { id: session.id, reason: END_REASON.KILLED })).catch((err) => {
|
|
49
|
+
logger.debug({ err, sessionId: session.id }, "PowerLine kill failed (process may have already exited)");
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// Transfer ALL pipe fds to grandparent BEFORE cleaning up subscriptions.
|
|
53
|
+
// Always transfer regardless of orphaned tasks: ipc_spawn creates child sessions
|
|
54
|
+
// (not tasks), so pipe subs exist even when getOrphanedTasks returns empty.
|
|
55
|
+
if (session.taskId) {
|
|
56
|
+
const task = taskStore.getTask(session.taskId);
|
|
57
|
+
if (task) {
|
|
58
|
+
const grandparentId = task.parentTaskId || ROOT_TASK_ID;
|
|
59
|
+
transferAllPipeSubscriptions(task.id, grandparentId);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
cleanupLifecycleStream(session.id);
|
|
63
|
+
const subs = streamRegistry.getSubscriptionsForSession(session.id);
|
|
64
|
+
for (const sub of subs) {
|
|
65
|
+
streamRegistry.unsubscribe(sub.id);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=grpc-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-shared.js","sourceRoot":"","sources":["../src/grpc-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,yBAAyB,EAEzB,UAAU,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EACL,cAAc,EAAE,SAAS,EAAE,cAAc,EACzC,sBAAsB,EAAE,MAAM,EAAE,IAAI,EACpC,cAAc,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,gBAAgB,GACnF,MAAM,kBAAkB,CAAC;AAE1B,0EAA0E;AAC1E,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,4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CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACvB,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,yDAAyD,CAAC,CAAC;QAC1G,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yEAAyE;IACzE,iFAAiF;IACjF,4EAA4E;IAC5E,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC;YACxD,4BAA4B,CAAC,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,cAAc,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACnE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { createDefaultCollector, registerGrackleRoutes } from "./grpc-service.js";
|
|
2
|
+
export { createLifecycleSubscriber } from "./lifecycle.js";
|
|
3
|
+
export { createSigchldSubscriber } from "./signals/sigchld.js";
|
|
4
|
+
export { createEscalationAutoSubscriber } from "./signals/escalation-auto.js";
|
|
5
|
+
export { createOrphanReparentSubscriber, transferAllPipeSubscriptions } from "./signals/orphan-reparent.js";
|
|
6
|
+
export { createRootTaskBootSubscriber } from "./root-task-boot.js";
|
|
7
|
+
export type { RootTaskBootDeps } from "./root-task-boot.js";
|
|
8
|
+
export { createCronPhase } from "./cron-phase.js";
|
|
9
|
+
export type { CronPhaseDeps } from "./cron-phase.js";
|
|
10
|
+
export { createDispatchPhase } from "./dispatch-phase.js";
|
|
11
|
+
export type { DispatchPhaseDeps } from "./dispatch-phase.js";
|
|
12
|
+
export { createOrphanPhase } from "./orphan-phase.js";
|
|
13
|
+
export type { OrphanPhaseDeps } from "./orphan-phase.js";
|
|
14
|
+
export { lifecycleCleanupPhase } from "./lifecycle-cleanup.js";
|
|
15
|
+
export { createEnvironmentReconciliationPhase } from "./environment-reconciliation.js";
|
|
16
|
+
export type { EnvironmentReconciliationDeps } from "./environment-reconciliation.js";
|
|
17
|
+
export { killSessionAndCleanup } from "./grpc-shared.js";
|
|
18
|
+
export { cleanupLifecycleStream, ensureLifecycleStream } from "./lifecycle.js";
|
|
19
|
+
export { toDialableHost, validatePipeInputs, resolveAncestorEnvironmentId, VALID_PIPE_MODES } from "./grpc-shared.js";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAGlF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5G,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACnE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oCAAoC,EAAE,MAAM,iCAAiC,CAAC;AACvF,YAAY,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// ─── gRPC Handler Aggregator ─────────────────────────────────
|
|
2
|
+
export { createDefaultCollector, registerGrackleRoutes } from "./grpc-service.js";
|
|
3
|
+
// ─── Subscriber Factories ───────────────────────────────────
|
|
4
|
+
export { createLifecycleSubscriber } from "./lifecycle.js";
|
|
5
|
+
export { createSigchldSubscriber } from "./signals/sigchld.js";
|
|
6
|
+
export { createEscalationAutoSubscriber } from "./signals/escalation-auto.js";
|
|
7
|
+
export { createOrphanReparentSubscriber, transferAllPipeSubscriptions } from "./signals/orphan-reparent.js";
|
|
8
|
+
export { createRootTaskBootSubscriber } from "./root-task-boot.js";
|
|
9
|
+
// ─── Reconciliation Phases ──────────────────────────────────
|
|
10
|
+
export { createCronPhase } from "./cron-phase.js";
|
|
11
|
+
export { createDispatchPhase } from "./dispatch-phase.js";
|
|
12
|
+
export { createOrphanPhase } from "./orphan-phase.js";
|
|
13
|
+
export { lifecycleCleanupPhase } from "./lifecycle-cleanup.js";
|
|
14
|
+
export { createEnvironmentReconciliationPhase } from "./environment-reconciliation.js";
|
|
15
|
+
// ─── Handler Utilities ──────────────────────────────────────
|
|
16
|
+
export { killSessionAndCleanup } from "./grpc-shared.js";
|
|
17
|
+
// ─── Re-exports from other modules ──────────────────────────
|
|
18
|
+
export { cleanupLifecycleStream, ensureLifecycleStream } from "./lifecycle.js";
|
|
19
|
+
export { toDialableHost, validatePipeInputs, resolveAncestorEnvironmentId, VALID_PIPE_MODES } from "./grpc-shared.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAElF,+DAA+D;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5G,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAGnE,+DAA+D;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oCAAoC,EAAE,MAAM,iCAAiC,CAAC;AAGvF,+DAA+D;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,+DAA+D;AAC/D,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { grackle } from "@grackle-ai/common";
|
|
2
|
+
/** Search the knowledge graph using semantic similarity. */
|
|
3
|
+
export declare function searchKnowledge(req: grackle.SearchKnowledgeRequest): Promise<grackle.SearchKnowledgeResponse>;
|
|
4
|
+
/** Get a knowledge node by ID. */
|
|
5
|
+
export declare function getKnowledgeNode(req: grackle.GetKnowledgeNodeRequest): Promise<grackle.GetKnowledgeNodeResponse>;
|
|
6
|
+
/** Expand a knowledge node to retrieve its neighbors. */
|
|
7
|
+
export declare function expandKnowledgeNode(req: grackle.ExpandKnowledgeNodeRequest): Promise<grackle.ExpandKnowledgeNodeResponse>;
|
|
8
|
+
/** List recently created knowledge nodes. */
|
|
9
|
+
export declare function listRecentKnowledgeNodes(req: grackle.ListRecentKnowledgeNodesRequest): Promise<grackle.ListRecentKnowledgeNodesResponse>;
|
|
10
|
+
/** Create a new native knowledge node with embedding. */
|
|
11
|
+
export declare function createKnowledgeNode(req: grackle.CreateKnowledgeNodeRequest): Promise<grackle.CreateKnowledgeNodeResponse>;
|
|
12
|
+
//# sourceMappingURL=knowledge-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-handlers.d.ts","sourceRoot":"","sources":["../src/knowledge-handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AA+D7C,4DAA4D;AAC5D,wBAAsB,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAqBnH;AAED,kCAAkC;AAClC,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAmBtH;AAED,yDAAyD;AACzD,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAmB/H;AAED,6CAA6C;AAC7C,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,+BAA+B,GAAG,OAAO,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAmB9I;AAED,yDAAyD;AACzD,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAuB/H"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { ConnectError, Code } from "@connectrpc/connect";
|
|
2
|
+
import { create } from "@bufbuild/protobuf";
|
|
3
|
+
import { grackle } from "@grackle-ai/common";
|
|
4
|
+
import { knowledgeSearch, getNode as getKnowledgeNodeById, expandNode, createNativeNode, ingest, createPassThroughChunker, listRecentNodes, } from "@grackle-ai/knowledge";
|
|
5
|
+
import { getKnowledgeEmbedder, isKnowledgeEnabled } from "@grackle-ai/core";
|
|
6
|
+
import { isNeo4jHealthy } from "@grackle-ai/core";
|
|
7
|
+
import { knowledgeNodeToProto, knowledgeEdgeToProto } from "./grpc-proto-converters.js";
|
|
8
|
+
import { logger } from "@grackle-ai/core";
|
|
9
|
+
/** Error message returned when Neo4j is unreachable. */
|
|
10
|
+
const NEO4J_UNAVAILABLE_MESSAGE = "Knowledge graph temporarily unavailable — Neo4j unreachable";
|
|
11
|
+
/**
|
|
12
|
+
* Guard that checks Neo4j health status.
|
|
13
|
+
*
|
|
14
|
+
* @throws ConnectError with Code.Unavailable if Neo4j is unreachable.
|
|
15
|
+
*/
|
|
16
|
+
function requireKnowledgeReady() {
|
|
17
|
+
if (!isNeo4jHealthy()) {
|
|
18
|
+
throw new ConnectError(NEO4J_UNAVAILABLE_MESSAGE, Code.Unavailable);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Guard that checks embedder availability and Neo4j health, returning the embedder.
|
|
23
|
+
*
|
|
24
|
+
* @throws ConnectError with Code.Unavailable if knowledge is not ready.
|
|
25
|
+
*/
|
|
26
|
+
function requireEmbedder() {
|
|
27
|
+
const embedder = getKnowledgeEmbedder();
|
|
28
|
+
if (!embedder) {
|
|
29
|
+
throw new ConnectError("Knowledge graph not available", Code.Unavailable);
|
|
30
|
+
}
|
|
31
|
+
requireKnowledgeReady();
|
|
32
|
+
return embedder;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wrap non-ConnectError exceptions as Code.Unavailable.
|
|
36
|
+
*
|
|
37
|
+
* ConnectErrors (e.g. NotFound, InvalidArgument) are re-thrown as-is so
|
|
38
|
+
* the handler's own error semantics are preserved.
|
|
39
|
+
*/
|
|
40
|
+
function wrapNeo4jError(err) {
|
|
41
|
+
if (err instanceof ConnectError) {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
// Log the full error server-side for debugging; return a generic message
|
|
45
|
+
// to clients to avoid leaking internal details (hostnames, ports, etc.)
|
|
46
|
+
logger.error({ err }, "Knowledge graph operation failed");
|
|
47
|
+
throw new ConnectError(NEO4J_UNAVAILABLE_MESSAGE, Code.Unavailable);
|
|
48
|
+
}
|
|
49
|
+
/** Search the knowledge graph using semantic similarity. */
|
|
50
|
+
export async function searchKnowledge(req) {
|
|
51
|
+
const embedder = requireEmbedder();
|
|
52
|
+
try {
|
|
53
|
+
const results = await knowledgeSearch(req.query, embedder, {
|
|
54
|
+
limit: req.limit || 10,
|
|
55
|
+
workspaceId: req.workspaceId || undefined,
|
|
56
|
+
});
|
|
57
|
+
return create(grackle.SearchKnowledgeResponseSchema, {
|
|
58
|
+
results: results.map((r) => create(grackle.SearchKnowledgeResultSchema, {
|
|
59
|
+
score: r.score,
|
|
60
|
+
node: knowledgeNodeToProto(r.node),
|
|
61
|
+
edges: r.edges.map(knowledgeEdgeToProto),
|
|
62
|
+
})),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
wrapNeo4jError(err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Get a knowledge node by ID. */
|
|
70
|
+
export async function getKnowledgeNode(req) {
|
|
71
|
+
if (!isKnowledgeEnabled()) {
|
|
72
|
+
throw new ConnectError("Knowledge graph not available", Code.Unavailable);
|
|
73
|
+
}
|
|
74
|
+
requireKnowledgeReady();
|
|
75
|
+
try {
|
|
76
|
+
const result = await getKnowledgeNodeById(req.id);
|
|
77
|
+
if (!result) {
|
|
78
|
+
throw new ConnectError(`Knowledge node not found: ${req.id}`, Code.NotFound);
|
|
79
|
+
}
|
|
80
|
+
return create(grackle.GetKnowledgeNodeResponseSchema, {
|
|
81
|
+
node: knowledgeNodeToProto(result.node),
|
|
82
|
+
edges: result.edges.map(knowledgeEdgeToProto),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
wrapNeo4jError(err);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Expand a knowledge node to retrieve its neighbors. */
|
|
90
|
+
export async function expandKnowledgeNode(req) {
|
|
91
|
+
if (!isKnowledgeEnabled()) {
|
|
92
|
+
throw new ConnectError("Knowledge graph not available", Code.Unavailable);
|
|
93
|
+
}
|
|
94
|
+
requireKnowledgeReady();
|
|
95
|
+
try {
|
|
96
|
+
const result = await expandNode(req.id, {
|
|
97
|
+
depth: req.depth || 1,
|
|
98
|
+
edgeTypes: req.edgeTypes.length > 0 ? req.edgeTypes : undefined,
|
|
99
|
+
});
|
|
100
|
+
return create(grackle.ExpandKnowledgeNodeResponseSchema, {
|
|
101
|
+
nodes: result.nodes.map(knowledgeNodeToProto),
|
|
102
|
+
edges: result.edges.map(knowledgeEdgeToProto),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
wrapNeo4jError(err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** List recently created knowledge nodes. */
|
|
110
|
+
export async function listRecentKnowledgeNodes(req) {
|
|
111
|
+
if (!isKnowledgeEnabled()) {
|
|
112
|
+
throw new ConnectError("Knowledge graph not available", Code.Unavailable);
|
|
113
|
+
}
|
|
114
|
+
requireKnowledgeReady();
|
|
115
|
+
try {
|
|
116
|
+
const result = await listRecentNodes(req.limit || 20, req.workspaceId || undefined);
|
|
117
|
+
return create(grackle.ListRecentKnowledgeNodesResponseSchema, {
|
|
118
|
+
nodes: result.nodes.map(knowledgeNodeToProto),
|
|
119
|
+
edges: result.edges.map(knowledgeEdgeToProto),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
wrapNeo4jError(err);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Create a new native knowledge node with embedding. */
|
|
127
|
+
export async function createKnowledgeNode(req) {
|
|
128
|
+
const embedder = requireEmbedder();
|
|
129
|
+
try {
|
|
130
|
+
const chunker = createPassThroughChunker();
|
|
131
|
+
const embedded = await ingest(req.content, chunker, embedder);
|
|
132
|
+
if (embedded.length === 0) {
|
|
133
|
+
throw new ConnectError("Content produced no embeddings", Code.InvalidArgument);
|
|
134
|
+
}
|
|
135
|
+
const id = await createNativeNode({
|
|
136
|
+
category: (req.category || "insight"),
|
|
137
|
+
title: req.title,
|
|
138
|
+
content: req.content,
|
|
139
|
+
tags: [...req.tags],
|
|
140
|
+
embedding: embedded[0].vector,
|
|
141
|
+
workspaceId: req.workspaceId || "",
|
|
142
|
+
});
|
|
143
|
+
return create(grackle.CreateKnowledgeNodeResponseSchema, { id });
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
wrapNeo4jError(err);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=knowledge-handlers.js.map
|