chore: server-and-serverless template

This commit is contained in:
e2e
2026-06-28 17:35:09 +02:00
commit 73f8ded296
202 changed files with 9063 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
{
"agentRoutes": {
"basePath": "",
"tags": [
"pikku:public"
],
"auth": false,
"routes": {
"agentRun": {
"auth": null,
"contentType": null,
"method": "post",
"route": "/rpc/agent/:agentName",
"sse": null,
"timeout": null,
"func": {
"pikkuFuncId": "agentCaller"
}
},
"agentStream": {
"auth": null,
"contentType": null,
"method": "post",
"route": "/rpc/agent/:agentName/stream",
"sse": true,
"timeout": null,
"func": {
"pikkuFuncId": "agentStreamCaller"
}
},
"agentApprove": {
"auth": null,
"contentType": null,
"method": "post",
"route": "/rpc/agent/:agentName/approve",
"sse": null,
"timeout": null,
"func": {
"pikkuFuncId": "agentApproveCaller"
}
},
"agentResume": {
"auth": null,
"contentType": null,
"method": "post",
"route": "/rpc/agent/:agentName/resume",
"sse": true,
"timeout": null,
"func": {
"pikkuFuncId": "agentResumeCaller"
}
}
}
},
"consoleRoutes": {
"basePath": "",
"tags": [],
"auth": false,
"routes": {
"workflowRunStream": {
"auth": null,
"contentType": null,
"method": "get",
"route": "/workflow-run/:runId/stream",
"sse": true,
"timeout": null,
"func": {
"pikkuFuncId": "console:streamWorkflowRun",
"packageName": "@pikku/addon-console"
}
},
"functionTestsStream": {
"auth": null,
"contentType": null,
"method": "get",
"route": "/function-tests/stream",
"sse": true,
"timeout": null,
"func": {
"pikkuFuncId": "console:streamFunctionTests",
"packageName": "@pikku/addon-console"
}
}
}
}
}

View File

@@ -0,0 +1,5 @@
/**
* This file was generated by @pikku/cli@0.12.48
*/
import contractsMeta from './pikku-http-contracts-meta.gen.json' with { type: 'json' }
export default contractsMeta

View File

