@processfocus/runtime-local 0.1.0-next.3 → 0.1.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/authentication-server.mjs +3 -3
- package/dist/{chunk-bg5r4wpv.js → chunk-3wzp2sax.js} +168 -117
- package/dist/{chunk-cbd36jq1.js → chunk-5kjvzbwr.js} +1 -1
- package/dist/{chunk-727y6qkb.js → chunk-egeb4821.js} +2 -2
- package/dist/{chunk-d4ctj079.js → chunk-q5v72erd.js} +2 -2
- package/dist/{chunk-04r0t2mb.js → chunk-wvbz0nmd.js} +97 -49
- package/dist/{chunk-r5s2v669.js → chunk-y8fnwbx0.js} +512 -480
- package/dist/dashboard-source/apps/frontend/app/(protected)/connected-apps/disconnect-form.tsx +57 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/connected-apps/page.tsx +97 -0
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/list-page-client.tsx +26 -1
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/[...listPath]/page.tsx +11 -12
- package/dist/dashboard-source/apps/frontend/app/(protected)/lists/components/list-create-form.tsx +7 -5
- package/dist/dashboard-source/apps/frontend/app/api/dev/import-events/route.ts +69 -1
- package/dist/dashboard-source/apps/frontend/app/app-shell.tsx +4 -3
- package/dist/dashboard-source/apps/frontend/app/mcp/[[...endpoint]]/route.ts +0 -3
- package/dist/dashboard-source/apps/frontend/components/Header.tsx +10 -0
- package/dist/dashboard-source/apps/frontend/lib/collections/collection-provider-factory.tsx +3 -2
- package/dist/dashboard-source/apps/frontend/lib/collections/graphql-stream.ts +21 -1
- package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-query-invalidation.tsx +66 -9
- package/dist/dashboard-source/apps/frontend/lib/dev/import-completed-refresh.ts +10 -6
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/gql.ts +3 -3
- package/dist/dashboard-source/apps/frontend/lib/generated/gql/graphql.ts +2 -3
- package/dist/dashboard-source/apps/frontend/lib/mcp/oauth.ts +61 -72
- package/dist/dashboard-source/apps/frontend/lib/mcp/origin.ts +20 -12
- package/dist/dashboard-source/apps/frontend/lib/mcp/store.ts +80 -166
- package/dist/dashboard-source/apps/frontend/lib/mcp/todos.ts +42 -19
- package/dist/dashboard-source/apps/frontend/package.json +2 -3
- package/dist/dashboard-source/modules/shadcn-components/src/lib/date-time-display.tsx +3 -2
- package/dist/dashboard-source.json +2 -3
- package/dist/graphql-server.mjs +34 -7
- package/dist/job-worker-supervisor.mjs +3 -3
- package/dist/job-worker.mjs +5 -5
- package/dist/main.mjs +7 -2
- package/dist/resources/graphql-schema/system.graphql +1 -0
- package/package.json +3 -4
|
@@ -68,7 +68,7 @@ type Documents = {
|
|
|
68
68
|
"\n query McpListCapabilities($path: String!) {\n listMetadata(listPath: $path) {\n path\n name\n browse { configured authorized }\n detail { configured authorized }\n create { configured authorized }\n update { configured authorized }\n delete { configured authorized }\n configuredProcessStartCount\n authorizedProcessStarts { path name startStepPath }\n }\n }\n": typeof types.McpListCapabilitiesDocument,
|
|
69
69
|
"\n query McpProcessCatalog($page: Int!, $processPath: String) {\n processes(page: $page, limit: 25, processPath: $processPath, requireStartMutation: true) {\n page\n hasNextPage\n nodes { path name category purpose }\n }\n }\n": typeof types.McpProcessCatalogDocument,
|
|
70
70
|
"\n query McpProcessStartForm($processPath: String!, $input: JSON!) {\n processStartForm(processPath: $processPath, input: $input) {\n startStepPath\n mutationName\n inputTypeName\n fields\n defaultValues\n errors\n requiresDashboard\n unconfirmedDefaults\n submissionInput\n }\n }\n": typeof types.McpProcessStartFormDocument,
|
|
71
|
-
"\n query McpActionableTodos($page: Int
|
|
71
|
+
"\n query McpActionableTodos($page: Int!) {\n todos(page: $page, limit: 25, status: \"Actionable\") {\n page\n hasNextPage\n nodes {\n id\n processExecutionId\n processName\n stepName\n stepPath\n status\n priority\n dueAt\n description\n summary { label value }\n }\n }\n }\n": typeof types.McpActionableTodosDocument,
|
|
72
72
|
"\n query McpTodoForm($todoId: ID!, $answers: JSON!) {\n todoChatForm(todoId: $todoId, answers: $answers)\n }\n": typeof types.McpTodoFormDocument,
|
|
73
73
|
"\n mutation McpCompleteTodo($todoId: ID!, $answers: JSON!) {\n completeTodoFromChat(todoId: $todoId, answers: $answers) {\n executionId\n stepPath\n }\n }\n": typeof types.McpCompleteTodoDocument,
|
|
74
74
|
};
|
|
@@ -127,7 +127,7 @@ const documents: Documents = {
|
|
|
127
127
|
"\n query McpListCapabilities($path: String!) {\n listMetadata(listPath: $path) {\n path\n name\n browse { configured authorized }\n detail { configured authorized }\n create { configured authorized }\n update { configured authorized }\n delete { configured authorized }\n configuredProcessStartCount\n authorizedProcessStarts { path name startStepPath }\n }\n }\n": types.McpListCapabilitiesDocument,
|
|
128
128
|
"\n query McpProcessCatalog($page: Int!, $processPath: String) {\n processes(page: $page, limit: 25, processPath: $processPath, requireStartMutation: true) {\n page\n hasNextPage\n nodes { path name category purpose }\n }\n }\n": types.McpProcessCatalogDocument,
|
|
129
129
|
"\n query McpProcessStartForm($processPath: String!, $input: JSON!) {\n processStartForm(processPath: $processPath, input: $input) {\n startStepPath\n mutationName\n inputTypeName\n fields\n defaultValues\n errors\n requiresDashboard\n unconfirmedDefaults\n submissionInput\n }\n }\n": types.McpProcessStartFormDocument,
|
|
130
|
-
"\n query McpActionableTodos($page: Int
|
|
130
|
+
"\n query McpActionableTodos($page: Int!) {\n todos(page: $page, limit: 25, status: \"Actionable\") {\n page\n hasNextPage\n nodes {\n id\n processExecutionId\n processName\n stepName\n stepPath\n status\n priority\n dueAt\n description\n summary { label value }\n }\n }\n }\n": types.McpActionableTodosDocument,
|
|
131
131
|
"\n query McpTodoForm($todoId: ID!, $answers: JSON!) {\n todoChatForm(todoId: $todoId, answers: $answers)\n }\n": types.McpTodoFormDocument,
|
|
132
132
|
"\n mutation McpCompleteTodo($todoId: ID!, $answers: JSON!) {\n completeTodoFromChat(todoId: $todoId, answers: $answers) {\n executionId\n stepPath\n }\n }\n": types.McpCompleteTodoDocument,
|
|
133
133
|
};
|
|
@@ -365,7 +365,7 @@ export function graphql(source: "\n query McpProcessStartForm($processPath: Str
|
|
|
365
365
|
/**
|
|
366
366
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
367
367
|
*/
|
|
368
|
-
export function graphql(source: "\n query McpActionableTodos($page: Int
|
|
368
|
+
export function graphql(source: "\n query McpActionableTodos($page: Int!) {\n todos(page: $page, limit: 25, status: \"Actionable\") {\n page\n hasNextPage\n nodes {\n id\n processExecutionId\n processName\n stepName\n stepPath\n status\n priority\n dueAt\n description\n summary { label value }\n }\n }\n }\n"): (typeof documents)["\n query McpActionableTodos($page: Int!) {\n todos(page: $page, limit: 25, status: \"Actionable\") {\n page\n hasNextPage\n nodes {\n id\n processExecutionId\n processName\n stepName\n stepPath\n status\n priority\n dueAt\n description\n summary { label value }\n }\n }\n }\n"];
|
|
369
369
|
/**
|
|
370
370
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
371
371
|
*/
|
|
@@ -500,11 +500,10 @@ export type McpProcessStartFormQuery = { processStartForm: { startStepPath: stri
|
|
|
500
500
|
|
|
501
501
|
export type McpActionableTodosQueryVariables = Exact<{
|
|
502
502
|
page: number;
|
|
503
|
-
status: string;
|
|
504
503
|
}>;
|
|
505
504
|
|
|
506
505
|
|
|
507
|
-
export type McpActionableTodosQuery = { todos: { page: number, hasNextPage: boolean, nodes: Array<{ id: string, processExecutionId: string, processName: string, stepName: string, status: string, priority: string, dueAt: string | null, description: string, summary: Array<{ label: string, value: string }> }> } };
|
|
506
|
+
export type McpActionableTodosQuery = { todos: { page: number, hasNextPage: boolean, nodes: Array<{ id: string, processExecutionId: string, processName: string, stepName: string, stepPath: string, status: string, priority: string, dueAt: string | null, description: string, summary: Array<{ label: string, value: string }> }> } };
|
|
508
507
|
|
|
509
508
|
export type McpTodoFormQueryVariables = Exact<{
|
|
510
509
|
todoId: string | number;
|
|
@@ -577,6 +576,6 @@ export const McpListsDocument = {"kind":"Document","definitions":[{"kind":"Opera
|
|
|
577
576
|
export const McpListCapabilitiesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"McpListCapabilities"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"path"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"listMetadata"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"listPath"},"value":{"kind":"Variable","name":{"kind":"Name","value":"path"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"browse"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"configured"}},{"kind":"Field","name":{"kind":"Name","value":"authorized"}}]}},{"kind":"Field","name":{"kind":"Name","value":"detail"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"configured"}},{"kind":"Field","name":{"kind":"Name","value":"authorized"}}]}},{"kind":"Field","name":{"kind":"Name","value":"create"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"configured"}},{"kind":"Field","name":{"kind":"Name","value":"authorized"}}]}},{"kind":"Field","name":{"kind":"Name","value":"update"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"configured"}},{"kind":"Field","name":{"kind":"Name","value":"authorized"}}]}},{"kind":"Field","name":{"kind":"Name","value":"delete"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"configured"}},{"kind":"Field","name":{"kind":"Name","value":"authorized"}}]}},{"kind":"Field","name":{"kind":"Name","value":"configuredProcessStartCount"}},{"kind":"Field","name":{"kind":"Name","value":"authorizedProcessStarts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"startStepPath"}}]}}]}}]}}]} as unknown as DocumentNode<McpListCapabilitiesQuery, McpListCapabilitiesQueryVariables>;
|
|
578
577
|
export const McpProcessCatalogDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"McpProcessCatalog"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"page"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"processPath"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"processes"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"page"},"value":{"kind":"Variable","name":{"kind":"Name","value":"page"}}},{"kind":"Argument","name":{"kind":"Name","value":"limit"},"value":{"kind":"IntValue","value":"25"}},{"kind":"Argument","name":{"kind":"Name","value":"processPath"},"value":{"kind":"Variable","name":{"kind":"Name","value":"processPath"}}},{"kind":"Argument","name":{"kind":"Name","value":"requireStartMutation"},"value":{"kind":"BooleanValue","value":true}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"page"}},{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"path"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"category"}},{"kind":"Field","name":{"kind":"Name","value":"purpose"}}]}}]}}]}}]} as unknown as DocumentNode<McpProcessCatalogQuery, McpProcessCatalogQueryVariables>;
|
|
579
578
|
export const McpProcessStartFormDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"McpProcessStartForm"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"processPath"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"JSON"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"processStartForm"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"processPath"},"value":{"kind":"Variable","name":{"kind":"Name","value":"processPath"}}},{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"startStepPath"}},{"kind":"Field","name":{"kind":"Name","value":"mutationName"}},{"kind":"Field","name":{"kind":"Name","value":"inputTypeName"}},{"kind":"Field","name":{"kind":"Name","value":"fields"}},{"kind":"Field","name":{"kind":"Name","value":"defaultValues"}},{"kind":"Field","name":{"kind":"Name","value":"errors"}},{"kind":"Field","name":{"kind":"Name","value":"requiresDashboard"}},{"kind":"Field","name":{"kind":"Name","value":"unconfirmedDefaults"}},{"kind":"Field","name":{"kind":"Name","value":"submissionInput"}}]}}]}}]} as unknown as DocumentNode<McpProcessStartFormQuery, McpProcessStartFormQueryVariables>;
|
|
580
|
-
export const McpActionableTodosDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"McpActionableTodos"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"page"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}
|
|
579
|
+
export const McpActionableTodosDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"McpActionableTodos"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"page"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"todos"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"page"},"value":{"kind":"Variable","name":{"kind":"Name","value":"page"}}},{"kind":"Argument","name":{"kind":"Name","value":"limit"},"value":{"kind":"IntValue","value":"25"}},{"kind":"Argument","name":{"kind":"Name","value":"status"},"value":{"kind":"StringValue","value":"Actionable","block":false}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"page"}},{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"processExecutionId"}},{"kind":"Field","name":{"kind":"Name","value":"processName"}},{"kind":"Field","name":{"kind":"Name","value":"stepName"}},{"kind":"Field","name":{"kind":"Name","value":"stepPath"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"priority"}},{"kind":"Field","name":{"kind":"Name","value":"dueAt"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"summary"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}}]}}]}}]}}]} as unknown as DocumentNode<McpActionableTodosQuery, McpActionableTodosQueryVariables>;
|
|
581
580
|
export const McpTodoFormDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"McpTodoForm"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"todoId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"answers"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"JSON"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"todoChatForm"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"todoId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"todoId"}}},{"kind":"Argument","name":{"kind":"Name","value":"answers"},"value":{"kind":"Variable","name":{"kind":"Name","value":"answers"}}}]}]}}]} as unknown as DocumentNode<McpTodoFormQuery, McpTodoFormQueryVariables>;
|
|
582
581
|
export const McpCompleteTodoDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"McpCompleteTodo"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"todoId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"answers"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"JSON"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"completeTodoFromChat"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"todoId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"todoId"}}},{"kind":"Argument","name":{"kind":"Name","value":"answers"},"value":{"kind":"Variable","name":{"kind":"Name","value":"answers"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"executionId"}},{"kind":"Field","name":{"kind":"Name","value":"stepPath"}}]}}]}}]} as unknown as DocumentNode<McpCompleteTodoMutation, McpCompleteTodoMutationVariables>;
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import "server-only"
|
|
2
2
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto"
|
|
3
|
-
import { Result, Schema } from "effect"
|
|
3
|
+
import { DateTime, Result, Schema } from "effect"
|
|
4
4
|
import { type NextRequest, NextResponse } from "next/server"
|
|
5
5
|
import { type ProviderUserSession, subjects } from "../../../../modules/auth-session/src/index.ts"
|
|
6
6
|
import { type Tokens, createClient } from "../../../../modules/openauth/src/client.ts"
|
|
7
7
|
import { OAuthMetadataFetchError } from "../../../../modules/openauth/src/error.ts"
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
connectedAppsPath,
|
|
10
|
+
consentPath,
|
|
11
|
+
cookieName,
|
|
12
|
+
loopback,
|
|
13
|
+
mcpOrigin,
|
|
14
|
+
opaque,
|
|
15
|
+
} from "./origin.ts"
|
|
9
16
|
import { bucket } from "./store.ts"
|
|
10
17
|
import { getAuthClient } from "@/lib/auth/client"
|
|
11
18
|
import { getFrontendAuthClientConfig } from "@/lib/auth/issuer"
|
|
12
19
|
import { decodeJwtPayload } from "@/lib/auth/jwt"
|
|
13
|
-
import { getCookieNamesFromHost } from "@/lib/auth/session"
|
|
14
20
|
import { acceptVerifiedSession } from "@/lib/auth/ssr-session"
|
|
21
|
+
import { getFrontendManifest } from "@/lib/frontend-manifest-store"
|
|
15
22
|
|
|
16
23
|
const VIEW = "work:read"
|
|
17
24
|
const ACT = "work:act"
|
|
@@ -35,6 +42,7 @@ const Grant = Schema.Struct({
|
|
|
35
42
|
clientId: Schema.String,
|
|
36
43
|
userId: Schema.String,
|
|
37
44
|
scope: Schema.Literals([VIEW, `${VIEW} ${ACT}`]),
|
|
45
|
+
authorisedAt: Schema.Int,
|
|
38
46
|
})
|
|
39
47
|
type Grant = typeof Grant.Type
|
|
40
48
|
const Client = Schema.Struct({
|
|
@@ -390,75 +398,51 @@ const sameOriginForm = (request: Request, origin: string) =>
|
|
|
390
398
|
request.headers.get("content-type")?.split(";")[0] ===
|
|
391
399
|
"application/x-www-form-urlencoded"
|
|
392
400
|
|
|
393
|
-
export const
|
|
394
|
-
|
|
395
|
-
origin
|
|
396
|
-
)
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const login = new URL("/login", origin)
|
|
407
|
-
login.searchParams.set("redirect", path)
|
|
408
|
-
return request.method === "GET"
|
|
409
|
-
? location(login)
|
|
410
|
-
: oauthError("access_denied", 401)
|
|
401
|
+
export const listConnections = async (origin: string, userId: string) => {
|
|
402
|
+
const connections = []
|
|
403
|
+
for await (const { value } of clients(origin).entries()) {
|
|
404
|
+
const grant = value.grants.find((grant) => grant.userId === userId)
|
|
405
|
+
if (grant) {
|
|
406
|
+
connections.push({
|
|
407
|
+
id: grant.id,
|
|
408
|
+
clientId: grant.clientId,
|
|
409
|
+
name: value.name,
|
|
410
|
+
access: grant.scope === VIEW ? "View work" : "View and act",
|
|
411
|
+
authorisedAt: grant.authorisedAt,
|
|
412
|
+
})
|
|
413
|
+
}
|
|
411
414
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
!("email" in session) ||
|
|
415
|
-
!session.humanSession ||
|
|
416
|
-
session.delegation ||
|
|
417
|
-
!(await acceptVerifiedSession(session, token))
|
|
418
|
-
)
|
|
419
|
-
return oauthError("access_denied", 403)
|
|
415
|
+
return connections
|
|
416
|
+
}
|
|
420
417
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
// Revoking it invalidates every credential without touching Dashboard cookies.
|
|
437
|
-
if (
|
|
438
|
-
!(await store.put(
|
|
439
|
-
grant.clientId,
|
|
440
|
-
{ ...client.value, grants },
|
|
441
|
-
grants.length === 0 ? Date.now() + registrationLifetime : undefined,
|
|
442
|
-
client,
|
|
443
|
-
))
|
|
418
|
+
export const disconnectConnection = async ({
|
|
419
|
+
origin,
|
|
420
|
+
userId,
|
|
421
|
+
clientId,
|
|
422
|
+
grantId,
|
|
423
|
+
}: {
|
|
424
|
+
origin: string
|
|
425
|
+
userId: string
|
|
426
|
+
clientId: string
|
|
427
|
+
grantId: string
|
|
428
|
+
}): Promise<boolean> => {
|
|
429
|
+
const client = await registeredClient(origin, clientId)
|
|
430
|
+
if (
|
|
431
|
+
!client?.value.grants.some(
|
|
432
|
+
(grant) => grant.userId === userId && grant.id === grantId,
|
|
444
433
|
)
|
|
445
|
-
|
|
446
|
-
return
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
...headers,
|
|
458
|
-
"Referrer-Policy": "same-origin",
|
|
459
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
460
|
-
},
|
|
461
|
-
},
|
|
434
|
+
)
|
|
435
|
+
return false
|
|
436
|
+
const grants = client.value.grants.filter((grant) => grant.id !== grantId)
|
|
437
|
+
// Codes and tokens check the current grant ID, not just the registration.
|
|
438
|
+
// Revoking it invalidates every credential without touching Dashboard cookies.
|
|
439
|
+
return Boolean(
|
|
440
|
+
await clients(origin).put(
|
|
441
|
+
clientId,
|
|
442
|
+
{ ...client.value, grants },
|
|
443
|
+
grants.length === 0 ? Date.now() + registrationLifetime : undefined,
|
|
444
|
+
client,
|
|
445
|
+
),
|
|
462
446
|
)
|
|
463
447
|
}
|
|
464
448
|
|
|
@@ -570,7 +554,11 @@ export const consent = async (request: NextRequest): Promise<Response> => {
|
|
|
570
554
|
)
|
|
571
555
|
return oauthError("invalid_request")
|
|
572
556
|
if (request.method === "GET") {
|
|
573
|
-
const
|
|
557
|
+
const clientName = escapeHtml(client.value.name)
|
|
558
|
+
const { organisation } = getFrontendManifest()
|
|
559
|
+
const organisationName = escapeHtml(
|
|
560
|
+
organisation.acronym ?? organisation.name,
|
|
561
|
+
)
|
|
574
562
|
const accessDetails = existing
|
|
575
563
|
? `<p>Existing access: ${existing.scope === VIEW ? "View work" : "View and act"}.</p>
|
|
576
564
|
<p class="notice">Reconnecting only restores access. It does not run an interrupted action.</p>`
|
|
@@ -606,7 +594,7 @@ export const consent = async (request: NextRequest): Promise<Response> => {
|
|
|
606
594
|
<header>
|
|
607
595
|
<div class="brand"><span class="mark" aria-hidden="true">PF</span> Process Focus</div>
|
|
608
596
|
<p class="eyebrow">MCP connection</p>
|
|
609
|
-
<h1>${existing ? "Reconnect" : "Connect"} ${
|
|
597
|
+
<h1>${existing ? "Reconnect" : "Connect"} ${clientName} to ${organisationName}?</h1>
|
|
610
598
|
</header>
|
|
611
599
|
<div class="details">
|
|
612
600
|
<p><strong>Environment:</strong> ${escapeHtml(origin)}</p>
|
|
@@ -620,7 +608,7 @@ export const consent = async (request: NextRequest): Promise<Response> => {
|
|
|
620
608
|
<button type="submit" name="action" value="deny">Deny</button>
|
|
621
609
|
</div>
|
|
622
610
|
</form>
|
|
623
|
-
<p class="manage"><a href="
|
|
611
|
+
<p class="manage"><a href="${connectedAppsPath}">Manage MCP connections</a></p>
|
|
624
612
|
</main>
|
|
625
613
|
</body>
|
|
626
614
|
</html>`,
|
|
@@ -664,6 +652,7 @@ export const consent = async (request: NextRequest): Promise<Response> => {
|
|
|
664
652
|
clientId: entry.clientId,
|
|
665
653
|
userId: human.userId,
|
|
666
654
|
scope: choice === "act" ? `${VIEW} ${ACT}` : VIEW,
|
|
655
|
+
authorisedAt: DateTime.toEpochMillis(DateTime.nowUnsafe()),
|
|
667
656
|
}
|
|
668
657
|
if (
|
|
669
658
|
!(await clients(origin).put(
|
|
@@ -6,24 +6,32 @@ export const loopback = (url: URL): boolean =>
|
|
|
6
6
|
!url.username &&
|
|
7
7
|
!url.password
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
const host = request.headers.get("host")
|
|
9
|
+
export const mcpOriginForHost = (host: string | null): string | undefined => {
|
|
10
|
+
if (!host) return undefined
|
|
12
11
|
if (process.env["PF_RUNTIME_MODE"] === "local") {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(`http://${host}`)
|
|
14
|
+
return loopback(url) && host === url.host ? url.origin : undefined
|
|
15
|
+
} catch {
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (process.env["PF_RUNTIME_MODE"] === "deployed") {
|
|
15
20
|
// OpenNext restores Host from CloudFront's viewer-request function.
|
|
16
|
-
// Neither header nor the request URL can choose a different issuer.
|
|
17
21
|
const domain = process.env["PF_MCP_DOMAIN"]
|
|
18
|
-
if (
|
|
19
|
-
return undefined
|
|
20
|
-
} else {
|
|
21
|
-
return undefined
|
|
22
|
+
if (domain && host === domain) return `https://${domain}`
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
return undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const mcpOrigin = (request: Request): string | undefined => {
|
|
28
|
+
const origin = mcpOriginForHost(request.headers.get("host"))
|
|
29
|
+
if (!origin || new URL(request.url).origin !== origin) return undefined
|
|
30
|
+
const requestOrigin = request.headers.get("origin")
|
|
31
|
+
return requestOrigin === null || requestOrigin === origin ? origin : undefined
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
export const connectedAppsPath = "/connected-apps"
|
|
27
35
|
export const consentPath = "/mcp/consent"
|
|
28
36
|
export const opaque = /^[A-Za-z0-9_-]{43}$/
|
|
29
37
|
export const cookieName = (origin: string, id: string): string =>
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import "server-only"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { createHmac } from "node:crypto"
|
|
3
|
+
import { Option, Schema } from "effect"
|
|
4
|
+
import { getGraphqlEndpoint } from "@/lib/graphql/endpoint"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
// only in local mode; every deployed read/write goes through DynamoDB.
|
|
15
|
-
const local: typeof globalThis & {
|
|
16
|
-
pfMcpRecords?: Map<string, Map<string, Stored>>
|
|
17
|
-
} = globalThis
|
|
6
|
+
const path = "/internal/mcp-oauth"
|
|
7
|
+
const Stored = Schema.Struct({
|
|
8
|
+
key: Schema.String,
|
|
9
|
+
revision: Schema.String,
|
|
10
|
+
value: Schema.Unknown,
|
|
11
|
+
})
|
|
12
|
+
const MaybeRecord = Schema.NullOr(Stored)
|
|
13
|
+
const RecordPage = Schema.Array(Stored)
|
|
18
14
|
|
|
15
|
+
type RecordVersion<T> = { revision: string; value: T }
|
|
19
16
|
type Bucket<T> = {
|
|
20
17
|
get(id: string): Promise<RecordVersion<T> | undefined>
|
|
21
18
|
entries(): AsyncIterable<RecordVersion<T>>
|
|
@@ -28,166 +25,83 @@ type Bucket<T> = {
|
|
|
28
25
|
remove(id: string, previous: RecordVersion<T>): Promise<boolean>
|
|
29
26
|
}
|
|
30
27
|
|
|
28
|
+
async function request<A>(
|
|
29
|
+
schema: Schema.Decoder<A>,
|
|
30
|
+
operation: Record<string, unknown>,
|
|
31
|
+
): Promise<A> {
|
|
32
|
+
const deployed = process.env["PF_RUNTIME_MODE"] === "deployed"
|
|
33
|
+
const base = deployed
|
|
34
|
+
? process.env["PF_MCP_STORAGE_ORIGIN"]
|
|
35
|
+
: getGraphqlEndpoint()
|
|
36
|
+
const secret = deployed
|
|
37
|
+
? process.env["PUBLIC_TODO_TOKEN_SECRET"]
|
|
38
|
+
: process.env["PF_MCP_STORAGE_SECRET"]
|
|
39
|
+
if (!base || !secret) throw new Error("MCP OAuth storage is not configured")
|
|
40
|
+
const authorization = createHmac("sha256", secret)
|
|
41
|
+
.update(path)
|
|
42
|
+
.digest("base64url")
|
|
43
|
+
const response = await fetch(new URL(path, base), {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
Authorization: `Bearer ${authorization}`,
|
|
48
|
+
},
|
|
49
|
+
cache: "no-store",
|
|
50
|
+
redirect: "error",
|
|
51
|
+
body: JSON.stringify(operation),
|
|
52
|
+
}).catch(() => undefined)
|
|
53
|
+
if (!response?.ok) throw new Error("MCP OAuth storage unavailable")
|
|
54
|
+
const decoded = Schema.decodeUnknownOption(schema)(
|
|
55
|
+
await response.json().catch(() => undefined),
|
|
56
|
+
)
|
|
57
|
+
if (Option.isNone(decoded))
|
|
58
|
+
throw new Error("Invalid MCP OAuth storage response")
|
|
59
|
+
return decoded.value
|
|
60
|
+
}
|
|
61
|
+
|
|
31
62
|
export function bucket<T>(
|
|
32
63
|
origin: string,
|
|
33
64
|
kind: string,
|
|
34
65
|
schema: Schema.Decoder<T>,
|
|
35
66
|
): Bucket<T> {
|
|
36
67
|
const partition = `${origin}#${kind}`
|
|
37
|
-
const decode = Schema.
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (process.env["PF_RUNTIME_MODE"] !== "deployed") {
|
|
43
|
-
local.pfMcpRecords ??= new Map()
|
|
44
|
-
const records = local.pfMcpRecords
|
|
45
|
-
const data = records.get(partition) ?? new Map<string, Stored>()
|
|
46
|
-
records.set(partition, data)
|
|
47
|
-
const prune = () => {
|
|
48
|
-
for (const [id, value] of data) {
|
|
49
|
-
if (value.expires !== undefined && value.expires <= Date.now())
|
|
50
|
-
data.delete(id)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
get: async (id) => {
|
|
55
|
-
const value = data.get(id)
|
|
56
|
-
return value ? parse(value) : undefined
|
|
57
|
-
},
|
|
58
|
-
async *entries() {
|
|
59
|
-
prune()
|
|
60
|
-
for (const value of data.values()) {
|
|
61
|
-
const record = parse(value)
|
|
62
|
-
if (record) yield record
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
put: async (id, value, expires, previous) => {
|
|
66
|
-
prune()
|
|
67
|
-
if (data.get(id)?.revision !== previous?.revision) return undefined
|
|
68
|
-
const revision = randomUUID()
|
|
69
|
-
data.set(id, { revision, expires, json: JSON.stringify(value) })
|
|
70
|
-
return { revision, value }
|
|
71
|
-
},
|
|
72
|
-
remove: async (id, previous) => {
|
|
73
|
-
prune()
|
|
74
|
-
if (data.get(id)?.revision !== previous.revision) return false
|
|
75
|
-
return data.delete(id)
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const TableName = process.env["PF_MCP_TABLE"]
|
|
81
|
-
if (!TableName) throw new Error("Hosted MCP storage is not configured")
|
|
82
|
-
const keys = { pk: { S: partition } }
|
|
83
|
-
const key = (id: string) => ({ ...keys, sk: { S: id } })
|
|
84
|
-
const read = (item: DdbItem) => {
|
|
85
|
-
const revision = item["revision"]?.S
|
|
86
|
-
const json = item["json"]?.S
|
|
87
|
-
const expires = item["expires"]?.N
|
|
88
|
-
if (!revision || !json) throw new Error("Invalid MCP storage record")
|
|
89
|
-
return parse({
|
|
90
|
-
revision,
|
|
91
|
-
json,
|
|
92
|
-
expires: expires === undefined ? undefined : Number(expires),
|
|
93
|
-
})
|
|
68
|
+
const decode = Schema.decodeUnknownOption(schema)
|
|
69
|
+
const record = ({ value, revision }: typeof Stored.Type) => {
|
|
70
|
+
const decoded = decode(value)
|
|
71
|
+
if (Option.isNone(decoded)) throw new Error("Invalid MCP OAuth record")
|
|
72
|
+
return { revision, value: decoded.value }
|
|
94
73
|
}
|
|
95
74
|
return {
|
|
96
|
-
get: (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const { Item } = yield* db.getItem({
|
|
101
|
-
TableName,
|
|
102
|
-
Key: key(id),
|
|
103
|
-
ConsistentRead: true,
|
|
104
|
-
})
|
|
105
|
-
return Item ? read(Item) : undefined
|
|
106
|
-
}),
|
|
107
|
-
),
|
|
75
|
+
get: async (key) => {
|
|
76
|
+
const row = await request(MaybeRecord, { op: "get", partition, key })
|
|
77
|
+
return row === null ? undefined : record(row)
|
|
78
|
+
},
|
|
108
79
|
async *entries() {
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
cursor = LastEvaluatedKey
|
|
128
|
-
} while (cursor)
|
|
80
|
+
let after: string | undefined
|
|
81
|
+
for (;;) {
|
|
82
|
+
const rows = await request(RecordPage, { op: "list", partition, after })
|
|
83
|
+
for (const row of rows) yield record(row)
|
|
84
|
+
after = rows.at(-1)?.key
|
|
85
|
+
if (rows.length < 100) return
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
put: async (key, value, expires, previous) => {
|
|
89
|
+
const row = await request(MaybeRecord, {
|
|
90
|
+
op: "put",
|
|
91
|
+
partition,
|
|
92
|
+
key,
|
|
93
|
+
value,
|
|
94
|
+
expires,
|
|
95
|
+
previous: previous?.revision,
|
|
96
|
+
})
|
|
97
|
+
return row === null ? undefined : record(row)
|
|
129
98
|
},
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
TableName,
|
|
138
|
-
Item: {
|
|
139
|
-
...key(id),
|
|
140
|
-
revision: { S: revision },
|
|
141
|
-
json: { S: JSON.stringify(value) },
|
|
142
|
-
...(expires === undefined
|
|
143
|
-
? {}
|
|
144
|
-
: {
|
|
145
|
-
expires: { N: String(expires) },
|
|
146
|
-
ttl: { N: String(Math.ceil(expires / 1000)) },
|
|
147
|
-
}),
|
|
148
|
-
},
|
|
149
|
-
ConditionExpression: previous
|
|
150
|
-
? "revision = :revision AND (attribute_not_exists(expires) OR expires > :now)"
|
|
151
|
-
: "attribute_not_exists(pk)",
|
|
152
|
-
...(previous
|
|
153
|
-
? {
|
|
154
|
-
ExpressionAttributeValues: {
|
|
155
|
-
":revision": { S: previous.revision },
|
|
156
|
-
":now": { N: String(Date.now()) },
|
|
157
|
-
},
|
|
158
|
-
}
|
|
159
|
-
: {}),
|
|
160
|
-
})
|
|
161
|
-
.pipe(
|
|
162
|
-
Effect.as({ revision, value }),
|
|
163
|
-
Effect.catchTag("ConditionalCheckFailedException", () =>
|
|
164
|
-
Effect.succeed(undefined),
|
|
165
|
-
),
|
|
166
|
-
)
|
|
167
|
-
}),
|
|
168
|
-
),
|
|
169
|
-
remove: (id, previous) =>
|
|
170
|
-
live.runPromise(
|
|
171
|
-
Effect.gen(function* () {
|
|
172
|
-
const db = yield* DynamoDB
|
|
173
|
-
return yield* db
|
|
174
|
-
.deleteItem({
|
|
175
|
-
TableName,
|
|
176
|
-
Key: key(id),
|
|
177
|
-
ConditionExpression:
|
|
178
|
-
"revision = :revision AND (attribute_not_exists(expires) OR expires > :now)",
|
|
179
|
-
ExpressionAttributeValues: {
|
|
180
|
-
":revision": { S: previous.revision },
|
|
181
|
-
":now": { N: String(Date.now()) },
|
|
182
|
-
},
|
|
183
|
-
})
|
|
184
|
-
.pipe(
|
|
185
|
-
Effect.as(true),
|
|
186
|
-
Effect.catchTag("ConditionalCheckFailedException", () =>
|
|
187
|
-
Effect.succeed(false),
|
|
188
|
-
),
|
|
189
|
-
)
|
|
190
|
-
}),
|
|
191
|
-
),
|
|
99
|
+
remove: (key, previous) =>
|
|
100
|
+
request(Schema.Boolean, {
|
|
101
|
+
op: "remove",
|
|
102
|
+
partition,
|
|
103
|
+
key,
|
|
104
|
+
previous: previous.revision,
|
|
105
|
+
}),
|
|
192
106
|
}
|
|
193
107
|
}
|