@feltdb/feltkit 0.1.1 → 0.2.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/dist/app.d.ts +106 -10
- package/dist/app.js +51 -0
- package/dist/app.js.map +1 -1
- package/dist/cli/main.js +218 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/skills.d.ts +39 -0
- package/dist/cli/skills.js +125 -0
- package/dist/cli/skills.js.map +1 -0
- package/dist/dashboard/assets/{index-BLnBFDJs.css → index--1Tqbv_A.css} +1 -1
- package/dist/dashboard/assets/index-Bm4qCYpv.js +15 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/runtime/activity.d.ts +21 -8
- package/dist/runtime/activity.js +17 -3
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent.d.ts +353 -0
- package/dist/runtime/agent.js +1345 -0
- package/dist/runtime/agent.js.map +1 -0
- package/dist/runtime/authority.d.ts +23 -3
- package/dist/runtime/authority.js +69 -5
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/changes.d.ts +16 -8
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/content.d.ts +33 -0
- package/dist/runtime/content.js +46 -0
- package/dist/runtime/content.js.map +1 -0
- package/dist/runtime/context.d.ts +26 -1
- package/dist/runtime/credentials.d.ts +42 -0
- package/dist/runtime/credentials.js +32 -0
- package/dist/runtime/credentials.js.map +1 -0
- package/dist/runtime/data.d.ts +8 -2
- package/dist/runtime/data.js +74 -9
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/decisions.d.ts +131 -0
- package/dist/runtime/decisions.js +301 -0
- package/dist/runtime/decisions.js.map +1 -0
- package/dist/runtime/environment.js +11 -0
- package/dist/runtime/environment.js.map +1 -1
- package/dist/runtime/idempotency.d.ts +37 -0
- package/dist/runtime/idempotency.js +88 -0
- package/dist/runtime/idempotency.js.map +1 -0
- package/dist/runtime/instance.d.ts +8 -3
- package/dist/runtime/instance.js +27 -4
- package/dist/runtime/instance.js.map +1 -1
- package/dist/runtime/integrations.d.ts +120 -0
- package/dist/runtime/integrations.js +412 -0
- package/dist/runtime/integrations.js.map +1 -0
- package/dist/runtime/loader.d.ts +5 -1
- package/dist/runtime/loader.js +35 -13
- package/dist/runtime/loader.js.map +1 -1
- package/dist/runtime/projects.d.ts +1 -0
- package/dist/runtime/projects.js +6 -4
- package/dist/runtime/projects.js.map +1 -1
- package/dist/runtime/readiness.d.ts +29 -0
- package/dist/runtime/readiness.js +154 -0
- package/dist/runtime/readiness.js.map +1 -0
- package/dist/runtime/runtime.d.ts +50 -1
- package/dist/runtime/runtime.js +225 -9
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +186 -36
- package/dist/runtime/services.js +420 -152
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.d.ts +7 -18
- package/dist/runtime/sessions.js +7 -5
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/server/admin.d.ts +26 -0
- package/dist/server/admin.js +510 -8
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +13 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/management.d.ts +12 -0
- package/dist/server/management.js +177 -0
- package/dist/server/management.js.map +1 -0
- package/dist/server/mcp.d.ts +202 -0
- package/dist/server/mcp.js +62 -4
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/operators.d.ts +77 -0
- package/dist/server/operators.js +162 -0
- package/dist/server/operators.js.map +1 -0
- package/dist/server/project.js +17 -4
- package/dist/server/project.js.map +1 -1
- package/dist/testing/index.js +3 -2
- package/dist/testing/index.js.map +1 -1
- package/package.json +18 -11
- package/skills/.claude-plugin/marketplace.json +16 -0
- package/skills/.claude-plugin/plugin.json +24 -0
- package/skills/README.md +44 -0
- package/skills/feltkit-agent/SKILL.md +84 -0
- package/skills/feltkit-build/SKILL.md +143 -0
- package/skills/feltkit-data/SKILL.md +79 -0
- package/skills/feltkit-operations/SKILL.md +72 -0
- package/skills/feltkit-services/SKILL.md +102 -0
- package/dist/dashboard/assets/index-CxJGCspE.js +0 -15
package/dist/server/mcp.d.ts
CHANGED
|
@@ -9,4 +9,206 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
11
11
|
import type { FeltKitRuntime } from "../runtime/runtime.js";
|
|
12
|
+
/**
|
|
13
|
+
* FeltKit agent tools, next to the application's own. They let an external coding agent
|
|
14
|
+
* work a FeltDB agent task: read context, claim a handoff, propose actions (which run as
|
|
15
|
+
* the task owner through AppPort, consequential ones only after a person approves them in
|
|
16
|
+
* Studio), record notes, and complete. There is deliberately no approve tool.
|
|
17
|
+
* Every tool needs feltkit.agent.read / feltkit.agent.write, checked by the agent itself.
|
|
18
|
+
*/
|
|
19
|
+
export declare const AGENT_TOOLS: ({
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: string;
|
|
24
|
+
properties: {
|
|
25
|
+
objective?: undefined;
|
|
26
|
+
playbook?: undefined;
|
|
27
|
+
target?: undefined;
|
|
28
|
+
capability?: undefined;
|
|
29
|
+
args?: undefined;
|
|
30
|
+
handoffId?: undefined;
|
|
31
|
+
taskId?: undefined;
|
|
32
|
+
input?: undefined;
|
|
33
|
+
reason?: undefined;
|
|
34
|
+
summary?: undefined;
|
|
35
|
+
decisions?: undefined;
|
|
36
|
+
pendingWork?: undefined;
|
|
37
|
+
};
|
|
38
|
+
additionalProperties: boolean;
|
|
39
|
+
required?: undefined;
|
|
40
|
+
};
|
|
41
|
+
} | {
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
inputSchema: {
|
|
45
|
+
type: string;
|
|
46
|
+
properties: {
|
|
47
|
+
objective: {
|
|
48
|
+
type: string;
|
|
49
|
+
};
|
|
50
|
+
playbook: {
|
|
51
|
+
type: string;
|
|
52
|
+
};
|
|
53
|
+
target: {
|
|
54
|
+
type: string;
|
|
55
|
+
};
|
|
56
|
+
capability: {
|
|
57
|
+
type: string;
|
|
58
|
+
};
|
|
59
|
+
args: {
|
|
60
|
+
type: string;
|
|
61
|
+
};
|
|
62
|
+
handoffId?: undefined;
|
|
63
|
+
taskId?: undefined;
|
|
64
|
+
input?: undefined;
|
|
65
|
+
reason?: undefined;
|
|
66
|
+
summary?: undefined;
|
|
67
|
+
decisions?: undefined;
|
|
68
|
+
pendingWork?: undefined;
|
|
69
|
+
};
|
|
70
|
+
required: string[];
|
|
71
|
+
additionalProperties: boolean;
|
|
72
|
+
};
|
|
73
|
+
} | {
|
|
74
|
+
name: string;
|
|
75
|
+
description: string;
|
|
76
|
+
inputSchema: {
|
|
77
|
+
type: string;
|
|
78
|
+
properties: {
|
|
79
|
+
handoffId: {
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
objective?: undefined;
|
|
83
|
+
playbook?: undefined;
|
|
84
|
+
target?: undefined;
|
|
85
|
+
capability?: undefined;
|
|
86
|
+
args?: undefined;
|
|
87
|
+
taskId?: undefined;
|
|
88
|
+
input?: undefined;
|
|
89
|
+
reason?: undefined;
|
|
90
|
+
summary?: undefined;
|
|
91
|
+
decisions?: undefined;
|
|
92
|
+
pendingWork?: undefined;
|
|
93
|
+
};
|
|
94
|
+
required: string[];
|
|
95
|
+
additionalProperties: boolean;
|
|
96
|
+
};
|
|
97
|
+
} | {
|
|
98
|
+
name: string;
|
|
99
|
+
description: string;
|
|
100
|
+
inputSchema: {
|
|
101
|
+
type: string;
|
|
102
|
+
properties: {
|
|
103
|
+
taskId: {
|
|
104
|
+
type: string;
|
|
105
|
+
};
|
|
106
|
+
objective?: undefined;
|
|
107
|
+
playbook?: undefined;
|
|
108
|
+
target?: undefined;
|
|
109
|
+
capability?: undefined;
|
|
110
|
+
args?: undefined;
|
|
111
|
+
handoffId?: undefined;
|
|
112
|
+
input?: undefined;
|
|
113
|
+
reason?: undefined;
|
|
114
|
+
summary?: undefined;
|
|
115
|
+
decisions?: undefined;
|
|
116
|
+
pendingWork?: undefined;
|
|
117
|
+
};
|
|
118
|
+
required: string[];
|
|
119
|
+
additionalProperties: boolean;
|
|
120
|
+
};
|
|
121
|
+
} | {
|
|
122
|
+
name: string;
|
|
123
|
+
description: string;
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: string;
|
|
126
|
+
properties: {
|
|
127
|
+
taskId: {
|
|
128
|
+
type: string;
|
|
129
|
+
};
|
|
130
|
+
capability: {
|
|
131
|
+
type: string;
|
|
132
|
+
};
|
|
133
|
+
input: {
|
|
134
|
+
type: string;
|
|
135
|
+
};
|
|
136
|
+
reason: {
|
|
137
|
+
type: string;
|
|
138
|
+
};
|
|
139
|
+
objective?: undefined;
|
|
140
|
+
playbook?: undefined;
|
|
141
|
+
target?: undefined;
|
|
142
|
+
args?: undefined;
|
|
143
|
+
handoffId?: undefined;
|
|
144
|
+
summary?: undefined;
|
|
145
|
+
decisions?: undefined;
|
|
146
|
+
pendingWork?: undefined;
|
|
147
|
+
};
|
|
148
|
+
required: string[];
|
|
149
|
+
additionalProperties: boolean;
|
|
150
|
+
};
|
|
151
|
+
} | {
|
|
152
|
+
name: string;
|
|
153
|
+
description: string;
|
|
154
|
+
inputSchema: {
|
|
155
|
+
type: string;
|
|
156
|
+
properties: {
|
|
157
|
+
taskId: {
|
|
158
|
+
type: string;
|
|
159
|
+
};
|
|
160
|
+
summary: {
|
|
161
|
+
type: string;
|
|
162
|
+
};
|
|
163
|
+
decisions: {
|
|
164
|
+
type: string;
|
|
165
|
+
items: {
|
|
166
|
+
type: string;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
pendingWork: {
|
|
170
|
+
type: string;
|
|
171
|
+
items: {
|
|
172
|
+
type: string;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
objective?: undefined;
|
|
176
|
+
playbook?: undefined;
|
|
177
|
+
target?: undefined;
|
|
178
|
+
capability?: undefined;
|
|
179
|
+
args?: undefined;
|
|
180
|
+
handoffId?: undefined;
|
|
181
|
+
input?: undefined;
|
|
182
|
+
reason?: undefined;
|
|
183
|
+
};
|
|
184
|
+
required: string[];
|
|
185
|
+
additionalProperties: boolean;
|
|
186
|
+
};
|
|
187
|
+
} | {
|
|
188
|
+
name: string;
|
|
189
|
+
description: string;
|
|
190
|
+
inputSchema: {
|
|
191
|
+
type: string;
|
|
192
|
+
properties: {
|
|
193
|
+
taskId: {
|
|
194
|
+
type: string;
|
|
195
|
+
};
|
|
196
|
+
summary: {
|
|
197
|
+
type: string;
|
|
198
|
+
};
|
|
199
|
+
objective?: undefined;
|
|
200
|
+
playbook?: undefined;
|
|
201
|
+
target?: undefined;
|
|
202
|
+
capability?: undefined;
|
|
203
|
+
args?: undefined;
|
|
204
|
+
handoffId?: undefined;
|
|
205
|
+
input?: undefined;
|
|
206
|
+
reason?: undefined;
|
|
207
|
+
decisions?: undefined;
|
|
208
|
+
pendingWork?: undefined;
|
|
209
|
+
};
|
|
210
|
+
required: string[];
|
|
211
|
+
additionalProperties: boolean;
|
|
212
|
+
};
|
|
213
|
+
})[];
|
|
12
214
|
export declare function handleMcp(runtime: FeltKitRuntime, request: IncomingMessage, response: ServerResponse): Promise<void>;
|
package/dist/server/mcp.js
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
1
|
import { readBody, sendJSON, bearerToken } from "./http.js";
|
|
2
|
+
import { fromAppPortPrincipal } from "../runtime/authority.js";
|
|
3
|
+
import { isFeltKitError } from "../errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* FeltKit agent tools, next to the application's own. They let an external coding agent
|
|
6
|
+
* work a FeltDB agent task: read context, claim a handoff, propose actions (which run as
|
|
7
|
+
* the task owner through AppPort, consequential ones only after a person approves them in
|
|
8
|
+
* Studio), record notes, and complete. There is deliberately no approve tool.
|
|
9
|
+
* Every tool needs feltkit.agent.read / feltkit.agent.write, checked by the agent itself.
|
|
10
|
+
*/
|
|
11
|
+
export const AGENT_TOOLS = [
|
|
12
|
+
{ name: "feltkit_context", description: "This application as you may see it: collections, capabilities (with whether you may call each and whether it needs approval), services and their states, recent errors and denials.", inputSchema: { type: "object", properties: {}, additionalProperties: false } },
|
|
13
|
+
{ name: "feltkit_agent_tasks", description: "Agent tasks in this application and handoffs waiting to be claimed.", inputSchema: { type: "object", properties: {}, additionalProperties: false } },
|
|
14
|
+
{ name: "feltkit_agent_create", description: "Create a task you own. playbook: diagnose-job | diagnose-delivery | inspect-app | invoke | handoff (default).", inputSchema: { type: "object", properties: { objective: { type: "string" }, playbook: { type: "string" }, target: { type: "string" }, capability: { type: "string" }, args: { type: "object" } }, required: ["objective"], additionalProperties: false } },
|
|
15
|
+
{ name: "feltkit_agent_claim", description: "Claim an open handoff. You become the task owner and receive its context.", inputSchema: { type: "object", properties: { handoffId: { type: "string" } }, required: ["handoffId"], additionalProperties: false } },
|
|
16
|
+
{ name: "feltkit_agent_get", description: "A task with its checkpoints (and their verified evidence), FeltDB execution record, and actions with their states (proposed, approved, executing, succeeded, failed, interrupted = outcome unknown, rejected, cancelled) and attribution.", inputSchema: { type: "object", properties: { taskId: { type: "string" } }, required: ["taskId"], additionalProperties: false } },
|
|
17
|
+
{ name: "feltkit_agent_propose", description: "Propose an action on a task you own. Observations run now; consequential actions wait for a person to approve them in FeltKit Studio.", inputSchema: { type: "object", properties: { taskId: { type: "string" }, capability: { type: "string" }, input: { type: "object" }, reason: { type: "string" } }, required: ["taskId", "capability", "reason"], additionalProperties: false } },
|
|
18
|
+
{ name: "feltkit_agent_note", description: "Record progress and decisions on a task you own.", inputSchema: { type: "object", properties: { taskId: { type: "string" }, summary: { type: "string" }, decisions: { type: "array", items: { type: "string" } }, pendingWork: { type: "array", items: { type: "string" } } }, required: ["taskId", "summary"], additionalProperties: false } },
|
|
19
|
+
{ name: "feltkit_agent_complete", description: "Complete a task you own with a summary. Refused while any action is open (awaiting approval, running, or with an unknown outcome).", inputSchema: { type: "object", properties: { taskId: { type: "string" }, summary: { type: "string" } }, required: ["taskId", "summary"], additionalProperties: false } },
|
|
20
|
+
];
|
|
21
|
+
async function callAgentTool(runtime, principal, name, args) {
|
|
22
|
+
const agent = runtime.agent;
|
|
23
|
+
switch (name) {
|
|
24
|
+
case "feltkit_context":
|
|
25
|
+
// The same read permission as every other agent tool.
|
|
26
|
+
agent.authorizeRead(principal);
|
|
27
|
+
return agent.applicationContext(principal);
|
|
28
|
+
case "feltkit_agent_tasks":
|
|
29
|
+
return { tasks: await agent.list(principal), handoffs: await agent.openHandoffs(principal) };
|
|
30
|
+
case "feltkit_agent_create":
|
|
31
|
+
return agent.createTask({ objective: String(args.objective ?? ""), principal, ...(args.playbook ? { playbook: args.playbook } : {}), ...(args.target ? { target: String(args.target) } : {}), ...(args.capability ? { capability: String(args.capability) } : {}), ...(args.args ? { args: args.args } : {}) });
|
|
32
|
+
case "feltkit_agent_claim":
|
|
33
|
+
return agent.claim(String(args.handoffId ?? ""), principal);
|
|
34
|
+
case "feltkit_agent_get":
|
|
35
|
+
return agent.get(String(args.taskId ?? ""), principal);
|
|
36
|
+
case "feltkit_agent_propose":
|
|
37
|
+
return agent.propose(String(args.taskId ?? ""), { capability: String(args.capability ?? ""), input: args.input ?? {}, reason: String(args.reason ?? "") }, principal);
|
|
38
|
+
case "feltkit_agent_note":
|
|
39
|
+
return agent.note(String(args.taskId ?? ""), { summary: String(args.summary ?? ""), ...(Array.isArray(args.decisions) ? { decisions: args.decisions } : {}), ...(Array.isArray(args.pendingWork) ? { pendingWork: args.pendingWork } : {}) }, principal);
|
|
40
|
+
case "feltkit_agent_complete":
|
|
41
|
+
return agent.complete(String(args.taskId ?? ""), String(args.summary ?? ""), principal);
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
2
45
|
const PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
|
|
3
46
|
const rpcError = (id, code, message) => ({ jsonrpc: "2.0", id: id ?? null, error: { code, message } });
|
|
4
47
|
export async function handleMcp(runtime, request, response) {
|
|
@@ -8,9 +51,11 @@ export async function handleMcp(runtime, request, response) {
|
|
|
8
51
|
}
|
|
9
52
|
const token = bearerToken(request);
|
|
10
53
|
const session = token ? await runtime.sessions.get(token) : undefined;
|
|
11
|
-
|
|
54
|
+
// An AppPort Services API key is accepted too (services.apiKeys), as its own principal.
|
|
55
|
+
const keyed = !session && token ? await runtime.principalForToken(token) : null;
|
|
56
|
+
if (!session && !keyed) {
|
|
12
57
|
response.setHeader("WWW-Authenticate", 'Bearer realm="feltkit"');
|
|
13
|
-
sendJSON(response, 401, rpcError(null, -32001, "An agent session token is required (Authorization: Bearer <token>). Create one with `feltkit session create --type agent
|
|
58
|
+
sendJSON(response, 401, rpcError(null, -32001, "An agent session token is required (Authorization: Bearer <token>). Create one with `feltkit session create --type agent`, or use an API key."));
|
|
14
59
|
return;
|
|
15
60
|
}
|
|
16
61
|
let message;
|
|
@@ -22,7 +67,8 @@ export async function handleMcp(runtime, request, response) {
|
|
|
22
67
|
return;
|
|
23
68
|
}
|
|
24
69
|
const batch = Array.isArray(message) ? message : [message];
|
|
25
|
-
const bridge = runtime.mcpBridge(null, session);
|
|
70
|
+
const bridge = session ? runtime.mcpBridge(null, session) : runtime.mcpBridge(keyed, undefined);
|
|
71
|
+
const principal = (session ? fromAppPortPrincipal(session.principal) : keyed);
|
|
26
72
|
const replies = [];
|
|
27
73
|
for (const rpc of batch) {
|
|
28
74
|
if (!rpc || rpc.jsonrpc !== "2.0" || typeof rpc.method !== "string") {
|
|
@@ -47,10 +93,22 @@ export async function handleMcp(runtime, request, response) {
|
|
|
47
93
|
result = {};
|
|
48
94
|
break;
|
|
49
95
|
case "tools/list":
|
|
50
|
-
result = { tools: bridge.listTools().map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })) };
|
|
96
|
+
result = { tools: [...bridge.listTools().map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema })), ...AGENT_TOOLS] };
|
|
51
97
|
break;
|
|
52
98
|
case "tools/call": {
|
|
53
99
|
const name = String(rpc.params?.name ?? "");
|
|
100
|
+
if (AGENT_TOOLS.some((tool) => tool.name === name)) {
|
|
101
|
+
try {
|
|
102
|
+
const value = await callAgentTool(runtime, principal, name, (rpc.params?.arguments ?? {}));
|
|
103
|
+
result = { content: [{ type: "text", text: JSON.stringify(value) }], structuredContent: { result: value } };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
// Tool execution errors are results, as MCP defines them; the code is FeltKit's.
|
|
107
|
+
const code = isFeltKitError(error) ? error.code : "INTERNAL";
|
|
108
|
+
result = { content: [{ type: "text", text: `${code}: ${error.message}` }], isError: true };
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
54
112
|
result = await bridge.callTool(name, rpc.params?.arguments ?? {});
|
|
55
113
|
break;
|
|
56
114
|
}
|
package/dist/server/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/server/mcp.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG5D,MAAM,iBAAiB,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AASrE,MAAM,QAAQ,GAAG,CAAC,EAAwB,EAAE,IAAY,EAAE,OAAe,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;AAE7I,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAuB,EAAE,OAAwB,EAAE,QAAwB;IACzG,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC9B,QAAQ,CA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0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Production operators: who may use Studio against a deployed application.
|
|
3
|
+
*
|
|
4
|
+
* Development Studio acts as declared dev identities, authorized by the admin token.
|
|
5
|
+
* None of that carries into production. There, every /_feltkit/api request must come
|
|
6
|
+
* from a verified operator, and the operation is authorized as that person:
|
|
7
|
+
*
|
|
8
|
+
* 1. A FeltKit operator session (kind "operator"), from the `feltkit_operator` cookie
|
|
9
|
+
* (HttpOnly, SameSite=Strict, Secure, Path=/_feltkit) or a Bearer token. Sessions are
|
|
10
|
+
* FeltKit sessions in this environment's FeltDB instance: a session from another
|
|
11
|
+
* environment does not exist here.
|
|
12
|
+
* 2. Otherwise the application's own `auth.authenticate` hook, which verifies the request
|
|
13
|
+
* with the application's identity provider.
|
|
14
|
+
*
|
|
15
|
+
* Operator sessions start from a one-time **grant**: `feltkit operator grant --id <id>
|
|
16
|
+
* --role <role>` on the production host signs { application, environment, subject, roles,
|
|
17
|
+
* expiry, nonce } with this environment's operator key (`FELTKIT_OPERATOR_KEY`, else
|
|
18
|
+
* `.feltkit/<env>/operator-key`, mode 0600). Studio exchanges the grant once for a session.
|
|
19
|
+
* The root of trust is whoever can read that key, i.e. the host operator. Roles must be
|
|
20
|
+
* declared by the application; the grant cannot invent permissions.
|
|
21
|
+
*
|
|
22
|
+
* Writes from a browser also need: Content-Type application/json, an Origin equal to the
|
|
23
|
+
* request's own host, an `x-feltkit-csrf` header bound to the session, and an
|
|
24
|
+
* `x-feltkit-environment` header naming this environment.
|
|
25
|
+
*/
|
|
26
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
27
|
+
import type { FeltKitRuntime } from "../runtime/runtime.js";
|
|
28
|
+
import { type Principal } from "../runtime/authority.js";
|
|
29
|
+
export declare const OPERATOR_PERMISSIONS: {
|
|
30
|
+
readonly read: "feltkit.operations.read";
|
|
31
|
+
readonly write: "feltkit.operations.write";
|
|
32
|
+
};
|
|
33
|
+
export declare const OPERATOR_COOKIE = "feltkit_operator";
|
|
34
|
+
/** This environment's operator signing key. Never logged, never sent anywhere. */
|
|
35
|
+
export declare function operatorKey(runtimeDir: string, env?: NodeJS.ProcessEnv): Buffer;
|
|
36
|
+
export interface GrantClaims {
|
|
37
|
+
application: string;
|
|
38
|
+
environment: string;
|
|
39
|
+
subject: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
roles: string[];
|
|
42
|
+
expiresAt: number;
|
|
43
|
+
nonce: string;
|
|
44
|
+
}
|
|
45
|
+
/** A one-time operator grant. Short-lived; exchanged once for a session. */
|
|
46
|
+
export declare function createGrant(key: Buffer, claims: Omit<GrantClaims, "expiresAt" | "nonce"> & {
|
|
47
|
+
ttlMs?: number;
|
|
48
|
+
}): string;
|
|
49
|
+
export declare function verifyGrant(key: Buffer, grant: string, expected: {
|
|
50
|
+
application: string;
|
|
51
|
+
environment: string;
|
|
52
|
+
}): GrantClaims;
|
|
53
|
+
/** Exchange a grant for an operator session. Each grant works once. */
|
|
54
|
+
export declare function signIn(runtime: FeltKitRuntime, grant: string, key: Buffer): Promise<{
|
|
55
|
+
token: string;
|
|
56
|
+
principal: Principal;
|
|
57
|
+
expiresAt?: string;
|
|
58
|
+
}>;
|
|
59
|
+
export declare function setSessionCookie(runtime: FeltKitRuntime, response: ServerResponse, token: string | null): void;
|
|
60
|
+
export interface Operator {
|
|
61
|
+
principal: Principal;
|
|
62
|
+
/** The session token, when the operator holds a FeltKit operator session. */
|
|
63
|
+
token?: string;
|
|
64
|
+
via: "operator-session" | "auth-hook";
|
|
65
|
+
}
|
|
66
|
+
/** The verified operator behind a request, or null. Never a client-supplied claim. */
|
|
67
|
+
export declare function authenticateOperator(runtime: FeltKitRuntime, request: IncomingMessage): Promise<Operator | null>;
|
|
68
|
+
/** A CSRF value bound to the operator's session (or, for hook identities, to the principal). */
|
|
69
|
+
export declare function csrfFor(operator: Operator): string;
|
|
70
|
+
/**
|
|
71
|
+
* Browser-write protections for production: JSON only (no cross-site simple requests),
|
|
72
|
+
* same-origin Origin, the session-bound CSRF value, and the environment the caller means.
|
|
73
|
+
*/
|
|
74
|
+
export declare function checkWrite(runtime: FeltKitRuntime, request: IncomingMessage, operator: Operator | null): void;
|
|
75
|
+
/** Require an operator holding `permission`. Unauthenticated → 401; unauthorized → 403, without detail. */
|
|
76
|
+
export declare function requireOperator(runtime: FeltKitRuntime, operator: Operator | null, permission: string): Promise<Principal>;
|
|
77
|
+
export declare const newRequestId: () => string;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { FeltKitError } from "../errors.js";
|
|
5
|
+
import { normalizePrincipal } from "../runtime/authority.js";
|
|
6
|
+
import { writeAtomic } from "../runtime/projects.js";
|
|
7
|
+
import { bearerToken, headerRecord, safeEqual } from "./http.js";
|
|
8
|
+
export const OPERATOR_PERMISSIONS = { read: "feltkit.operations.read", write: "feltkit.operations.write" };
|
|
9
|
+
export const OPERATOR_COOKIE = "feltkit_operator";
|
|
10
|
+
const GRANTS = "_feltkit_operator_grants";
|
|
11
|
+
const GRANT_PREFIX = "fkg1";
|
|
12
|
+
const DEFAULT_GRANT_TTL_MS = 10 * 60_000;
|
|
13
|
+
const DEFAULT_SESSION_TTL_MS = 8 * 60 * 60_000;
|
|
14
|
+
/** This environment's operator signing key. Never logged, never sent anywhere. */
|
|
15
|
+
export function operatorKey(runtimeDir, env = process.env) {
|
|
16
|
+
const fromEnv = env.FELTKIT_OPERATOR_KEY;
|
|
17
|
+
if (fromEnv) {
|
|
18
|
+
const key = Buffer.from(fromEnv, "base64url");
|
|
19
|
+
if (key.length < 32)
|
|
20
|
+
throw new FeltKitError("CONFIGURATION", "FELTKIT_OPERATOR_KEY must be at least 32 bytes, base64url-encoded.");
|
|
21
|
+
return key;
|
|
22
|
+
}
|
|
23
|
+
mkdirSync(runtimeDir, { recursive: true });
|
|
24
|
+
const file = join(runtimeDir, "operator-key");
|
|
25
|
+
if (existsSync(file)) {
|
|
26
|
+
const key = Buffer.from(readFileSync(file, "utf8").trim(), "base64url");
|
|
27
|
+
if (key.length >= 32)
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
const key = randomBytes(32);
|
|
31
|
+
writeAtomic(file, `${key.toString("base64url")}\n`, 0o600);
|
|
32
|
+
return key;
|
|
33
|
+
}
|
|
34
|
+
const sign = (key, payload) => createHmac("sha256", key).update(`${GRANT_PREFIX}.${payload}`).digest("base64url");
|
|
35
|
+
/** A one-time operator grant. Short-lived; exchanged once for a session. */
|
|
36
|
+
export function createGrant(key, claims) {
|
|
37
|
+
if (!/^[A-Za-z0-9._@:-]{1,128}$/.test(claims.subject))
|
|
38
|
+
throw new FeltKitError("INVALID_ARGUMENT", "The operator id may contain letters, digits, and . _ @ : - (1–128 characters).");
|
|
39
|
+
if (!claims.roles.length)
|
|
40
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Give the operator at least one role (--role).");
|
|
41
|
+
const body = {
|
|
42
|
+
application: claims.application,
|
|
43
|
+
environment: claims.environment,
|
|
44
|
+
subject: claims.subject,
|
|
45
|
+
...(claims.name ? { name: claims.name } : {}),
|
|
46
|
+
roles: [...claims.roles],
|
|
47
|
+
expiresAt: Date.now() + Math.min(claims.ttlMs ?? DEFAULT_GRANT_TTL_MS, 24 * 60 * 60_000),
|
|
48
|
+
nonce: randomBytes(16).toString("base64url"),
|
|
49
|
+
};
|
|
50
|
+
const payload = Buffer.from(JSON.stringify(body)).toString("base64url");
|
|
51
|
+
return `${GRANT_PREFIX}.${payload}.${sign(key, payload)}`;
|
|
52
|
+
}
|
|
53
|
+
const refused = () => new FeltKitError("UNAUTHORIZED", "The operator grant is invalid, expired, already used, or for another application or environment.");
|
|
54
|
+
export function verifyGrant(key, grant, expected) {
|
|
55
|
+
const [prefix, payload, signature] = String(grant ?? "").trim().split(".");
|
|
56
|
+
if (prefix !== GRANT_PREFIX || !payload || !signature || !safeEqual(signature, sign(key, payload)))
|
|
57
|
+
throw refused();
|
|
58
|
+
let claims;
|
|
59
|
+
try {
|
|
60
|
+
claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw refused();
|
|
64
|
+
}
|
|
65
|
+
if (claims.application !== expected.application || claims.environment !== expected.environment || !(claims.expiresAt > Date.now()) || !Array.isArray(claims.roles))
|
|
66
|
+
throw refused();
|
|
67
|
+
return claims;
|
|
68
|
+
}
|
|
69
|
+
/** Exchange a grant for an operator session. Each grant works once. */
|
|
70
|
+
export async function signIn(runtime, grant, key) {
|
|
71
|
+
const claims = verifyGrant(key, grant, { application: runtime.app.name, environment: runtime.environment.name });
|
|
72
|
+
const db = runtime.instance.handle("feltkit.operators");
|
|
73
|
+
try {
|
|
74
|
+
await db.transaction({ operations: [{ collection: GRANTS, id: createHash("sha256").update(claims.nonce).digest("hex"), requireAbsent: true, value: { subject: claims.subject, usedAt: new Date().toISOString(), expiresAt: claims.expiresAt } }] });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw refused();
|
|
78
|
+
}
|
|
79
|
+
const issued = await runtime.issueSession({ id: claims.subject, type: "user", roles: claims.roles, ...(claims.name ? { displayName: claims.name } : {}) }, { kind: "operator", label: "production operator", ttlMs: DEFAULT_SESSION_TTL_MS, via: "dashboard" });
|
|
80
|
+
return issued;
|
|
81
|
+
}
|
|
82
|
+
const cookieName = (runtime) => `${OPERATOR_COOKIE}_${runtime.environment.name}`;
|
|
83
|
+
function readCookie(request, name) {
|
|
84
|
+
for (const part of String(request.headers.cookie ?? "").split(";")) {
|
|
85
|
+
const [k, ...v] = part.trim().split("=");
|
|
86
|
+
if (k === name)
|
|
87
|
+
return decodeURIComponent(v.join("="));
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
export function setSessionCookie(runtime, response, token) {
|
|
92
|
+
const attributes = ["Path=/_feltkit", "HttpOnly", "SameSite=Strict", "Secure"];
|
|
93
|
+
response.setHeader("Set-Cookie", token ? `${cookieName(runtime)}=${encodeURIComponent(token)}; ${attributes.join("; ")}; Max-Age=${DEFAULT_SESSION_TTL_MS / 1000}` : `${cookieName(runtime)}=; ${attributes.join("; ")}; Max-Age=0`);
|
|
94
|
+
}
|
|
95
|
+
/** The verified operator behind a request, or null. Never a client-supplied claim. */
|
|
96
|
+
export async function authenticateOperator(runtime, request) {
|
|
97
|
+
const token = readCookie(request, cookieName(runtime)) ?? bearerToken(request);
|
|
98
|
+
if (token) {
|
|
99
|
+
const session = await runtime.sessions.get(token);
|
|
100
|
+
const kind = session?.attributes?.kind;
|
|
101
|
+
const principal = await runtime.principalForToken(token);
|
|
102
|
+
if (!session || kind !== "operator" || !principal || principal.type !== "user") {
|
|
103
|
+
throw new FeltKitError("UNAUTHORIZED", "Your operator session is invalid or has expired. Sign in again.");
|
|
104
|
+
}
|
|
105
|
+
return { principal, token, via: "operator-session" };
|
|
106
|
+
}
|
|
107
|
+
const hook = runtime.app.options.auth?.authenticate;
|
|
108
|
+
if (hook) {
|
|
109
|
+
const found = await hook({ method: request.method ?? "GET", path: request.url ?? "/", headers: headerRecord(request) });
|
|
110
|
+
if (found) {
|
|
111
|
+
const principal = normalizePrincipal(found);
|
|
112
|
+
if (principal.type === "user")
|
|
113
|
+
return { principal, via: "auth-hook" };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/** A CSRF value bound to the operator's session (or, for hook identities, to the principal). */
|
|
119
|
+
export function csrfFor(operator) {
|
|
120
|
+
return createHash("sha256").update(`feltkit-csrf:${operator.token ?? `hook:${operator.principal.id}`}`).digest("base64url").slice(0, 32);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Browser-write protections for production: JSON only (no cross-site simple requests),
|
|
124
|
+
* same-origin Origin, the session-bound CSRF value, and the environment the caller means.
|
|
125
|
+
*/
|
|
126
|
+
export function checkWrite(runtime, request, operator) {
|
|
127
|
+
const type = String(request.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase();
|
|
128
|
+
if (type !== "application/json")
|
|
129
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Production writes must be sent as Content-Type: application/json.");
|
|
130
|
+
const origin = request.headers.origin;
|
|
131
|
+
const host = request.headers["x-forwarded-host"] ?? request.headers.host;
|
|
132
|
+
let originHost = null;
|
|
133
|
+
try {
|
|
134
|
+
originHost = origin ? new URL(String(origin)).host : null;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
originHost = null;
|
|
138
|
+
}
|
|
139
|
+
if (!originHost || originHost !== String(host ?? "").split(",")[0].trim()) {
|
|
140
|
+
throw new FeltKitError("FORBIDDEN", "Cross-origin request refused: production writes must come from this server's own origin.");
|
|
141
|
+
}
|
|
142
|
+
const environment = request.headers["x-feltkit-environment"];
|
|
143
|
+
if (environment !== runtime.environment.name) {
|
|
144
|
+
throw new FeltKitError("FORBIDDEN", `This server is the ${runtime.environment.name} environment; the request did not name it (x-feltkit-environment). Nothing was changed.`);
|
|
145
|
+
}
|
|
146
|
+
if (operator) {
|
|
147
|
+
const csrf = request.headers["x-feltkit-csrf"];
|
|
148
|
+
if (typeof csrf !== "string" || !safeEqual(csrf, csrfFor(operator)))
|
|
149
|
+
throw new FeltKitError("FORBIDDEN", "Missing or wrong CSRF token. Reload Studio and try again.");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Require an operator holding `permission`. Unauthenticated → 401; unauthorized → 403, without detail. */
|
|
153
|
+
export async function requireOperator(runtime, operator, permission) {
|
|
154
|
+
if (!operator)
|
|
155
|
+
throw new FeltKitError("UNAUTHORIZED", "Sign in as an operator to use Studio in production.");
|
|
156
|
+
const decision = await runtime.authority.authorize({ access: permission, principal: operator.principal, target: { name: permission }, transport: "dashboard" });
|
|
157
|
+
if (!decision.allowed)
|
|
158
|
+
throw new FeltKitError("FORBIDDEN", `${operator.principal.id} does not hold ${permission}.`);
|
|
159
|
+
return operator.principal;
|
|
160
|
+
}
|
|
161
|
+
export const newRequestId = () => `req_${randomUUID()}`;
|
|
162
|
+
//# sourceMappingURL=operators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/server/operators.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAkB,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,yBAAyB,EAAE,KAAK,EAAE,0BAA0B,EAAW,CAAC;AACpH,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,MAAM,MAAM,GAAG,0BAA0B,CAAC;AAC1C,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,oBAAoB,GAAG,EAAE,GAAG,MAAM,CAAC;AACzC,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC;AAE/C,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,UAAkB,EAAE,MAAyB,OAAO,CAAC,GAAG;IAClF,MAAM,OAAO,GAAG,GAAG,CAAC,oBAAoB,CAAC;IACzC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,GAAG,GAAG,M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AC1G,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,qDAAqD,CAAC,CAAC;IAC7G,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;IAChK,IAAI,CAAC,QAAQ,CAAC,OAAO;QAAE,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC,EAAE,kBAAkB,UAAU,GAAG,CAAC,CAAC;IACpH,OAAO,QAAQ,CAAC,SAAS,CAAC;AAC5B,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,OAAO,UAAU,EAAE,EAAE,CAAC"}
|
package/dist/server/project.js
CHANGED
|
@@ -72,7 +72,15 @@ export function doctor(projectDir) {
|
|
|
72
72
|
detail: existsSync(join(projectDir, BACKEND_DIR)) ? `${BACKEND_DIR}/ with ${safeModules(projectDir).length} module(s)` : `No ${BACKEND_DIR}/ directory`,
|
|
73
73
|
fix: `Create ${BACKEND_DIR}/app.ts that exports feltkit({ name }).`,
|
|
74
74
|
});
|
|
75
|
-
|
|
75
|
+
// Like Node's resolution: the project's own node_modules, or an ancestor's (npm workspaces hoist).
|
|
76
|
+
const nodeModules = (() => {
|
|
77
|
+
for (let dir = resolve(projectDir);; dir = dirname(dir)) {
|
|
78
|
+
if (existsSync(join(dir, "node_modules")))
|
|
79
|
+
return true;
|
|
80
|
+
if (dirname(dir) === dir)
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
76
84
|
checks.push({ name: "Dependencies installed", ok: nodeModules, detail: nodeModules ? "node_modules present" : "node_modules missing", fix: "Run npm install." });
|
|
77
85
|
// One copy of @feltdb/core, shared with AppPort Services.
|
|
78
86
|
try {
|
|
@@ -125,8 +133,10 @@ async function loadVite(projectDir) {
|
|
|
125
133
|
export async function startDev(options) {
|
|
126
134
|
const projectDir = resolve(options.projectDir);
|
|
127
135
|
readPackageJson(projectDir);
|
|
128
|
-
//
|
|
129
|
-
//
|
|
136
|
+
// A second server for this environment is refused when it opens the state (FeltDB's
|
|
137
|
+
// owner lock across processes, the instance factory within one). Checked here first,
|
|
138
|
+
// from the runtime record, only to answer with the running server even when the
|
|
139
|
+
// sources currently fail to load.
|
|
130
140
|
const owner = readRuntimeRecord(join(projectDir, ".feltkit", "development"));
|
|
131
141
|
if (owner) {
|
|
132
142
|
throw new FeltKitError("DUPLICATE_INSTANCE", `This project's development environment is already running (pid ${owner.pid}) at ${owner.url}.`, {
|
|
@@ -294,7 +304,10 @@ export async function startProduction(options) {
|
|
|
294
304
|
const projectDir = resolve(options.projectDir);
|
|
295
305
|
const project = await loadBundle(join(projectDir, BUILD_DIR, "functions.mjs"));
|
|
296
306
|
const environment = resolveEnvironment({ projectDir, appName: project.app.name, name: options.environment ?? "production" });
|
|
297
|
-
|
|
307
|
+
// Local state is guarded by FeltDB's owner lock when it opens. A FeltDB server has no
|
|
308
|
+
// single-client lock, and FeltKit runs one server per environment, so for remote state
|
|
309
|
+
// the runtime record stays the guard on this host.
|
|
310
|
+
const owner = environment.storage.kind === "remote" ? readRuntimeRecord(environment.runtimeDir) : null;
|
|
298
311
|
if (owner && owner.pid !== process.pid) {
|
|
299
312
|
throw new FeltKitError("DUPLICATE_INSTANCE", `The ${environment.name} environment is already served by pid ${owner.pid} at ${owner.url}.`);
|
|
300
313
|
}
|