@pikku/cli 0.7.7 → 0.8.1
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/CHANGELOG.md +43 -0
- package/bin/pikku-all.ts +188 -91
- package/bin/pikku-fetch.ts +10 -38
- package/bin/pikku-nextjs.ts +12 -113
- package/bin/pikku-openapi.ts +9 -54
- package/bin/pikku-queue-service.ts +28 -0
- package/bin/pikku-schemas.ts +6 -32
- package/bin/pikku-websocket.ts +11 -41
- package/bin/pikku.ts +2 -0
- package/cli.schema.json +113 -10
- package/dist/bin/pikku-all.d.ts +1 -1
- package/dist/bin/pikku-all.js +105 -84
- package/dist/bin/pikku-fetch.d.ts +1 -3
- package/dist/bin/pikku-fetch.js +9 -15
- package/dist/bin/pikku-nextjs.d.ts +1 -4
- package/dist/bin/pikku-nextjs.js +10 -40
- package/dist/bin/pikku-openapi.d.ts +0 -3
- package/dist/bin/pikku-openapi.js +8 -24
- package/dist/bin/pikku-queue-service.d.ts +4 -0
- package/dist/bin/pikku-queue-service.js +19 -0
- package/dist/bin/pikku-schemas.d.ts +0 -3
- package/dist/bin/pikku-schemas.js +5 -11
- package/dist/bin/pikku-websocket.d.ts +1 -3
- package/dist/bin/pikku-websocket.js +9 -18
- package/dist/bin/pikku.js +2 -0
- package/dist/src/events/channels/pikku-channels.d.ts +2 -0
- package/dist/src/events/channels/pikku-channels.js +9 -0
- package/dist/src/events/channels/pikku-command-channels-map.d.ts +2 -0
- package/dist/src/events/channels/pikku-command-channels-map.js +8 -0
- package/dist/src/events/channels/pikku-command-channels.d.ts +2 -0
- package/dist/src/events/channels/pikku-command-channels.js +9 -0
- package/dist/src/events/channels/pikku-command-websocket-typed.d.ts +2 -0
- package/dist/src/events/channels/pikku-command-websocket-typed.js +15 -0
- package/dist/src/{serialize-typed-channel-map.js → events/channels/serialize-typed-channel-map.js} +2 -2
- package/dist/src/events/fetch/index.d.ts +2 -0
- package/dist/src/events/fetch/index.js +12 -0
- package/dist/src/events/functions/pikku-command-function-types.d.ts +2 -0
- package/dist/src/events/functions/pikku-command-function-types.js +13 -0
- package/dist/src/events/functions/pikku-command-functions.d.ts +6 -0
- package/dist/src/events/functions/pikku-command-functions.js +35 -0
- package/dist/src/events/functions/pikku-command-services.d.ts +3 -0
- package/dist/src/events/functions/pikku-command-services.js +73 -0
- package/dist/src/events/functions/pikku-function-types.d.ts +2 -0
- package/dist/{bin → src/events/functions}/pikku-function-types.js +6 -6
- package/dist/src/events/functions/pikku-functions.d.ts +6 -0
- package/dist/{bin → src/events/functions}/pikku-functions.js +5 -5
- package/dist/src/events/http/pikku-command-http-map.d.ts +2 -0
- package/dist/src/events/http/pikku-command-http-map.js +8 -0
- package/dist/src/events/http/pikku-command-http-routes.d.ts +2 -0
- package/dist/src/events/http/pikku-command-http-routes.js +9 -0
- package/dist/src/events/http/pikku-command-openapi.d.ts +2 -0
- package/dist/src/events/http/pikku-command-openapi.js +20 -0
- package/dist/src/events/http/pikku-http-routes.d.ts +2 -0
- package/dist/src/events/http/pikku-http-routes.js +9 -0
- package/dist/src/{serialize-typed-http-map.d.ts → events/http/serialize-typed-http-map.d.ts} +0 -1
- package/dist/src/{serialize-typed-http-map.js → events/http/serialize-typed-http-map.js} +2 -15
- package/dist/src/events/mcp/pikku-command-mcp-json.d.ts +2 -0
- package/dist/src/events/mcp/pikku-command-mcp-json.js +13 -0
- package/dist/src/events/mcp/pikku-command-mcp.d.ts +2 -0
- package/dist/src/events/mcp/pikku-command-mcp.js +54 -0
- package/dist/src/events/mcp/serialize-mcp-json.d.ts +5 -0
- package/dist/src/events/mcp/serialize-mcp-json.js +101 -0
- package/dist/src/events/queue/pikku-command-queue-map.d.ts +2 -0
- package/dist/src/events/queue/pikku-command-queue-map.js +8 -0
- package/dist/src/events/queue/pikku-command-queue-service.d.ts +2 -0
- package/dist/src/events/queue/pikku-command-queue-service.js +12 -0
- package/dist/src/events/queue/pikku-command-queue.d.ts +2 -0
- package/dist/src/events/queue/pikku-command-queue.js +10 -0
- package/dist/src/events/queue/pikku-queue-map.d.ts +2 -0
- package/dist/src/events/queue/pikku-queue-map.js +8 -0
- package/dist/src/events/queue/pikku-queue.d.ts +2 -0
- package/dist/src/events/queue/pikku-queue.js +10 -0
- package/dist/src/events/queue/serialize-queue-map.d.ts +4 -0
- package/dist/src/events/queue/serialize-queue-map.js +77 -0
- package/dist/src/events/queue/serialize-queue-meta.d.ts +2 -0
- package/dist/src/events/queue/serialize-queue-meta.js +6 -0
- package/dist/src/events/queue/serialize-queue-wrapper.d.ts +1 -0
- package/dist/src/events/queue/serialize-queue-wrapper.js +35 -0
- package/dist/src/events/rpc/pikku-command-rpc-client.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc-client.js +12 -0
- package/dist/src/events/rpc/pikku-command-rpc-map.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc-map.js +8 -0
- package/dist/src/events/rpc/pikku-command-rpc.d.ts +2 -0
- package/dist/src/events/rpc/pikku-command-rpc.js +6 -0
- package/dist/src/events/rpc/pikku-rpc.d.ts +2 -0
- package/dist/src/events/rpc/pikku-rpc.js +6 -0
- package/dist/src/events/rpc/serialize-rpc-wrapper.d.ts +1 -0
- package/dist/src/events/rpc/serialize-rpc-wrapper.js +29 -0
- package/dist/src/{serialize-typed-rpc-map.d.ts → events/rpc/serialize-typed-rpc-map.d.ts} +1 -1
- package/dist/src/{serialize-typed-rpc-map.js → events/rpc/serialize-typed-rpc-map.js} +3 -3
- package/dist/src/events/scheduler/pikku-command-scheduler.d.ts +2 -0
- package/dist/src/events/scheduler/pikku-command-scheduler.js +10 -0
- package/dist/src/inspector-glob.d.ts +1 -1
- package/dist/src/inspector-glob.js +4 -4
- package/dist/src/pikku-cli-config.d.ts +12 -2
- package/dist/src/pikku-cli-config.js +79 -30
- package/dist/src/pikku-command-schemas.d.ts +2 -0
- package/dist/src/pikku-command-schemas.js +8 -0
- package/dist/src/runtimes/nextjs/pikku-command-nextjs.d.ts +2 -0
- package/dist/src/runtimes/nextjs/pikku-command-nextjs.js +36 -0
- package/dist/src/schema-generator.d.ts +3 -2
- package/dist/src/schema-generator.js +9 -9
- package/dist/src/schemas.d.ts +2 -0
- package/dist/src/schemas.js +8 -0
- package/dist/src/{utils/serialize-import-map.js → serialize-import-map.js} +3 -0
- package/dist/src/serialize-pikku-types.js +378 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.js +1 -0
- package/dist/src/{utils/utils.d.ts → utils.d.ts} +20 -7
- package/dist/src/{utils/utils.js → utils.js} +56 -32
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/{bin → src/events/channels}/pikku-channels.ts +8 -3
- package/src/events/channels/pikku-command-channels-map.ts +26 -0
- package/src/events/channels/pikku-command-channels.ts +38 -0
- package/src/events/channels/pikku-command-websocket-typed.ts +36 -0
- package/src/{serialize-typed-channel-map.ts → events/channels/serialize-typed-channel-map.ts} +2 -2
- package/src/events/fetch/index.ts +33 -0
- package/src/events/functions/pikku-command-function-types.ts +48 -0
- package/src/events/functions/pikku-command-functions.ts +84 -0
- package/src/events/functions/pikku-command-services.ts +125 -0
- package/{bin → src/events/functions}/pikku-function-types.ts +12 -15
- package/{bin → src/events/functions}/pikku-functions.ts +9 -6
- package/src/events/http/pikku-command-http-map.ts +27 -0
- package/src/events/http/pikku-command-http-routes.ts +40 -0
- package/src/events/http/pikku-command-openapi.ts +54 -0
- package/{bin → src/events/http}/pikku-http-routes.ts +8 -3
- package/src/{serialize-typed-http-map.ts → events/http/serialize-typed-http-map.ts} +2 -19
- package/src/events/mcp/pikku-command-mcp-json.ts +33 -0
- package/src/events/mcp/pikku-command-mcp.ts +110 -0
- package/src/events/mcp/serialize-mcp-json.ts +159 -0
- package/src/events/queue/pikku-command-queue-map.ts +26 -0
- package/src/events/queue/pikku-command-queue-service.ts +33 -0
- package/src/events/queue/pikku-command-queue.ts +42 -0
- package/src/events/queue/pikku-queue-map.ts +26 -0
- package/src/events/queue/pikku-queue.ts +40 -0
- package/src/events/queue/serialize-queue-map.ts +119 -0
- package/src/events/queue/serialize-queue-meta.ts +10 -0
- package/src/events/queue/serialize-queue-wrapper.ts +35 -0
- package/src/events/rpc/pikku-command-rpc-client.ts +33 -0
- package/src/events/rpc/pikku-command-rpc-map.ts +26 -0
- package/src/events/rpc/pikku-command-rpc.ts +22 -0
- package/{bin → src/events/rpc}/pikku-rpc.ts +8 -6
- package/src/events/rpc/serialize-rpc-wrapper.ts +29 -0
- package/src/{serialize-typed-rpc-map.ts → events/rpc/serialize-typed-rpc-map.ts} +5 -4
- package/{bin/pikku-scheduler.ts → src/events/scheduler/pikku-command-scheduler.ts} +11 -8
- package/src/inspector-glob.ts +4 -2
- package/src/pikku-cli-config.ts +119 -42
- package/src/pikku-command-schemas.ts +33 -0
- package/src/runtimes/nextjs/pikku-command-nextjs.ts +110 -0
- package/src/schema-generator.ts +10 -5
- package/src/schemas.ts +33 -0
- package/src/{utils/serialize-import-map.ts → serialize-import-map.ts} +5 -0
- package/src/serialize-pikku-types.ts +378 -1
- package/src/types.ts +16 -0
- package/src/{utils/utils.ts → utils.ts} +68 -34
- package/tsconfig.json +1 -1
- package/bin/pikku-channels-map.ts +0 -25
- package/bin/pikku-http-map.ts +0 -26
- package/bin/pikku-nextjs.test.ts +0 -279
- package/bin/pikku-rpc-map.ts +0 -25
- package/dist/bin/pikku-channels-map.d.ts +0 -3
- package/dist/bin/pikku-channels-map.js +0 -8
- package/dist/bin/pikku-channels.d.ts +0 -3
- package/dist/bin/pikku-channels.js +0 -9
- package/dist/bin/pikku-function-types.d.ts +0 -4
- package/dist/bin/pikku-functions.d.ts +0 -7
- package/dist/bin/pikku-http-map.d.ts +0 -3
- package/dist/bin/pikku-http-map.js +0 -8
- package/dist/bin/pikku-http-routes.d.ts +0 -3
- package/dist/bin/pikku-http-routes.js +0 -9
- package/dist/bin/pikku-rpc-map.d.ts +0 -3
- package/dist/bin/pikku-rpc-map.js +0 -8
- package/dist/bin/pikku-rpc.d.ts +0 -3
- package/dist/bin/pikku-rpc.js +0 -6
- package/dist/bin/pikku-scheduler.d.ts +0 -3
- package/dist/bin/pikku-scheduler.js +0 -10
- /package/dist/src/{serialize-typed-channel-map.d.ts → events/channels/serialize-typed-channel-map.d.ts} +0 -0
- /package/dist/src/{serialize-websocket-wrapper.d.ts → events/channels/serialize-websocket-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-websocket-wrapper.js → events/channels/serialize-websocket-wrapper.js} +0 -0
- /package/dist/src/{openapi-spec-generator.d.ts → events/http/openapi-spec-generator.d.ts} +0 -0
- /package/dist/src/{openapi-spec-generator.js → events/http/openapi-spec-generator.js} +0 -0
- /package/dist/src/{serialize-fetch-wrapper.d.ts → events/http/serialize-fetch-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-fetch-wrapper.js → events/http/serialize-fetch-wrapper.js} +0 -0
- /package/dist/src/{serialize-scheduler-meta.d.ts → events/scheduler/serialize-scheduler-meta.d.ts} +0 -0
- /package/dist/src/{serialize-scheduler-meta.js → events/scheduler/serialize-scheduler-meta.js} +0 -0
- /package/dist/src/{serialize-nextjs-backend-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-nextjs-backend-wrapper.js → runtimes/nextjs/serialize-nextjs-backend-wrapper.js} +0 -0
- /package/dist/src/{serialize-nextjs-http-wrapper.d.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.d.ts} +0 -0
- /package/dist/src/{serialize-nextjs-http-wrapper.js → runtimes/nextjs/serialize-nextjs-http-wrapper.js} +0 -0
- /package/dist/src/{utils/serialize-import-map.d.ts → serialize-import-map.d.ts} +0 -0
- /package/src/{serialize-websocket-wrapper.ts → events/channels/serialize-websocket-wrapper.ts} +0 -0
- /package/src/{openapi-spec-generator.ts → events/http/openapi-spec-generator.ts} +0 -0
- /package/src/{serialize-fetch-wrapper.ts → events/http/serialize-fetch-wrapper.ts} +0 -0
- /package/src/{serialize-scheduler-meta.ts → events/scheduler/serialize-scheduler-meta.ts} +0 -0
- /package/src/{serialize-nextjs-backend-wrapper.ts → runtimes/nextjs/serialize-nextjs-backend-wrapper.ts} +0 -0
- /package/src/{serialize-nextjs-http-wrapper.ts → runtimes/nextjs/serialize-nextjs-http-wrapper.ts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
|
|
2
|
+
import { generateSchemas } from '../../schema-generator.js'
|
|
3
|
+
import { generateOpenAPISpec } from './openapi-spec-generator.js'
|
|
4
|
+
import { stringify } from 'yaml'
|
|
5
|
+
import { PikkuCommand } from '../../types.js'
|
|
6
|
+
|
|
7
|
+
export const pikkuOpenAPI: PikkuCommand = async (
|
|
8
|
+
logger,
|
|
9
|
+
{ tsconfig, openAPI },
|
|
10
|
+
{ http, functions }
|
|
11
|
+
) => {
|
|
12
|
+
return await logCommandInfoAndTime(
|
|
13
|
+
logger,
|
|
14
|
+
'Creating OpenAPI spec',
|
|
15
|
+
'Created OpenAPI spec',
|
|
16
|
+
[openAPI?.outputFile === undefined, 'openAPI outfile is not defined'],
|
|
17
|
+
async () => {
|
|
18
|
+
if (!openAPI?.outputFile) {
|
|
19
|
+
throw new Error('openAPI is required')
|
|
20
|
+
}
|
|
21
|
+
const schemas = await generateSchemas(
|
|
22
|
+
logger,
|
|
23
|
+
tsconfig,
|
|
24
|
+
functions.typesMap,
|
|
25
|
+
functions.meta,
|
|
26
|
+
http.meta
|
|
27
|
+
)
|
|
28
|
+
const openAPISpec = await generateOpenAPISpec(
|
|
29
|
+
functions.meta,
|
|
30
|
+
http.meta,
|
|
31
|
+
schemas,
|
|
32
|
+
openAPI.additionalInfo
|
|
33
|
+
)
|
|
34
|
+
if (openAPI.outputFile.endsWith('.json')) {
|
|
35
|
+
await writeFileInDir(
|
|
36
|
+
logger,
|
|
37
|
+
openAPI.outputFile,
|
|
38
|
+
JSON.stringify(openAPISpec, null, 2),
|
|
39
|
+
{ ignoreModifyComment: true }
|
|
40
|
+
)
|
|
41
|
+
} else if (
|
|
42
|
+
openAPI.outputFile.endsWith('.yaml') ||
|
|
43
|
+
openAPI.outputFile.endsWith('.yml')
|
|
44
|
+
) {
|
|
45
|
+
await writeFileInDir(
|
|
46
|
+
logger,
|
|
47
|
+
openAPI.outputFile,
|
|
48
|
+
stringify(openAPISpec),
|
|
49
|
+
{ ignoreModifyComment: true }
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { PikkuCLIConfig } from '
|
|
1
|
+
import { PikkuCLIConfig } from '../../pikku-cli-config.js'
|
|
2
2
|
import { InspectorState } from '@pikku/inspector'
|
|
3
3
|
import {
|
|
4
4
|
logCommandInfoAndTime,
|
|
5
5
|
serializeFileImports,
|
|
6
6
|
writeFileInDir,
|
|
7
|
-
} from '
|
|
7
|
+
} from '../../utils.js'
|
|
8
|
+
import { PikkuCommand } from '../../types.js'
|
|
8
9
|
|
|
9
|
-
export const pikkuHTTP = async (
|
|
10
|
+
export const pikkuHTTP: PikkuCommand = async (
|
|
11
|
+
logger,
|
|
10
12
|
cliConfig: PikkuCLIConfig,
|
|
11
13
|
visitState: InspectorState
|
|
12
14
|
) => {
|
|
13
15
|
return await logCommandInfoAndTime(
|
|
16
|
+
logger,
|
|
14
17
|
'Finding HTTP routes',
|
|
15
18
|
'Found HTTP routes',
|
|
16
19
|
[visitState.http.files.size === 0],
|
|
@@ -18,6 +21,7 @@ export const pikkuHTTP = async (
|
|
|
18
21
|
const { httpRoutesFile, httpRoutesMetaFile, packageMappings } = cliConfig
|
|
19
22
|
const { http } = visitState
|
|
20
23
|
await writeFileInDir(
|
|
24
|
+
logger,
|
|
21
25
|
httpRoutesFile,
|
|
22
26
|
serializeFileImports(
|
|
23
27
|
'addHTTPRoute',
|
|
@@ -27,6 +31,7 @@ export const pikkuHTTP = async (
|
|
|
27
31
|
)
|
|
28
32
|
)
|
|
29
33
|
await writeFileInDir(
|
|
34
|
+
logger,
|
|
30
35
|
httpRoutesMetaFile,
|
|
31
36
|
`import { pikkuState } from '@pikku/core'\npikkuState('http', 'meta', ${JSON.stringify(http.meta, null, 2)})`
|
|
32
37
|
)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HTTPRoutesMeta } from '@pikku/core/http'
|
|
2
|
-
import { serializeImportMap } from '
|
|
2
|
+
import { serializeImportMap } from '../../serialize-import-map.js'
|
|
3
3
|
import { MetaInputTypes, TypesMap } from '@pikku/inspector'
|
|
4
4
|
import { FunctionsMeta } from '@pikku/core'
|
|
5
|
+
import { generateCustomTypes } from '../../utils.js'
|
|
5
6
|
|
|
6
7
|
export const serializeTypedRoutesMap = (
|
|
7
8
|
relativeToPath: string,
|
|
@@ -54,24 +55,6 @@ export type RoutesWithMethod<Method extends string> = {
|
|
|
54
55
|
`
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
export function generateCustomTypes(
|
|
58
|
-
typesMap: TypesMap,
|
|
59
|
-
requiredTypes: Set<string>
|
|
60
|
-
) {
|
|
61
|
-
return `
|
|
62
|
-
// Custom types are those that are defined directly within generics
|
|
63
|
-
// or are broken into simpler types
|
|
64
|
-
${Array.from(typesMap.customTypes.entries())
|
|
65
|
-
.map(([name, { type, references }]) => {
|
|
66
|
-
references.forEach((name) => {
|
|
67
|
-
const originalName = typesMap.getTypeMeta(name).originalName
|
|
68
|
-
requiredTypes.add(originalName)
|
|
69
|
-
})
|
|
70
|
-
return `export type ${name} = ${type}`
|
|
71
|
-
})
|
|
72
|
-
.join('\n')}`
|
|
73
|
-
}
|
|
74
|
-
|
|
75
58
|
function generateRoutes(
|
|
76
59
|
routesMeta: HTTPRoutesMeta,
|
|
77
60
|
functionsMeta: FunctionsMeta,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
|
|
2
|
+
import { serializeMCPJson } from './serialize-mcp-json.js'
|
|
3
|
+
import { PikkuCommand } from '../../types.js'
|
|
4
|
+
|
|
5
|
+
export const pikkuMCPJSON: PikkuCommand = async (
|
|
6
|
+
logger,
|
|
7
|
+
{ mcpJsonFile, schemaDirectory },
|
|
8
|
+
{ mcpEndpoints, functions }
|
|
9
|
+
) => {
|
|
10
|
+
return await logCommandInfoAndTime(
|
|
11
|
+
logger,
|
|
12
|
+
'Generating MCP JSON',
|
|
13
|
+
'Generated MCP JSON',
|
|
14
|
+
[mcpEndpoints.files.size === 0 || !mcpJsonFile],
|
|
15
|
+
async () => {
|
|
16
|
+
// Generate MCP JSON file
|
|
17
|
+
if (mcpJsonFile) {
|
|
18
|
+
const mcpJson = await serializeMCPJson(
|
|
19
|
+
logger,
|
|
20
|
+
schemaDirectory,
|
|
21
|
+
functions.meta,
|
|
22
|
+
functions.typesMap,
|
|
23
|
+
mcpEndpoints.resourcesMeta,
|
|
24
|
+
mcpEndpoints.toolsMeta,
|
|
25
|
+
mcpEndpoints.promptsMeta
|
|
26
|
+
)
|
|
27
|
+
await writeFileInDir(logger, mcpJsonFile, mcpJson, {
|
|
28
|
+
ignoreModifyComment: true,
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logCommandInfoAndTime,
|
|
3
|
+
serializeFileImports,
|
|
4
|
+
writeFileInDir,
|
|
5
|
+
} from '../../utils.js'
|
|
6
|
+
import { PikkuCommand } from '../../types.js'
|
|
7
|
+
import { readFile } from 'fs/promises'
|
|
8
|
+
import { join } from 'path'
|
|
9
|
+
|
|
10
|
+
// Helper function to generate arguments from schema
|
|
11
|
+
const generateArgumentsFromSchema = async (
|
|
12
|
+
inputSchema: string | null,
|
|
13
|
+
schemaDirectory: string,
|
|
14
|
+
typesMap: any,
|
|
15
|
+
logger: any
|
|
16
|
+
): Promise<Array<{ name: string; description: string; required: boolean }>> => {
|
|
17
|
+
if (!inputSchema) return []
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
['boolean', 'string', 'number', 'null', 'undefined', 'void'].includes(
|
|
21
|
+
inputSchema
|
|
22
|
+
)
|
|
23
|
+
) {
|
|
24
|
+
return []
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const uniqueName = typesMap.getUniqueName(inputSchema)
|
|
28
|
+
if (!uniqueName) return []
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const schemaPath = join(
|
|
32
|
+
schemaDirectory,
|
|
33
|
+
'schemas',
|
|
34
|
+
`${uniqueName}.schema.json`
|
|
35
|
+
)
|
|
36
|
+
const schemaContent = await readFile(schemaPath, 'utf-8')
|
|
37
|
+
const schema = JSON.parse(schemaContent)
|
|
38
|
+
|
|
39
|
+
const argumentsArray: Array<{
|
|
40
|
+
name: string
|
|
41
|
+
description: string
|
|
42
|
+
required: boolean
|
|
43
|
+
}> = []
|
|
44
|
+
if (schema && typeof schema === 'object' && schema.properties) {
|
|
45
|
+
const properties = schema.properties as Record<string, any>
|
|
46
|
+
const required = (schema.required as string[]) || []
|
|
47
|
+
|
|
48
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
49
|
+
argumentsArray.push({
|
|
50
|
+
name: propName,
|
|
51
|
+
description: propSchema.description || `${propName} parameter`,
|
|
52
|
+
required: required.includes(propName),
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return argumentsArray
|
|
57
|
+
} catch (e) {
|
|
58
|
+
logger.warn(`Could not load schema for type: ${uniqueName}`)
|
|
59
|
+
return []
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const pikkuMCP: PikkuCommand = async (
|
|
64
|
+
logger,
|
|
65
|
+
{ mcpEndpointsFile, mcpEndpointsMetaFile, packageMappings, schemaDirectory },
|
|
66
|
+
{ mcpEndpoints, functions }
|
|
67
|
+
) => {
|
|
68
|
+
return await logCommandInfoAndTime(
|
|
69
|
+
logger,
|
|
70
|
+
'Finding MCP endpoints',
|
|
71
|
+
'Found MCP endpoints',
|
|
72
|
+
[mcpEndpoints.files.size === 0],
|
|
73
|
+
async () => {
|
|
74
|
+
await writeFileInDir(
|
|
75
|
+
logger,
|
|
76
|
+
mcpEndpointsFile,
|
|
77
|
+
serializeFileImports(
|
|
78
|
+
'addMCPResource or addMCPTool',
|
|
79
|
+
mcpEndpointsFile,
|
|
80
|
+
mcpEndpoints.files,
|
|
81
|
+
packageMappings
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
// Populate arguments for prompts meta before serializing
|
|
86
|
+
const promptsMetaWithArguments = { ...mcpEndpoints.promptsMeta }
|
|
87
|
+
for (const promptMeta of Object.values(promptsMetaWithArguments)) {
|
|
88
|
+
const functionMeta = functions.meta[promptMeta.pikkuFuncName]
|
|
89
|
+
if (functionMeta) {
|
|
90
|
+
const inputType = functionMeta.inputs?.[0]
|
|
91
|
+
promptMeta.arguments = await generateArgumentsFromSchema(
|
|
92
|
+
inputType || null,
|
|
93
|
+
schemaDirectory || '',
|
|
94
|
+
functions.typesMap,
|
|
95
|
+
logger
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
await writeFileInDir(
|
|
101
|
+
logger,
|
|
102
|
+
mcpEndpointsMetaFile,
|
|
103
|
+
`import { pikkuState } from '@pikku/core'
|
|
104
|
+
pikkuState('mcp', 'resourcesMeta', ${JSON.stringify(mcpEndpoints.resourcesMeta, null, 2)})
|
|
105
|
+
pikkuState('mcp', 'toolsMeta', ${JSON.stringify(mcpEndpoints.toolsMeta, null, 2)})
|
|
106
|
+
pikkuState('mcp', 'promptsMeta', ${JSON.stringify(promptsMetaWithArguments, null, 2)})`
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core'
|
|
4
|
+
import { FunctionsMeta, JSONValue } from '@pikku/core'
|
|
5
|
+
import { TypesMap } from '@pikku/inspector'
|
|
6
|
+
import { CLILogger } from '../../utils.js'
|
|
7
|
+
|
|
8
|
+
interface MCPEndpoint {
|
|
9
|
+
name: string
|
|
10
|
+
description?: string
|
|
11
|
+
parameters?: JSONValue
|
|
12
|
+
returns?: JSONValue
|
|
13
|
+
streaming?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const serializeMCPJson = async (
|
|
17
|
+
logger: CLILogger,
|
|
18
|
+
schemaDirectory: string,
|
|
19
|
+
functionsMeta: FunctionsMeta,
|
|
20
|
+
typesMap: TypesMap,
|
|
21
|
+
mcpResourceMeta: MCPResourceMeta,
|
|
22
|
+
mcpToolMeta: MCPToolMeta,
|
|
23
|
+
mcpPromptMeta: MCPPromptMeta
|
|
24
|
+
): Promise<string> => {
|
|
25
|
+
const tools: MCPEndpoint[] = []
|
|
26
|
+
const resources: MCPEndpoint[] = []
|
|
27
|
+
const prompts: any[] = []
|
|
28
|
+
|
|
29
|
+
// Helper function to load schema from file
|
|
30
|
+
const loadSchema = async (
|
|
31
|
+
typeName: string | undefined
|
|
32
|
+
): Promise<JSONValue | undefined> => {
|
|
33
|
+
if (
|
|
34
|
+
!typeName ||
|
|
35
|
+
['boolean', 'string', 'number', 'null', 'undefined', 'void'].includes(
|
|
36
|
+
typeName
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const uniqueName = typesMap.getUniqueName(typeName)
|
|
43
|
+
if (!uniqueName) {
|
|
44
|
+
return undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const schemaPath = join(
|
|
49
|
+
schemaDirectory,
|
|
50
|
+
'schemas',
|
|
51
|
+
`${uniqueName}.schema.json`
|
|
52
|
+
)
|
|
53
|
+
const schemaContent = await readFile(schemaPath, 'utf-8')
|
|
54
|
+
return JSON.parse(schemaContent)
|
|
55
|
+
} catch (e) {
|
|
56
|
+
logger.warn(`Could not load schema for type: ${uniqueName}`)
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Process MCP resources
|
|
62
|
+
for (const [name, endpointMeta] of Object.entries(mcpResourceMeta)) {
|
|
63
|
+
const functionMeta = functionsMeta[endpointMeta.pikkuFuncName]
|
|
64
|
+
if (!functionMeta) {
|
|
65
|
+
logger.warn(
|
|
66
|
+
`Function ${endpointMeta.pikkuFuncName} not found in functionsMeta. Skipping resource ${name}.`
|
|
67
|
+
)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const inputType = functionMeta.inputs?.[0]
|
|
72
|
+
const outputType = functionMeta.outputs?.[0]
|
|
73
|
+
|
|
74
|
+
const parameters = await loadSchema(inputType)
|
|
75
|
+
const returns = await loadSchema(outputType)
|
|
76
|
+
|
|
77
|
+
const endpoint = {
|
|
78
|
+
uri: name,
|
|
79
|
+
name,
|
|
80
|
+
description: endpointMeta.description,
|
|
81
|
+
...(parameters && { parameters }),
|
|
82
|
+
...(returns && { returns }),
|
|
83
|
+
...(endpointMeta.streaming && { streaming: true }),
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
resources.push(endpoint)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Process MCP tools
|
|
90
|
+
for (const [name, endpointMeta] of Object.entries(mcpToolMeta)) {
|
|
91
|
+
const functionMeta = functionsMeta[endpointMeta.pikkuFuncName]
|
|
92
|
+
if (!functionMeta) {
|
|
93
|
+
logger.warn(
|
|
94
|
+
`Function ${endpointMeta.pikkuFuncName} not found in functionsMeta. Skipping tool ${name}.`
|
|
95
|
+
)
|
|
96
|
+
continue
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const inputType = functionMeta.inputs?.[0]
|
|
100
|
+
const outputType = functionMeta.outputs?.[0]
|
|
101
|
+
|
|
102
|
+
const parameters = await loadSchema(inputType)
|
|
103
|
+
const returns = await loadSchema(outputType)
|
|
104
|
+
|
|
105
|
+
const endpoint = {
|
|
106
|
+
name,
|
|
107
|
+
description: endpointMeta.description,
|
|
108
|
+
...(parameters && { parameters }),
|
|
109
|
+
...(returns && { returns }),
|
|
110
|
+
...(endpointMeta.streaming && { streaming: true }),
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
tools.push(endpoint)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Process MCP prompts
|
|
117
|
+
for (const [name, endpointMeta] of Object.entries(mcpPromptMeta)) {
|
|
118
|
+
const functionMeta = functionsMeta[endpointMeta.pikkuFuncName]
|
|
119
|
+
if (!functionMeta) {
|
|
120
|
+
logger.warn(
|
|
121
|
+
`Function ${endpointMeta.pikkuFuncName} not found in functionsMeta. Skipping prompt ${name}.`
|
|
122
|
+
)
|
|
123
|
+
continue
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const inputType = functionMeta.inputs?.[0]
|
|
127
|
+
// TODO: this needs to be a json schema type, not any
|
|
128
|
+
const inputSchema: any = await loadSchema(inputType)
|
|
129
|
+
|
|
130
|
+
// Generate arguments from input schema
|
|
131
|
+
const argumentsArray: any[] = []
|
|
132
|
+
if (
|
|
133
|
+
inputSchema &&
|
|
134
|
+
typeof inputSchema === 'object' &&
|
|
135
|
+
inputSchema.properties
|
|
136
|
+
) {
|
|
137
|
+
const properties = inputSchema.properties as Record<string, any>
|
|
138
|
+
const required = (inputSchema.required as string[]) || []
|
|
139
|
+
|
|
140
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
141
|
+
argumentsArray.push({
|
|
142
|
+
name: propName,
|
|
143
|
+
description: propSchema.description || `${propName} parameter`,
|
|
144
|
+
required: required.includes(propName),
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const prompt = {
|
|
150
|
+
name,
|
|
151
|
+
description: endpointMeta.description,
|
|
152
|
+
arguments: argumentsArray,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
prompts.push(prompt)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return JSON.stringify({ tools, resources, prompts }, null, 2)
|
|
159
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
|
|
2
|
+
import { serializeQueueMap } from './serialize-queue-map.js'
|
|
3
|
+
import { PikkuCommand } from '../../types.js'
|
|
4
|
+
|
|
5
|
+
export const pikkuQueueMap: PikkuCommand = async (
|
|
6
|
+
logger,
|
|
7
|
+
{ queueMapDeclarationFile, packageMappings },
|
|
8
|
+
{ queueWorkers, functions }
|
|
9
|
+
) => {
|
|
10
|
+
return await logCommandInfoAndTime(
|
|
11
|
+
logger,
|
|
12
|
+
'Creating Queue map',
|
|
13
|
+
'Created Queue map',
|
|
14
|
+
[queueWorkers.files.size === 0],
|
|
15
|
+
async () => {
|
|
16
|
+
const content = serializeQueueMap(
|
|
17
|
+
queueMapDeclarationFile,
|
|
18
|
+
packageMappings,
|
|
19
|
+
functions.typesMap,
|
|
20
|
+
functions.meta,
|
|
21
|
+
queueWorkers.meta
|
|
22
|
+
)
|
|
23
|
+
await writeFileInDir(logger, queueMapDeclarationFile, content)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { serializeQueueWrapper } from './serialize-queue-wrapper.js'
|
|
2
|
+
import {
|
|
3
|
+
getFileImportRelativePath,
|
|
4
|
+
logCommandInfoAndTime,
|
|
5
|
+
writeFileInDir,
|
|
6
|
+
} from '../../utils.js'
|
|
7
|
+
import { PikkuCommandWithoutState } from '../../types.js'
|
|
8
|
+
|
|
9
|
+
export const pikkuQueueService: PikkuCommandWithoutState = async (
|
|
10
|
+
logger,
|
|
11
|
+
{ queueFile, queueMapDeclarationFile, packageMappings }
|
|
12
|
+
) => {
|
|
13
|
+
return await logCommandInfoAndTime(
|
|
14
|
+
logger,
|
|
15
|
+
'Generating queue service wrapper',
|
|
16
|
+
'Generated queue service wrapper',
|
|
17
|
+
[queueFile === undefined, "queueFile isn't set in the pikku config"],
|
|
18
|
+
async () => {
|
|
19
|
+
if (!queueFile) {
|
|
20
|
+
throw new Error("queueFile is isn't set in the pikku config")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const queueMapDeclarationPath = getFileImportRelativePath(
|
|
24
|
+
queueFile,
|
|
25
|
+
queueMapDeclarationFile,
|
|
26
|
+
packageMappings
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const content = [serializeQueueWrapper(queueMapDeclarationPath)]
|
|
30
|
+
await writeFileInDir(logger, queueFile, content.join('\n'))
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { PikkuCLIConfig } from '../../pikku-cli-config.js'
|
|
2
|
+
import { InspectorState } from '@pikku/inspector'
|
|
3
|
+
import {
|
|
4
|
+
logCommandInfoAndTime,
|
|
5
|
+
serializeFileImports,
|
|
6
|
+
writeFileInDir,
|
|
7
|
+
} from '../../utils.js'
|
|
8
|
+
import { serializeQueueMeta } from './serialize-queue-meta.js'
|
|
9
|
+
import { PikkuCommand } from '../../types.js'
|
|
10
|
+
|
|
11
|
+
export const pikkuQueue: PikkuCommand = async (
|
|
12
|
+
logger,
|
|
13
|
+
cliConfig: PikkuCLIConfig,
|
|
14
|
+
visitState: InspectorState
|
|
15
|
+
) => {
|
|
16
|
+
return await logCommandInfoAndTime(
|
|
17
|
+
logger,
|
|
18
|
+
'Finding queues',
|
|
19
|
+
'Found queue',
|
|
20
|
+
[visitState.queueWorkers.files.size === 0],
|
|
21
|
+
async () => {
|
|
22
|
+
const { queueWorkersFile, queueWorkersMetaFile, packageMappings } =
|
|
23
|
+
cliConfig
|
|
24
|
+
const { queueWorkers } = visitState
|
|
25
|
+
await writeFileInDir(
|
|
26
|
+
logger,
|
|
27
|
+
queueWorkersMetaFile,
|
|
28
|
+
serializeQueueMeta(queueWorkers.meta)
|
|
29
|
+
)
|
|
30
|
+
await writeFileInDir(
|
|
31
|
+
logger,
|
|
32
|
+
queueWorkersFile,
|
|
33
|
+
serializeFileImports(
|
|
34
|
+
'addQueueWorkers',
|
|
35
|
+
queueWorkersFile,
|
|
36
|
+
queueWorkers.files,
|
|
37
|
+
packageMappings
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { logCommandInfoAndTime, writeFileInDir } from '../../utils.js'
|
|
2
|
+
import { serializeQueueMap } from './serialize-queue-map.js'
|
|
3
|
+
import { PikkuCommand } from '../../types.js'
|
|
4
|
+
|
|
5
|
+
export const pikkuQueueMap: PikkuCommand = async (
|
|
6
|
+
logger,
|
|
7
|
+
{ queueMapDeclarationFile, packageMappings },
|
|
8
|
+
{ queueWorkers, functions }
|
|
9
|
+
) => {
|
|
10
|
+
return await logCommandInfoAndTime(
|
|
11
|
+
logger,
|
|
12
|
+
'Creating Queue map',
|
|
13
|
+
'Created Queue map',
|
|
14
|
+
[queueWorkers.files.size === 0],
|
|
15
|
+
async () => {
|
|
16
|
+
const content = serializeQueueMap(
|
|
17
|
+
queueMapDeclarationFile,
|
|
18
|
+
packageMappings,
|
|
19
|
+
functions.typesMap,
|
|
20
|
+
functions.meta,
|
|
21
|
+
queueWorkers.meta
|
|
22
|
+
)
|
|
23
|
+
await writeFileInDir(logger, queueMapDeclarationFile, content)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logCommandInfoAndTime,
|
|
3
|
+
serializeFileImports,
|
|
4
|
+
writeFileInDir,
|
|
5
|
+
} from '../../utils.js'
|
|
6
|
+
import { serializeQueueMeta } from './serialize-queue-meta.js'
|
|
7
|
+
import { PikkuCommand } from '../../types.js'
|
|
8
|
+
|
|
9
|
+
export const pikkuQueue: PikkuCommand = async (
|
|
10
|
+
logger,
|
|
11
|
+
cliConfig,
|
|
12
|
+
visitState
|
|
13
|
+
) => {
|
|
14
|
+
return await logCommandInfoAndTime(
|
|
15
|
+
logger,
|
|
16
|
+
'Finding queues',
|
|
17
|
+
'Found queue',
|
|
18
|
+
[visitState.queueWorkers.files.size === 0],
|
|
19
|
+
async () => {
|
|
20
|
+
const { queueWorkersFile, queueWorkersMetaFile, packageMappings } =
|
|
21
|
+
cliConfig
|
|
22
|
+
const { queueWorkers } = visitState
|
|
23
|
+
await writeFileInDir(
|
|
24
|
+
logger,
|
|
25
|
+
queueWorkersMetaFile,
|
|
26
|
+
serializeQueueMeta(queueWorkers.meta)
|
|
27
|
+
)
|
|
28
|
+
await writeFileInDir(
|
|
29
|
+
logger,
|
|
30
|
+
queueWorkersFile,
|
|
31
|
+
serializeFileImports(
|
|
32
|
+
'addQueueWorkers',
|
|
33
|
+
queueWorkersFile,
|
|
34
|
+
queueWorkers.files,
|
|
35
|
+
packageMappings
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
}
|