@@ -0,0 +1,147 @@
/**
* This file was generated by @pikku/cli@0.12.48
*/
/**
* HTTP-specific type definitions for tree-shaking optimization
*/
import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore, addHTTPPermission as addHTTPPermissionCore, wireHTTPRoutes as wireHTTPRoutesCore, defineHTTPRoutes as defineHTTPRoutesCore } from '@pikku/core/http'
import type { PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware, PikkuFunctionConfig } from '../function/pikku-function-types.gen.js'
import type { CoreHTTPFunctionWiring, HTTPMethod, HTTPRouteBaseConfig } from '@pikku/core/http'
/**
* Type definition for HTTP API wirings with type-safe path parameters.
* Supports both authenticated and unauthenticated functions.
*
* @template In - Input type for the HTTP wiring
* @template Out - Output type for the HTTP wiring
* @template Route - String literal type for the HTTP path (e.g., "/users/:id")
*/
type HTTPWiring<In, Out, Route extends string> = CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction<In, Out, 'rpc' | 'session'>, PikkuFunctionSessionless<In, Out, 'rpc' | 'session'>, PikkuPermission<In>, PikkuMiddleware>
/**
* Registers an HTTP wiring with the Pikku framework.
*
* @template In - Input type for the HTTP wiring
* @template Out - Output type for the HTTP wiring
* @template Route - String literal type for the HTTP path (e.g., "/users/:id")
* @param httpWiring - HTTP wiring definition with handler, method, and optional middleware
*/
export const wireHTTP = <In, Out, Route extends string>(
httpWiring: HTTPWiring<In, Out, Route> & AssertHTTPWiringParams<In, Route>
) => {
wireHTTPCore(httpWiring as any)
}
/**
* Registers HTTP middleware either globally or for a specific route pattern.
*
* When a string route pattern is provided along with middleware, the middleware
* is applied only to that route. Otherwise, if an array is provided, it is treated
* as global middleware (applied to all routes).
*
* @param routeOrMiddleware - Either a global middleware array or a route pattern string
* @param middleware - The middleware array to apply when a route pattern is specified
*
* @example
* ```typescript
* // Add global HTTP middleware
* addHTTPMiddleware([authMiddleware, loggingMiddleware])
*
* // Add route-specific middleware
* addHTTPMiddleware('/api/admin/*', [adminAuthMiddleware])
* ```
*/
export const addHTTPMiddleware = (
routeOrMiddleware: PikkuMiddleware[] | string,
middleware?: PikkuMiddleware[]
) => {
addHTTPMiddlewareCore(routeOrMiddleware as any, middleware as any)
}
/**
* Registers HTTP permissions either globally or for a specific route pattern.
*
* When a string route pattern is provided along with permissions, the permissions
* are applied only to that route. Permissions can be passed as an array or as a
* permission group object.
*
* @param pattern - Route pattern string (e.g., '*' for all routes, '/api/*' for specific routes)
* @param permissions - The permissions to apply for the specified route pattern
*
* @example
* ```typescript
* // Add global HTTP permissions
* addHTTPPermission('*', { global: globalPermission })
*
* // Add route-specific permissions
* addHTTPPermission('/api/admin/*', { admin: adminPermission })
* ```
*/
export const addHTTPPermission = <In = unknown>(
pattern: string,
permissions: Record<string, PikkuPermission<In>> | PikkuPermission<In>[]
) => {
addHTTPPermissionCore(pattern, permissions as any)
}
/**
* Route configuration for wireHTTPRoutes with proper typing
*/
type HTTPRouteConfig = HTTPRouteBaseConfig & {
method: HTTPMethod
route: string
func: PikkuFunctionConfig<any, any, any, any, any, any>
auth?: boolean
permissions?: Record<string, PikkuPermission | PikkuPermission[]>
middleware?: PikkuMiddleware[]
sse?: boolean
}
/**
* Typed route map for wireHTTPRoutes
*/
type TypedHTTPRouteMap = {
[key: string]: HTTPRouteConfig | TypedHTTPRouteMap | TypedHTTPRouteContract
}
/**
* Typed route contract for defineHTTPRoutes
*/
type TypedHTTPRouteContract<T extends TypedHTTPRouteMap = TypedHTTPRouteMap> = TypedHTTPRoutesGroupConfig & {
routes: T
}
/**
* Group config with typed middleware/permissions
*/
type TypedHTTPRoutesGroupConfig = {
basePath?: string
tags?: string[]
auth?: boolean
middleware?: PikkuMiddleware[]
permissions?: Record<string, PikkuPermission | PikkuPermission[]>
}
/**
* Full config for wireHTTPRoutes
*/
type TypedWireHTTPRoutesConfig = TypedHTTPRoutesGroupConfig & {
routes: TypedHTTPRouteMap | HTTPRouteConfig[]
}
/**
* Type-safe helper for defining route contracts that can be composed.
*/
export function defineHTTPRoutes<T extends TypedHTTPRouteMap>(routes: T): TypedHTTPRouteContract<T>
export function defineHTTPRoutes<T extends TypedHTTPRouteMap>(config: TypedHTTPRoutesGroupConfig & { routes: T }): TypedHTTPRouteContract<T>
export function defineHTTPRoutes<T extends TypedHTTPRouteMap>(configOrRoutes: T | (TypedHTTPRoutesGroupConfig & { routes: T })): TypedHTTPRouteContract<T> {
return defineHTTPRoutesCore(configOrRoutes as any) as unknown as TypedHTTPRouteContract<T>
}
/**
* Wires multiple HTTP routes from a nested map or array configuration.
*/
export const wireHTTPRoutes = (config: TypedWireHTTPRoutesConfig): void => {
wireHTTPRoutesCore(config as any)
}

View File

