@parlor/server 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/access.d.ts +27 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +41 -0
- package/dist/access.js.map +1 -0
- package/dist/actions.d.ts +35 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +159 -0
- package/dist/actions.js.map +1 -0
- package/dist/auth.d.ts +97 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +11 -0
- package/dist/auth.js.map +1 -0
- package/dist/body.d.ts +7 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/body.js +29 -0
- package/dist/body.js.map +1 -0
- package/dist/caller.d.ts +21 -0
- package/dist/caller.d.ts.map +1 -0
- package/dist/caller.js +46 -0
- package/dist/caller.js.map +1 -0
- package/dist/cors.d.ts +9 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/cors.js +25 -0
- package/dist/cors.js.map +1 -0
- package/dist/create-server.d.ts +39 -0
- package/dist/create-server.d.ts.map +1 -0
- package/dist/create-server.js +315 -0
- package/dist/create-server.js.map +1 -0
- package/dist/dev-auth.d.ts +17 -0
- package/dist/dev-auth.d.ts.map +1 -0
- package/dist/dev-auth.js +146 -0
- package/dist/dev-auth.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-calls.d.ts +7 -0
- package/dist/mcp-calls.d.ts.map +1 -0
- package/dist/mcp-calls.js +30 -0
- package/dist/mcp-calls.js.map +1 -0
- package/dist/mcp.d.ts +29 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +198 -0
- package/dist/mcp.js.map +1 -0
- package/dist/migrations.d.ts +10 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +81 -0
- package/dist/migrations.js.map +1 -0
- package/dist/plugin.d.ts +92 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +5 -0
- package/dist/plugin.js.map +1 -0
- package/dist/protocol.d.ts +18 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +7 -0
- package/dist/protocol.js.map +1 -0
- package/dist/revocation-horizon.d.ts +6 -0
- package/dist/revocation-horizon.d.ts.map +1 -0
- package/dist/revocation-horizon.js +6 -0
- package/dist/revocation-horizon.js.map +1 -0
- package/dist/scope.d.ts +6 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +4 -0
- package/dist/scope.js.map +1 -0
- package/package.json +41 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-calls.js","sourceRoot":"","sources":["../src/mcp-calls.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,QAAQ;IACV,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;IAE7D,KAAK,CAAC,GAAG,CACP,OAA4B,EAC5B,EAAa,EACb,OAA+B,EAC/B,IAAyC;QAEzC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACzD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC/B,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAmB,CAAC;QACpE,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACxB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC;gBAAS,CAAC;YACT,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC;gBAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,MAAM,CAAC,OAAgB,EAAE,EAAa,EAAE,MAAe;QACrD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE;YAC7D,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC,CAAC;IACpF,CAAC;CACF;AAED,MAAM,mBAAmB,GAAG,CAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,CAAU,CAAC;AAEvF,MAAM,KAAK,GAAG,CAAC,OAAgB,EAAE,EAAa,EAAU,EAAE,CACxD,IAAI,CAAC,SAAS,CAAC;IACb,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACzE,EAAE;CACH,CAAC,CAAC"}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type McpHttpHandler, type ServerContext } from "@modelcontextprotocol/server";
|
|
2
|
+
import type { AgentOrigin } from "@parlor/agent-ui";
|
|
3
|
+
import { type AgentUi } from "@parlor/agent-ui/server";
|
|
4
|
+
import { type ActionMap } from "@parlor/core";
|
|
5
|
+
import type { ActionRegistry } from "@parlor/core/registry";
|
|
6
|
+
import type { ActionRunner } from "./actions.js";
|
|
7
|
+
import type { CallerResolver } from "./caller.js";
|
|
8
|
+
export interface McpOptions<T extends ActionMap> {
|
|
9
|
+
readonly actions: ActionRegistry<T>;
|
|
10
|
+
readonly runner: ActionRunner;
|
|
11
|
+
readonly name?: string | undefined;
|
|
12
|
+
readonly version?: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Which app these tools belong to, told to every MCP client, so an agent connected to
|
|
15
|
+
* several Parlor apps keeps them apart.
|
|
16
|
+
*/
|
|
17
|
+
readonly app?: {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly description?: string | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
readonly agentUi?: AgentUi | undefined;
|
|
22
|
+
readonly callers?: CallerResolver | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare function appIdentity(app: McpOptions<ActionMap>["app"], origin: string | undefined): string;
|
|
25
|
+
export declare const PROGRESS_INTERVAL_MS = 10000;
|
|
26
|
+
export declare function originOf(ctx: ServerContext): AgentOrigin;
|
|
27
|
+
export declare function withProgress<T>(ctx: ServerContext, work: () => Promise<T>, intervalMs?: number): Promise<T>;
|
|
28
|
+
export declare function createMcpHandler<T extends ActionMap>(options: McpOptions<T>): McpHttpHandler;
|
|
29
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EAGnB,KAAK,aAAa,EAEnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAW,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,KAAK,OAAO,EAAmC,MAAM,yBAAyB,CAAC;AACxF,OAAO,EAGL,KAAK,SAAS,EAGf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,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I_MANIFEST_RESOURCE, UiFailure } from "@parlor/agent-ui/server";
|
|
3
|
+
import { ActionError, isMutating, } from "@parlor/core";
|
|
4
|
+
import { McpCalls } from "./mcp-calls.js";
|
|
5
|
+
/** The public origin first, then the one `parlor dev` serves the app on, then the request's. */
|
|
6
|
+
function appOrigin(request) {
|
|
7
|
+
const configured = process.env.PARLOR_ORIGIN || process.env.PARLOR_WEB_ORIGIN;
|
|
8
|
+
if (configured)
|
|
9
|
+
return new URL(configured).origin;
|
|
10
|
+
return request ? new URL(request.url).origin : undefined;
|
|
11
|
+
}
|
|
12
|
+
export function appIdentity(app, origin) {
|
|
13
|
+
const where = origin ? ` at ${origin}` : "";
|
|
14
|
+
const what = app?.description ? ` ${app.description.trim()}` : "";
|
|
15
|
+
const who = app ? app.name : "this app";
|
|
16
|
+
return `These tools belong to ${who}${where}.${what} They act only on ${who}, as the signed-in user; any other app's tools are a separate server.`;
|
|
17
|
+
}
|
|
18
|
+
function toolResult(result) {
|
|
19
|
+
const text = result === undefined ? "ok" : JSON.stringify(result, null, 2);
|
|
20
|
+
return {
|
|
21
|
+
content: [{ type: "text", text }],
|
|
22
|
+
...(result !== null && typeof result === "object" && !Array.isArray(result)
|
|
23
|
+
? { structuredContent: result }
|
|
24
|
+
: {}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function errorBodyOf(error) {
|
|
28
|
+
if (error instanceof UiFailure)
|
|
29
|
+
return error.error;
|
|
30
|
+
if (error instanceof ActionError) {
|
|
31
|
+
return {
|
|
32
|
+
code: error.code,
|
|
33
|
+
message: error.message,
|
|
34
|
+
...(error.issues
|
|
35
|
+
? {
|
|
36
|
+
issues: error.issues.map((issue) => ({
|
|
37
|
+
path: issue.path.join("."),
|
|
38
|
+
message: issue.message,
|
|
39
|
+
})),
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return { code: "internal", message: "Internal error" };
|
|
45
|
+
}
|
|
46
|
+
function toolError(error) {
|
|
47
|
+
return {
|
|
48
|
+
isError: true,
|
|
49
|
+
content: [
|
|
50
|
+
{ type: "text", text: JSON.stringify({ error: errorBodyOf(error) }, null, 2) },
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The SDK answers bad arguments in plain text before the handler runs. A schema that lists
|
|
56
|
+
* as the original but accepts anything leaves the check to the handler, which fails in the
|
|
57
|
+
* one error body.
|
|
58
|
+
*/
|
|
59
|
+
function unvalidated(schema) {
|
|
60
|
+
return { "~standard": { ...schema["~standard"], validate: (value) => ({ value }) } };
|
|
61
|
+
}
|
|
62
|
+
function actionDescription(action) {
|
|
63
|
+
return action.confirm
|
|
64
|
+
? `${action.description} When an agent calls it, the user must approve it in the app first; the call waits for that answer and fails with declined, confirmation_timeout or confirmation_unavailable without running.`
|
|
65
|
+
: action.description;
|
|
66
|
+
}
|
|
67
|
+
export const PROGRESS_INTERVAL_MS = 10_000;
|
|
68
|
+
async function verifiedOrigin(callers, request, ctx) {
|
|
69
|
+
const caller = callers && request ? await callers(request) : undefined;
|
|
70
|
+
const principal = caller?.principal;
|
|
71
|
+
if (principal?.kind === "agent" && principal.turn) {
|
|
72
|
+
return { via: "agent", name: principal.agent.name };
|
|
73
|
+
}
|
|
74
|
+
if (principal?.kind === "agent" && principal.agent.verified) {
|
|
75
|
+
return { via: "mcp", name: principal.agent.name };
|
|
76
|
+
}
|
|
77
|
+
return originOf(ctx);
|
|
78
|
+
}
|
|
79
|
+
async function turnClientOf(callers, request) {
|
|
80
|
+
const principal = callers && request ? (await callers(request)).principal : undefined;
|
|
81
|
+
return principal?.kind === "agent" && principal.turn
|
|
82
|
+
? { clientId: principal.turn.clientId }
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
85
|
+
export function originOf(ctx) {
|
|
86
|
+
const envelope = ctx.mcpReq.envelope;
|
|
87
|
+
const info = envelope?.[CLIENT_INFO_META_KEY];
|
|
88
|
+
const name = typeof info === "object" && info !== null
|
|
89
|
+
? info.name
|
|
90
|
+
: undefined;
|
|
91
|
+
return typeof name === "string" && name !== "" ? { via: "mcp", name } : { via: "mcp" };
|
|
92
|
+
}
|
|
93
|
+
export async function withProgress(ctx, work, intervalMs = PROGRESS_INTERVAL_MS) {
|
|
94
|
+
const progressToken = ctx.mcpReq._meta?.progressToken;
|
|
95
|
+
if (progressToken === undefined)
|
|
96
|
+
return work();
|
|
97
|
+
let progress = 0;
|
|
98
|
+
const timer = setInterval(() => {
|
|
99
|
+
ctx.mcpReq
|
|
100
|
+
.notify({
|
|
101
|
+
method: "notifications/progress",
|
|
102
|
+
params: {
|
|
103
|
+
progressToken,
|
|
104
|
+
progress: ++progress,
|
|
105
|
+
message: "Waiting for the user to approve in the app",
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
.catch(() => { });
|
|
109
|
+
}, intervalMs);
|
|
110
|
+
try {
|
|
111
|
+
return await work();
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
clearInterval(timer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export function createMcpHandler(options) {
|
|
118
|
+
const { actions, runner, agentUi, callers, app, name = app?.name ?? "parlor", version = "0.0.0", } = options;
|
|
119
|
+
const calls = new McpCalls();
|
|
120
|
+
const inCall = (ctx, toolCtx, work) => calls.run(ctx.requestInfo, toolCtx.mcpReq.id, [...(ctx.requestInfo ? [ctx.requestInfo.signal] : []), toolCtx.mcpReq.signal], work);
|
|
121
|
+
const factory = (ctx) => {
|
|
122
|
+
const instructions = [
|
|
123
|
+
appIdentity(app, appOrigin(ctx.requestInfo)),
|
|
124
|
+
agentUi?.instructions("mcp"),
|
|
125
|
+
]
|
|
126
|
+
.filter(Boolean)
|
|
127
|
+
.join("\n\n");
|
|
128
|
+
const server = new McpServer({ name, version, ...(app ? { title: app.name } : {}) }, { instructions });
|
|
129
|
+
server.server.setNotificationHandler("notifications/cancelled", (notification) => {
|
|
130
|
+
const { requestId, reason } = notification.params;
|
|
131
|
+
if (ctx.requestInfo && requestId !== undefined)
|
|
132
|
+
calls.cancel(ctx.requestInfo, requestId, reason);
|
|
133
|
+
});
|
|
134
|
+
for (const actionName of actions.names()) {
|
|
135
|
+
const action = actions.get(actionName);
|
|
136
|
+
if (!action)
|
|
137
|
+
continue;
|
|
138
|
+
server.registerTool(actionName, {
|
|
139
|
+
description: actionDescription(action),
|
|
140
|
+
inputSchema: unvalidated(action.input),
|
|
141
|
+
annotations: { readOnlyHint: !isMutating(action) },
|
|
142
|
+
}, async (args, toolCtx) => {
|
|
143
|
+
try {
|
|
144
|
+
const origin = await verifiedOrigin(callers, ctx.requestInfo, toolCtx);
|
|
145
|
+
const result = await inCall(ctx, toolCtx, (signal) => {
|
|
146
|
+
const run = () => runner.run(actionName, args, ctx.requestInfo, "mcp", { signal, origin });
|
|
147
|
+
return action.confirm ? withProgress(toolCtx, run) : run();
|
|
148
|
+
});
|
|
149
|
+
return toolResult(result.data);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return toolError(error);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const uiTools = agentUi?.tools("mcp") ?? [];
|
|
157
|
+
const uiManifest = uiTools.length > 0 ? agentUi?.manifest() : undefined;
|
|
158
|
+
if (uiManifest) {
|
|
159
|
+
server.registerResource("ui-manifest", UI_MANIFEST_RESOURCE, {
|
|
160
|
+
description: "The app's pages and the views they show, with full JSON schemas for each view's value.",
|
|
161
|
+
mimeType: "application/json",
|
|
162
|
+
}, (uri) => ({
|
|
163
|
+
contents: [
|
|
164
|
+
{
|
|
165
|
+
uri: uri.href,
|
|
166
|
+
mimeType: "application/json",
|
|
167
|
+
text: JSON.stringify(uiManifest, null, 2),
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
for (const tool of uiTools) {
|
|
173
|
+
server.registerTool(tool.name, {
|
|
174
|
+
description: tool.description,
|
|
175
|
+
inputSchema: unvalidated(tool.input),
|
|
176
|
+
annotations: { readOnlyHint: tool.readOnly },
|
|
177
|
+
}, async (args, toolCtx) => {
|
|
178
|
+
try {
|
|
179
|
+
const input = tool.input.safeParse(args);
|
|
180
|
+
if (!input.success) {
|
|
181
|
+
throw new ActionError("invalid_input", `Invalid input for "${tool.name}"`, {
|
|
182
|
+
issues: input.error.issues,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return toolResult(await inCall(ctx, toolCtx, async (signal) => tool.run(input.data, await agentUi.contextFor(ctx.requestInfo, await verifiedOrigin(callers, ctx.requestInfo, toolCtx), signal, await turnClientOf(callers, ctx.requestInfo)))));
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (!(error instanceof UiFailure))
|
|
189
|
+
console.error("[parlor] UI tool failed:", error);
|
|
190
|
+
return toolError(error);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return server;
|
|
195
|
+
};
|
|
196
|
+
return createSdkHandler(factory);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,IAAI,gBAAgB,EAGpC,SAAS,GAGV,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAgB,oBAAoB,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,EACL,WAAW,EAIX,UAAU,GACX,MAAM,cAAc,CAAC;AAKtB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAkB1C,gGAAgG;AAChG,SAAS,SAAS,CAAC,OAA4B;IAC7C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,i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AG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAC1C,IAAI,CAAC,GAAG,CACN,KAAK,CAAC,IAAI,EACV,MAAM,OAAQ,CAAC,UAAU,CACvB,GAAG,CAAC,WAAW,EACf,MAAM,cAAc,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,EACvD,MAAM,EACN,MAAM,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,CAC7C,CACF,CACF,CACF,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,CAAC,KAAK,YAAY,SAAS,CAAC;wBAC/B,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;oBACnD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DataProvider } from "@parlor/core";
|
|
2
|
+
import type { ServerPlugin } from "./plugin.js";
|
|
3
|
+
export declare function checkMigrations(plugin: ServerPlugin): void;
|
|
4
|
+
/**
|
|
5
|
+
* PGlite refuses several commands in one prepared statement, so a migration is run one
|
|
6
|
+
* statement at a time. Quotes, comments and dollar-quoted bodies may hold semicolons.
|
|
7
|
+
*/
|
|
8
|
+
export declare function splitStatements(script: string): string[];
|
|
9
|
+
export declare function applyMigrations(database: DataProvider, plugins: readonly ServerPlugin[]): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAS1D;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CA+BxD;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,SAAS,YAAY,EAAE,GAC/B,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
const MIGRATION_LOCK_KEY = 7_311_208;
|
|
3
|
+
export function checkMigrations(plugin) {
|
|
4
|
+
const seen = new Set();
|
|
5
|
+
for (const { id } of plugin.migrations ?? []) {
|
|
6
|
+
if (!id.startsWith(`${plugin.name}/`)) {
|
|
7
|
+
throw new Error(`Migration "${id}" must start with "${plugin.name}/".`);
|
|
8
|
+
}
|
|
9
|
+
if (seen.has(id))
|
|
10
|
+
throw new Error(`Migration "${id}" is listed twice.`);
|
|
11
|
+
seen.add(id);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const DOLLAR_TAG = /^\$[A-Za-z_]*\$/;
|
|
15
|
+
/**
|
|
16
|
+
* PGlite refuses several commands in one prepared statement, so a migration is run one
|
|
17
|
+
* statement at a time. Quotes, comments and dollar-quoted bodies may hold semicolons.
|
|
18
|
+
*/
|
|
19
|
+
export function splitStatements(script) {
|
|
20
|
+
const statements = [];
|
|
21
|
+
let start = 0;
|
|
22
|
+
let at = 0;
|
|
23
|
+
const skipTo = (end) => {
|
|
24
|
+
const close = script.indexOf(end, at);
|
|
25
|
+
at = close === -1 ? script.length : close + end.length;
|
|
26
|
+
};
|
|
27
|
+
while (at < script.length) {
|
|
28
|
+
const char = script[at];
|
|
29
|
+
if (char === "'" || char === '"') {
|
|
30
|
+
at += 1;
|
|
31
|
+
skipTo(char);
|
|
32
|
+
}
|
|
33
|
+
else if (script.startsWith("--", at)) {
|
|
34
|
+
skipTo("\n");
|
|
35
|
+
}
|
|
36
|
+
else if (script.startsWith("/*", at)) {
|
|
37
|
+
skipTo("*/");
|
|
38
|
+
}
|
|
39
|
+
else if (char === "$" && DOLLAR_TAG.test(script.slice(at))) {
|
|
40
|
+
const tag = DOLLAR_TAG.exec(script.slice(at))[0];
|
|
41
|
+
at += tag.length;
|
|
42
|
+
skipTo(tag);
|
|
43
|
+
}
|
|
44
|
+
else if (char === ";") {
|
|
45
|
+
statements.push(script.slice(start, at));
|
|
46
|
+
at += 1;
|
|
47
|
+
start = at;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
at += 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
statements.push(script.slice(start));
|
|
54
|
+
return statements.map((statement) => statement.trim()).filter(Boolean);
|
|
55
|
+
}
|
|
56
|
+
export async function applyMigrations(database, plugins) {
|
|
57
|
+
const migrations = plugins.flatMap((plugin) => plugin.migrations ?? []);
|
|
58
|
+
if (migrations.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
await database.transaction(async (handle) => {
|
|
61
|
+
const tx = handle;
|
|
62
|
+
await tx.execute(sql `select pg_advisory_xact_lock(${MIGRATION_LOCK_KEY})`);
|
|
63
|
+
await tx.execute(sql `
|
|
64
|
+
create table if not exists parlor_migrations (
|
|
65
|
+
id text primary key,
|
|
66
|
+
applied_at timestamptz not null default now()
|
|
67
|
+
)`);
|
|
68
|
+
const result = (await tx.execute(sql `select id from parlor_migrations`));
|
|
69
|
+
const rows = Array.isArray(result) ? result : (result.rows ?? []);
|
|
70
|
+
const applied = new Set(rows.map((row) => row.id));
|
|
71
|
+
for (const migration of migrations) {
|
|
72
|
+
if (applied.has(migration.id))
|
|
73
|
+
continue;
|
|
74
|
+
for (const statement of splitStatements(migration.sql)) {
|
|
75
|
+
await tx.execute(sql.raw(statement));
|
|
76
|
+
}
|
|
77
|
+
await tx.execute(sql `insert into parlor_migrations (id) values (${migration.id})`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAOlC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC,MAAM,UAAU,eAAe,CAAC,MAAoB;IAClD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,EAAE,EAAE,EAAE,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;QAC7C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,cAAc,EAAE,sBAAsB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC;QACxE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACtC,EAAE,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MA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AAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;YACvC,CAAC;YACD,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,8CAA8C,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;QACrF,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ActionErrorCode, ActionSource, AuthenticatedPrincipal, DataProvider, Principal, Tag } from "@parlor/core";
|
|
2
|
+
import type { ActionRegistry } from "@parlor/core/registry";
|
|
3
|
+
import type { ServerChannel } from "@parlor/sync";
|
|
4
|
+
import type { CallerOf } from "./access.js";
|
|
5
|
+
import type { AuthProvider } from "./auth.js";
|
|
6
|
+
import type { Caller } from "./caller.js";
|
|
7
|
+
/**
|
|
8
|
+
* A framework feature the app installs with `createServer({ plugins })`. It owns the
|
|
9
|
+
* tables prefixed `parlor_<name>_` and every path under `/_parlor/<name>/`.
|
|
10
|
+
*/
|
|
11
|
+
export interface ServerPlugin {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly migrations?: readonly Migration[] | undefined;
|
|
14
|
+
setup(host: PluginHost): PluginRuntime;
|
|
15
|
+
}
|
|
16
|
+
/** Applied once per database in list order. An applied id must never change. */
|
|
17
|
+
export interface Migration {
|
|
18
|
+
readonly id: `${string}/${number}_${string}`;
|
|
19
|
+
readonly sql: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PluginRuntime {
|
|
22
|
+
/**
|
|
23
|
+
* Served at `POST /_parlor/<plugin>/actions/<action>` through the same runner as the app's
|
|
24
|
+
* actions, but never listed on MCP and never callable by an agent.
|
|
25
|
+
*/
|
|
26
|
+
readonly actions?: ActionRegistry | undefined;
|
|
27
|
+
readonly channel?: ServerChannel | undefined;
|
|
28
|
+
readonly routes?: readonly AnyPluginRoute[] | undefined;
|
|
29
|
+
/** Called once per action call on every surface after it settles, whatever the outcome. */
|
|
30
|
+
audit?(record: ActionAudit): void;
|
|
31
|
+
/** Runs before `close()` awaits in-flight requests, so it must end what it holds open. */
|
|
32
|
+
close?(): void | Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export interface ActionAudit {
|
|
35
|
+
readonly at: number;
|
|
36
|
+
readonly action: string;
|
|
37
|
+
readonly principal: Principal;
|
|
38
|
+
readonly source: ActionSource;
|
|
39
|
+
readonly scope: string;
|
|
40
|
+
/** SHA-256 of the input as received; the input itself is not kept. */
|
|
41
|
+
readonly inputDigest: string;
|
|
42
|
+
/** `ran` once `run` started; `refused` when the call stopped before it. */
|
|
43
|
+
readonly stage: "refused" | "ran";
|
|
44
|
+
readonly outcome: "ok" | "cancelled" | ActionErrorCode;
|
|
45
|
+
readonly confirmation?: ConfirmationAnswer | undefined;
|
|
46
|
+
}
|
|
47
|
+
export type ConfirmationAnswer = "approved" | "declined" | "timeout" | "unavailable";
|
|
48
|
+
type SignedInKind = AuthenticatedPrincipal["kind"];
|
|
49
|
+
/**
|
|
50
|
+
* A plain route with no transaction or sync event. `access` decides who may call it and
|
|
51
|
+
* types the caller its handler receives. An anonymous caller is admitted only when `access`
|
|
52
|
+
* lists it and no enforcing auth provider is installed.
|
|
53
|
+
*/
|
|
54
|
+
export interface PluginRoute<K extends SignedInKind | "anonymous"> {
|
|
55
|
+
readonly method: "GET" | "POST";
|
|
56
|
+
readonly path: `/${string}`;
|
|
57
|
+
readonly access: readonly K[];
|
|
58
|
+
handle(request: Request, caller: CallerOf<K>): Promise<Response>;
|
|
59
|
+
}
|
|
60
|
+
/** Callable by anyone, signed in or not: sign-in pages, OAuth endpoints. */
|
|
61
|
+
export interface PublicPluginRoute {
|
|
62
|
+
readonly method: "GET" | "POST";
|
|
63
|
+
/** Absolute when it starts with `/.well-known/`. */
|
|
64
|
+
readonly path: `/${string}`;
|
|
65
|
+
readonly access: "public";
|
|
66
|
+
handle(request: Request): Promise<Response>;
|
|
67
|
+
}
|
|
68
|
+
export type AnyPluginRoute = PluginRoute<SignedInKind | "anonymous"> | PublicPluginRoute;
|
|
69
|
+
/** Infers `K` from `access`, so the handler's caller type follows the list. */
|
|
70
|
+
export declare function pluginRoute<const K extends SignedInKind | "anonymous">(route: PluginRoute<K>): PluginRoute<K>;
|
|
71
|
+
export interface PluginHost {
|
|
72
|
+
readonly basePath: string;
|
|
73
|
+
readonly database: DataProvider | undefined;
|
|
74
|
+
/** The installed auth provider, for plugins that mint or look up credentials (chat). */
|
|
75
|
+
readonly auth?: AuthProvider | undefined;
|
|
76
|
+
/** `createServer` got an `auth` key whose value is undefined: a sign-in setup that failed to configure. */
|
|
77
|
+
readonly authMisconfigured?: boolean;
|
|
78
|
+
callerOf(request: Request): Promise<Caller>;
|
|
79
|
+
/**
|
|
80
|
+
* Resolves once the database holds every plugin's tables. Work a plugin starts on its own,
|
|
81
|
+
* such as a timer, waits for it; request handlers need not, as the server awaits it first.
|
|
82
|
+
*/
|
|
83
|
+
ready?(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Records a sync event for writes made outside an action's transaction, such as through
|
|
86
|
+
* a library that holds its own connection. With `tx`, the event commits with that
|
|
87
|
+
* transaction instead of its own. Does nothing when sync is off.
|
|
88
|
+
*/
|
|
89
|
+
announce(scope: string, tags: readonly Tag[], tx?: unknown): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,YAAY,EACZ,SAAS,EACT,GAAG,EACJ,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KA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AW,CAAC,CAAC,CAAC,CAEhB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IAC5C,wFAAwF;IACxF,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACzC,2GAA2G;IAC3G,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C;;;OAGG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAsFA,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CACzB,KAAqB;IAErB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UiManifest } from "@parlor/agent-ui";
|
|
2
|
+
import type { ActionDescriptor } from "@parlor/core/registry";
|
|
3
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
4
|
+
export declare const DEFAULT_BASE_PATH = "/_parlor";
|
|
5
|
+
export declare const SOURCE_HEADER = "x-parlor-source";
|
|
6
|
+
export declare const CLIENT_HEADER = "x-parlor-client";
|
|
7
|
+
/** A native shell reads its bearer session from this response header after signing in. */
|
|
8
|
+
export declare const SESSION_TOKEN_HEADER = "set-auth-token";
|
|
9
|
+
export interface Manifest {
|
|
10
|
+
readonly protocol: typeof PROTOCOL_VERSION;
|
|
11
|
+
/** What a pairing host shows locally; filled once the server knows the app's name. */
|
|
12
|
+
readonly app?: {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
} | undefined;
|
|
15
|
+
readonly actions: readonly ActionDescriptor[];
|
|
16
|
+
readonly ui?: UiManifest | undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAC/C,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAC/C,0FAA0F;AAC1F,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AAErD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,gBAAgB,CAAC;IAC3C,sFAAsF;IACtF,QAAQ,CAAC,GAAG,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC9C,QAAQ,CAAC,EAAE,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACtC"}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const PROTOCOL_VERSION = 1;
|
|
2
|
+
export const DEFAULT_BASE_PATH = "/_parlor";
|
|
3
|
+
export const SOURCE_HEADER = "x-parlor-source";
|
|
4
|
+
export const CLIENT_HEADER = "x-parlor-client";
|
|
5
|
+
/** A native shell reads its bearer session from this response header after signing in. */
|
|
6
|
+
export const SESSION_TOKEN_HEADER = "set-auth-token";
|
|
7
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAC/C,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAC/C,0FAA0F;AAC1F,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long a revocation is remembered. Whatever it revokes must stop verifying within
|
|
3
|
+
* this long, or the revocation is forgotten while the credential still works.
|
|
4
|
+
*/
|
|
5
|
+
export declare const REVOCATION_HORIZON_MS: number;
|
|
6
|
+
//# sourceMappingURL=revocation-horizon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revocation-horizon.d.ts","sourceRoot":"","sources":["../src/revocation-horizon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAc,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long a revocation is remembered. Whatever it revokes must stop verifying within
|
|
3
|
+
* this long, or the revocation is forgotten while the credential still works.
|
|
4
|
+
*/
|
|
5
|
+
export const REVOCATION_HORIZON_MS = 11 * 60_000;
|
|
6
|
+
//# sourceMappingURL=revocation-horizon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revocation-horizon.js","sourceRoot":"","sources":["../src/revocation-horizon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,MAAM,CAAC"}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Principal } from "@parlor/core";
|
|
2
|
+
/** The tenant a request belongs to. Called once per request. */
|
|
3
|
+
export type ScopeResolver = (request: Request, principal: Principal) => string | Promise<string>;
|
|
4
|
+
export declare const DEFAULT_SCOPE = "default";
|
|
5
|
+
export declare const defaultScope: ScopeResolver;
|
|
6
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,cAAc,CAAC;AAEtD,gEAAgE;AAChE,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,KACjB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9B,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,eAAO,MAAM,YAAY,EAAE,aACS,CAAC"}
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,cAAc,CAAC;AAQtD,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC,MAAM,CAAC,MAAM,YAAY,GAAkB,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,CACjE,MAAM,CAAC,SAAS,CAAC,IAAI,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parlor/server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"homepage": "https://cychien.github.io/parlor",
|
|
5
|
+
"bugs": "https://github.com/cychien/parlor/issues",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/cychien/parlor.git",
|
|
10
|
+
"directory": "packages/server"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@modelcontextprotocol/server": "^2.3.1",
|
|
24
|
+
"drizzle-orm": "^0.45.4",
|
|
25
|
+
"h3": "^2.0.1",
|
|
26
|
+
"zod": "^4.6.5",
|
|
27
|
+
"@parlor/agent-ui": "0.1.0",
|
|
28
|
+
"@parlor/core": "0.1.0",
|
|
29
|
+
"@parlor/sync": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@modelcontextprotocol/client": "^2.3.1",
|
|
33
|
+
"@types/node": "^24.14.0",
|
|
34
|
+
"srvx": "^1.0.5",
|
|
35
|
+
"typescript": "^7.0.2",
|
|
36
|
+
"vitest": "^5.0.3",
|
|
37
|
+
"@parlor/data": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
|
+
"test": "vitest run"
|
|
43
|
+
}
|
|
6
44
|
}
|