@@ -0,0 +1,151 @@
/**
* This file was generated by @pikku/cli@0.12.48
*/
/**
* This provides the structure needed for typescript to be aware of routes and their return types
*/
import type { StreamWorkflowRunInput, StreamFunctionTestsOutput } from '@pikku/addon-console/dist/.pikku/rpc/pikku-rpc-wirings-map.internal.gen'
export type AgentApproveCallerInput = { agentName: string; runId: string; approvals: { toolCallId: string; approved: boolean; }[]; }
export type AgentCallerInput = { agentName: string; message: string; threadId: string; resourceId: string; }
export type AgentResumeCallerInput = { agentName: string; runId: string; toolCallId: string; approved: boolean; }
export type AgentStreamCallerInput = { agentName: string; message: string; threadId: string; resourceId: string; context?: string; }
export type AuthHandlerOutput = Promise<any> | Promise<void>
export type DeleteAgentThreadInput = { threadId: string; resourceId?: string; }
export type DeleteAgentThreadOutput = { deleted: boolean; }
export type EdgeEchoInput = {
message: string;
}
export type EdgeEchoOutput = {
echoed: string;
serverless: boolean;
}
export type GetAgentThreadMessagesInput = { threadId: string; resourceId?: string; }
export type GetAgentThreadMessagesOutput = any[]
export type GetAgentThreadRunsInput = { threadId: string; resourceId?: string; }
export type GetAgentThreadRunsOutput = any[]
export type GetAgentThreadsInput = { agentName?: string; resourceId?: string; limit?: number; offset?: number; }
export type GetAgentThreadsOutput = any[]
export type GetMessageInput = {}
export type GetMessageOutput = {
message: string;
updatedAt: string;
updatedBy: {
email: string;
name: string | null;
} | null;
}
export type GetSessionInput = {}
export type GetSessionOutput = {
userId: string;
email: string;
name: string | null;
}
export type PikkuConsoleGetSecretInput = { secretId: string; }
export type PikkuConsoleGetSecretOutput = { exists: boolean; value: unknown; }
export type PikkuConsoleGetVariableInput = { variableId: string; }
export type PikkuConsoleGetVariableOutput = { exists: boolean; value: unknown; }
export type PikkuConsoleHasSecretInput = { secretId: string; }
export type PikkuConsoleHasSecretOutput = { exists: boolean; }
export type PikkuConsoleSetSecretInput = { secretId: string; value: unknown; }
export type PikkuConsoleSetSecretOutput = { success: boolean; }
export type PikkuConsoleSetVariableInput = { variableId: string; value: unknown; }
export type PikkuConsoleSetVariableOutput = { success: boolean; }
export type RemoteRPCHandlerInput = { rpcName: string; data?: unknown; }
export type RpcCallerInput = { rpcName: string; data?: unknown; }
export type SecretSchema_betterAuthSecret = string
export type ServerCounterInput = {}
export type ServerCounterOutput = {
count: number;
pid: number;
}
export type ServerUptimeInput = {}
export type ServerUptimeOutput = {
uptimeSeconds: number;
nodeVersion: string;
rssMb: number;
}
export type UpdateMessageInput = {
message: string;
}
export type UpdateMessageOutput = {
message: string;
updatedAt: string;
updatedBy: {
email: string;
name: string | null;
} | null;
}
// The '& {}' is a workaround for not directly refering to a type since it confuses typescript
export type AgentCallerInputParams = Pick<AgentCallerInput, 'agentName'> & {}
export type AgentCallerInputBody = Omit<AgentCallerInput, 'agentName'> & {}
export type AgentStreamCallerInputParams = Pick<AgentStreamCallerInput, 'agentName'> & {}
export type AgentStreamCallerInputBody = Omit<AgentStreamCallerInput, 'agentName'> & {}
export type AgentApproveCallerInputParams = Pick<AgentApproveCallerInput, 'agentName'> & {}
export type AgentApproveCallerInputBody = Omit<AgentApproveCallerInput, 'agentName'> & {}
export type AgentResumeCallerInputParams = Pick<AgentResumeCallerInput, 'agentName'> & {}
export type AgentResumeCallerInputBody = Omit<AgentResumeCallerInput, 'agentName'> & {}
export type StreamWorkflowRunInputParams = Pick<StreamWorkflowRunInput, 'runId'> & {}
export type StreamWorkflowRunInputBody = Omit<StreamWorkflowRunInput, 'runId'> & {}
export type RpcCallerInputParams = Pick<RpcCallerInput, 'rpcName'> & {}
export type RpcCallerInputBody = Omit<RpcCallerInput, 'rpcName'> & {}
export type RemoteRPCHandlerInputParams = Pick<RemoteRPCHandlerInput, 'rpcName'> & {}
export type RemoteRPCHandlerInputBody = Omit<RemoteRPCHandlerInput, 'rpcName'> & {}
export type ServerUptimeInputBody = ServerUptimeInput & {}
export type ServerCounterInputBody = ServerCounterInput & {}
interface HTTPWiringHandler<I, O> {
input: I;
output: O;
}
export type HTTPWiringsMap = {
readonly '/api/auth{/*splat}': {
readonly GET: HTTPWiringHandler<null, AuthHandlerOutput>,
readonly POST: HTTPWiringHandler<null, AuthHandlerOutput>,
},
readonly '/workflow-run/:runId/stream': {
readonly GET: HTTPWiringHandler<StreamWorkflowRunInput, null>,
},
readonly '/function-tests/stream': {
readonly GET: HTTPWiringHandler<null, StreamFunctionTestsOutput>,
},
readonly '/rpc/agent/:agentName': {
readonly POST: HTTPWiringHandler<AgentCallerInput, null>,
},
readonly '/rpc/agent/:agentName/stream': {
readonly POST: HTTPWiringHandler<AgentStreamCallerInput, null>,
},
readonly '/rpc/agent/:agentName/approve': {
readonly POST: HTTPWiringHandler<AgentApproveCallerInput, null>,
},
readonly '/rpc/agent/:agentName/resume': {
readonly POST: HTTPWiringHandler<AgentResumeCallerInput, null>,
},
readonly '/rpc/:rpcName': {
readonly POST: HTTPWiringHandler<RpcCallerInput, null>,
},
readonly '/remote/rpc/:rpcName': {
readonly POST: HTTPWiringHandler<RemoteRPCHandlerInput, null>,
},
readonly '/server/uptime': {
readonly POST: HTTPWiringHandler<ServerUptimeInput, ServerUptimeOutput>,
},
readonly '/server/counter': {
readonly POST: HTTPWiringHandler<ServerCounterInput, ServerCounterOutput>,
},
};
export type HTTPWiringHandlerOf<HTTPWiring extends keyof HTTPWiringsMap, Method extends keyof HTTPWiringsMap[HTTPWiring]> =
HTTPWiringsMap[HTTPWiring][Method] extends { input: infer I; output: infer O }
? HTTPWiringHandler<I, O>
: never;
export type HTTPWiringsWithMethod<Method extends string> = {
[HTTPWiring in keyof HTTPWiringsMap]: Method extends keyof HTTPWiringsMap[HTTPWiring] ? HTTPWiring : never;
}[keyof HTTPWiringsMap];

View File

@@ -0,0 +1,197 @@
{
"get": {
"/api/auth{/*splat}": {
"pikkuFuncId": "authHandler",
"route": "/api/auth{/*splat}",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/auth.gen.ts",
"method": "get",
"middleware": [
{
"type": "http",
"route": "*"
}
]
},
"/workflow-run/:runId/stream": {
"pikkuFuncId": "http:get:/workflow-run/:runId/stream",
"route": "/workflow-run/:runId/stream",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/console.gen.ts",
"method": "get",
"params": [
"runId"
],
"middleware": [
{
"type": "http",
"route": "*"
}
],
"sse": true
},
"/function-tests/stream": {
"pikkuFuncId": "http:get:/function-tests/stream",
"route": "/function-tests/stream",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/console.gen.ts",
"method": "get",
"middleware": [
{
"type": "http",
"route": "*"
}
],
"sse": true
}
},
"post": {
"/rpc/agent/:agentName": {
"pikkuFuncId": "agentCaller",
"route": "/rpc/agent/:agentName",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/agent.gen.ts",
"method": "post",
"params": [
"agentName"
],
"tags": [
"pikku:public"
],
"middleware": [
{
"type": "http",
"route": "*"
}
]
},
"/rpc/agent/:agentName/stream": {
"pikkuFuncId": "agentStreamCaller",
"route": "/rpc/agent/:agentName/stream",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/agent.gen.ts",
"method": "post",
"params": [
"agentName"
],
"tags": [
"pikku:public"
],
"middleware": [
{
"type": "http",
"route": "*"
}
],
"sse": true
},
"/rpc/agent/:agentName/approve": {
"pikkuFuncId": "agentApproveCaller",
"route": "/rpc/agent/:agentName/approve",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/agent.gen.ts",
"method": "post",
"params": [
"agentName"
],
"tags": [
"pikku:public"
],
"middleware": [
{
"type": "http",
"route": "*"
}
]
},
"/rpc/agent/:agentName/resume": {
"pikkuFuncId": "agentResumeCaller",
"route": "/rpc/agent/:agentName/resume",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/agent.gen.ts",
"method": "post",
"params": [
"agentName"
],
"tags": [
"pikku:public"
],
"middleware": [
{
"type": "http",
"route": "*"
}
],
"sse": true
},
"/api/auth{/*splat}": {
"pikkuFuncId": "authHandler",
"route": "/api/auth{/*splat}",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/auth.gen.ts",
"method": "post",
"middleware": [
{
"type": "http",
"route": "*"
}
]
},
"/rpc/:rpcName": {
"pikkuFuncId": "rpcCaller",
"route": "/rpc/:rpcName",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/rpc-public.gen.ts",
"method": "post",
"params": [
"rpcName"
],
"middleware": [
{
"type": "http",
"route": "*"
}
]
},
"/remote/rpc/:rpcName": {
"pikkuFuncId": "remoteRPCHandler",
"route": "/remote/rpc/:rpcName",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/scaffold/rpc-remote.gen.ts",
"method": "post",
"params": [
"rpcName"
],
"middleware": [
{
"type": "http",
"route": "*"
},
{
"type": "wire",
"name": "pikkuRemoteAuthMiddleware",
"inline": false
}
]
},
"/server/uptime": {
"pikkuFuncId": "serverUptime",
"route": "/server/uptime",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/wirings/server.http.ts",
"method": "post",
"middleware": [
{
"type": "http",
"route": "*"
}
]
},
"/server/counter": {
"pikkuFuncId": "serverCounter",
"route": "/server/counter",
"sourceFile": "/Users/yasser/git/pikku/fabric/templates/server-and-serverless/packages/functions/src/wirings/server.http.ts",
"method": "post",
"middleware": [
{
"type": "http",
"route": "*"
}
]
}
},
"put": {},
"delete": {},
"head": {},
"patch": {},
"options": {}
}

View File

@@ -0,0 +1,7 @@
/**
* This file was generated by @pikku/cli@0.12.48
*/
import { pikkuState } from '@pikku/core/internal'
import type { HTTPWiringsMeta } from '@pikku/core/http'
import metaData from './pikku-http-wirings-meta.gen.json' with { type: 'json' }
pikkuState(null, 'http', 'meta', metaData as HTTPWiringsMeta)

View File

@@ -0,0 +1,12 @@
/**
* This file was generated by @pikku/cli@0.12.48
*/
/* The files with an wireHTTP function call */
import '../../src/middleware/cors.middleware.js'
import '../../src/scaffold/agent.gen.js'
import '../../src/scaffold/auth-middleware.gen.js'
import '../../src/scaffold/auth.gen.js'
import '../../src/scaffold/console.gen.js'
import '../../src/scaffold/rpc-public.gen.js'
import '../../src/scaffold/rpc-remote.gen.js'
import '../../src/wirings/server.http.js'