@flowgram.ai/runtime-nodejs 0.1.0-alpha.10

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 ADDED
@@ -0,0 +1,16 @@
1
+ # FlowGram Runtime NodeJS
2
+
3
+ ## Starting the server
4
+ ```bash
5
+ pnpm dev
6
+ ```
7
+
8
+ ## Building the server
9
+ ```bash
10
+ pnpm build
11
+ ```
12
+
13
+ ## Running the server
14
+ ```bash
15
+ pnpm start
16
+ ```
@@ -0,0 +1,192 @@
1
+ // src/server/index.ts
2
+ import { fastifyTRPCOpenApiPlugin } from "trpc-openapi";
3
+ import fastify from "fastify";
4
+ import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify";
5
+ import { ServerInfoDefine } from "@flowgram.ai/runtime-interface";
6
+ import ws from "@fastify/websocket";
7
+ import fastifySwaggerUI from "@fastify/swagger-ui";
8
+ import fastifySwagger from "@fastify/swagger";
9
+ import cors from "@fastify/cors";
10
+
11
+ // src/config/index.ts
12
+ var ServerConfig = {
13
+ name: "flowgram-runtime",
14
+ title: "FlowGram Runtime",
15
+ description: "FlowGram Runtime Demo",
16
+ runtime: "nodejs",
17
+ version: "0.0.1",
18
+ dev: false,
19
+ port: 4e3,
20
+ basePath: "/api",
21
+ docsPath: "/docs"
22
+ };
23
+
24
+ // src/api/index.ts
25
+ import { FlowGramAPINames } from "@flowgram.ai/runtime-interface";
26
+
27
+ // src/api/trpc.ts
28
+ import { initTRPC } from "@trpc/server";
29
+ var t = initTRPC.context().meta().create({
30
+ errorFormatter({ shape }) {
31
+ return shape;
32
+ }
33
+ });
34
+ var router = t.router;
35
+ var publicProcedure = t.procedure;
36
+
37
+ // src/api/create-api.ts
38
+ import z from "zod";
39
+ import { WorkflowRuntimeAPIs } from "@flowgram.ai/runtime-js";
40
+ import { FlowGramAPIMethod, FlowGramAPIs } from "@flowgram.ai/runtime-interface";
41
+ var createAPI = (apiName) => {
42
+ const define = FlowGramAPIs[apiName];
43
+ const caller = WorkflowRuntimeAPIs[apiName];
44
+ if (define.method === FlowGramAPIMethod.GET) {
45
+ const procedure2 = publicProcedure.meta({
46
+ openapi: {
47
+ method: define.method,
48
+ path: define.path,
49
+ summary: define.name,
50
+ tags: [define.module]
51
+ }
52
+ }).input(define.schema.input).output(z.union([define.schema.output, z.undefined()])).query(async (opts) => {
53
+ const input = opts.input;
54
+ try {
55
+ const output = await caller(input);
56
+ return output;
57
+ } catch {
58
+ return void 0;
59
+ }
60
+ });
61
+ return {
62
+ define,
63
+ procedure: procedure2
64
+ };
65
+ }
66
+ const procedure = publicProcedure.meta({
67
+ openapi: {
68
+ method: define.method,
69
+ path: define.path,
70
+ summary: define.name,
71
+ tags: [define.module]
72
+ }
73
+ }).input(define.schema.input).output(z.union([define.schema.output, z.undefined()])).mutation(async (opts) => {
74
+ const input = opts.input;
75
+ try {
76
+ const output = await caller(input);
77
+ return output;
78
+ } catch {
79
+ return void 0;
80
+ }
81
+ });
82
+ return {
83
+ define,
84
+ procedure
85
+ };
86
+ };
87
+
88
+ // src/api/index.ts
89
+ var APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));
90
+ var routers = APIS.reduce((acc, api) => {
91
+ acc[api.define.path] = api.procedure;
92
+ return acc;
93
+ }, {});
94
+ var appRouter = router(routers);
95
+
96
+ // src/server/docs.ts
97
+ import { generateOpenApiDocument } from "trpc-openapi";
98
+ var serverDocument = generateOpenApiDocument(appRouter, {
99
+ title: ServerConfig.title,
100
+ description: ServerConfig.description,
101
+ version: ServerConfig.version,
102
+ baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,
103
+ docsUrl: "https://flowgram.ai",
104
+ tags: ["Task"]
105
+ });
106
+
107
+ // src/server/context.ts
108
+ function createContext(ctx) {
109
+ const { req, res } = ctx;
110
+ return { req, res };
111
+ }
112
+
113
+ // src/server/index.ts
114
+ async function createServer() {
115
+ const server = fastify({ logger: ServerConfig.dev });
116
+ await server.register(cors);
117
+ await server.register(ws);
118
+ await server.register(fastifyTRPCPlugin, {
119
+ prefix: "/trpc",
120
+ useWss: false,
121
+ trpcOptions: { router: appRouter, createContext }
122
+ });
123
+ await server.register(fastifyTRPCOpenApiPlugin, {
124
+ basePath: ServerConfig.basePath,
125
+ router: appRouter,
126
+ createContext
127
+ });
128
+ await server.register(fastifySwagger, {
129
+ mode: "static",
130
+ specification: { document: serverDocument },
131
+ uiConfig: { displayOperationId: true },
132
+ exposeRoute: true
133
+ });
134
+ await server.register(fastifySwaggerUI, {
135
+ routePrefix: ServerConfig.docsPath,
136
+ uiConfig: {
137
+ docExpansion: "full",
138
+ deepLinking: false
139
+ },
140
+ uiHooks: {
141
+ onRequest: function(request, reply, next) {
142
+ next();
143
+ },
144
+ preHandler: function(request, reply, next) {
145
+ next();
146
+ }
147
+ },
148
+ staticCSP: true,
149
+ transformStaticCSP: (header) => header,
150
+ transformSpecification: (swaggerObject, request, reply) => swaggerObject,
151
+ transformSpecificationClone: true
152
+ });
153
+ server.get(ServerInfoDefine.path, async () => {
154
+ const serverTime = /* @__PURE__ */ new Date();
155
+ const output = {
156
+ name: ServerConfig.name,
157
+ title: ServerConfig.title,
158
+ description: ServerConfig.description,
159
+ runtime: ServerConfig.runtime,
160
+ version: ServerConfig.version,
161
+ time: serverTime.toISOString()
162
+ };
163
+ return output;
164
+ });
165
+ const stop = async () => {
166
+ await server.close();
167
+ };
168
+ const start = async () => {
169
+ try {
170
+ const address = await server.listen({ port: ServerConfig.port });
171
+ await server.ready();
172
+ server.swagger();
173
+ console.log(
174
+ `> Listen Port: ${ServerConfig.port}
175
+ > Server Address: ${address}
176
+ > API Docs: http://localhost:4000/docs`
177
+ );
178
+ } catch (err) {
179
+ server.log.error(err);
180
+ process.exit(1);
181
+ }
182
+ };
183
+ return { server, start, stop };
184
+ }
185
+
186
+ // src/index.ts
187
+ async function main() {
188
+ const server = await createServer();
189
+ server.start();
190
+ }
191
+ main();
192
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/index.ts","../../src/config/index.ts","../../src/api/index.ts","../../src/api/trpc.ts","../../src/api/create-api.ts","../../src/server/docs.ts","../../src/server/context.ts","../../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { fastifyTRPCOpenApiPlugin } from 'trpc-openapi';\nimport fastify from 'fastify';\nimport { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';\nimport { ServerInfoDefine, type ServerInfoOutput } from '@flowgram.ai/runtime-interface';\nimport ws from '@fastify/websocket';\nimport fastifySwaggerUI from '@fastify/swagger-ui';\nimport fastifySwagger from '@fastify/swagger';\nimport cors from '@fastify/cors';\n\nimport { ServerConfig } from '@config/index';\nimport { appRouter } from '@api/index';\nimport { serverDocument } from './docs';\nimport { createContext } from './context';\n\nexport async function createServer() {\n const server = fastify({ logger: ServerConfig.dev });\n\n await server.register(cors);\n await server.register(ws);\n await server.register(fastifyTRPCPlugin, {\n prefix: '/trpc',\n useWss: false,\n trpcOptions: { router: appRouter, createContext },\n });\n await server.register(fastifyTRPCOpenApiPlugin, {\n basePath: ServerConfig.basePath,\n router: appRouter,\n createContext,\n } as any);\n\n await server.register(fastifySwagger, {\n mode: 'static',\n specification: { document: serverDocument },\n uiConfig: { displayOperationId: true },\n exposeRoute: true,\n } as any);\n\n await server.register(fastifySwaggerUI, {\n routePrefix: ServerConfig.docsPath,\n uiConfig: {\n docExpansion: 'full',\n deepLinking: false,\n },\n uiHooks: {\n onRequest: function (request, reply, next) {\n next();\n },\n preHandler: function (request, reply, next) {\n next();\n },\n },\n staticCSP: true,\n transformStaticCSP: (header) => header,\n transformSpecification: (swaggerObject, request, reply) => swaggerObject,\n transformSpecificationClone: true,\n });\n\n server.get(ServerInfoDefine.path, async (): Promise<ServerInfoOutput> => {\n const serverTime = new Date();\n const output: ServerInfoOutput = {\n name: ServerConfig.name,\n title: ServerConfig.title,\n description: ServerConfig.description,\n runtime: ServerConfig.runtime,\n version: ServerConfig.version,\n time: serverTime.toISOString(),\n };\n return output;\n });\n\n const stop = async () => {\n await server.close();\n };\n const start = async () => {\n try {\n const address = await server.listen({ port: ServerConfig.port });\n await server.ready();\n server.swagger();\n console.log(\n `> Listen Port: ${ServerConfig.port}\\n> Server Address: ${address}\\n> API Docs: http://localhost:4000/docs`\n );\n } catch (err) {\n server.log.error(err);\n process.exit(1);\n }\n };\n\n return { server, start, stop };\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { ServerParams } from '@server/type';\n\nexport const ServerConfig: ServerParams = {\n name: 'flowgram-runtime',\n title: 'FlowGram Runtime',\n description: 'FlowGram Runtime Demo',\n runtime: 'nodejs',\n version: '0.0.1',\n dev: false,\n port: 4000,\n basePath: '/api',\n docsPath: '/docs',\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowGramAPINames } from '@flowgram.ai/runtime-interface';\n\nimport { APIRouter } from './type';\nimport { router } from './trpc';\nimport { createAPI } from './create-api';\n\nconst APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));\n\nexport const routers = APIS.reduce((acc, api) => {\n acc[api.define.path] = api.procedure;\n return acc;\n}, {} as APIRouter);\n\nexport const appRouter = router(routers);\n\nexport type AppRouter = typeof appRouter;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { OpenApiMeta } from 'trpc-openapi';\nimport { initTRPC } from '@trpc/server';\n\nimport type { Context } from '../server/context';\n\nconst t = initTRPC\n .context<Context>()\n .meta<OpenApiMeta>()\n .create({\n errorFormatter({ shape }) {\n return shape;\n },\n });\n\nexport const router = t.router;\nexport const publicProcedure = t.procedure;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport z from 'zod';\nimport { WorkflowRuntimeAPIs } from '@flowgram.ai/runtime-js';\nimport { FlowGramAPIMethod, FlowGramAPIName, FlowGramAPIs } from '@flowgram.ai/runtime-interface';\n\nimport { APIHandler } from './type';\nimport { publicProcedure } from './trpc';\n\nexport const createAPI = (apiName: FlowGramAPIName): APIHandler => {\n const define = FlowGramAPIs[apiName];\n const caller = WorkflowRuntimeAPIs[apiName];\n if (define.method === FlowGramAPIMethod.GET) {\n const procedure = publicProcedure\n .meta({\n openapi: {\n method: define.method,\n path: define.path,\n summary: define.name,\n tags: [define.module],\n },\n })\n .input(define.schema.input)\n .output(z.union([define.schema.output, z.undefined()]))\n .query(async (opts) => {\n const input = opts.input;\n try {\n const output = await caller(input);\n return output;\n } catch {\n return undefined;\n }\n });\n\n return {\n define,\n procedure: procedure as any,\n };\n }\n\n const procedure = publicProcedure\n .meta({\n openapi: {\n method: define.method,\n path: define.path,\n summary: define.name,\n tags: [define.module],\n },\n })\n .input(define.schema.input)\n .output(z.union([define.schema.output, z.undefined()]))\n .mutation(async (opts) => {\n const input = opts.input;\n try {\n const output = await caller(input);\n return output;\n } catch {\n return undefined;\n }\n });\n return {\n define,\n procedure: procedure as any,\n };\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { generateOpenApiDocument } from 'trpc-openapi';\n\nimport { ServerConfig } from '@config/index';\nimport { appRouter } from '@api/index';\n\n// Generate OpenAPI schema document\nexport const serverDocument = generateOpenApiDocument(appRouter, {\n title: ServerConfig.title,\n description: ServerConfig.description,\n version: ServerConfig.version,\n baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,\n docsUrl: 'https://flowgram.ai',\n tags: ['Task'],\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';\n\nexport function createContext(ctx: CreateFastifyContextOptions) {\n const { req, res } = ctx;\n return { req, res };\n}\n\nexport type Context = Awaited<ReturnType<typeof createContext>>;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { createServer } from '@server/index';\n\nasync function main() {\n const server = await createServer();\n server.start();\n}\n\nmain();\n"],"mappings":";AAKA,SAAS,gCAAgC;AACzC,OAAO,aAAa;AACpB,SAAS,yBAAyB;AAClC,SAAS,wBAA+C;AACxD,OAAO,QAAQ;AACf,OAAO,sBAAsB;AAC7B,OAAO,oBAAoB;AAC3B,OAAO,UAAU;;;ACLV,IAAM,eAA6B;AAAA,EACxC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AAAA,EACT,SAAS;AAAA,EACT,KAAK;AAAA,EACL,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ;;;ACZA,SAAS,wBAAwB;;;ACCjC,SAAS,gBAAgB;AAIzB,IAAM,IAAI,SACP,QAAiB,EACjB,KAAkB,EAClB,OAAO;AAAA,EACN,eAAe,EAAE,MAAM,GAAG;AACxB,WAAO;AAAA,EACT;AACF,CAAC;AAEI,IAAM,SAAS,EAAE;AACjB,IAAM,kBAAkB,EAAE;;;ACfjC,OAAO,OAAO;AACd,SAAS,2BAA2B;AACpC,SAAS,mBAAoC,oBAAoB;AAK1D,IAAM,YAAY,CAAC,YAAyC;AACjE,QAAM,SAAS,aAAa,OAAO;AACnC,QAAM,SAAS,oBAAoB,OAAO;AAC1C,MAAI,OAAO,WAAW,kBAAkB,KAAK;AAC3C,UAAMA,aAAY,gBACf,KAAK;AAAA,MACJ,SAAS;AAAA,QACP,QAAQ,OAAO;AAAA,QACf,MAAM,OAAO;AAAA,QACb,SAAS,OAAO;AAAA,QAChB,MAAM,CAAC,OAAO,MAAM;AAAA,MACtB;AAAA,IACF,CAAC,EACA,MAAM,OAAO,OAAO,KAAK,EACzB,OAAO,EAAE,MAAM,CA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aAAa;AAAA,MAC1B,SAAS,aAAa;AAAA,MACtB,SAAS,aAAa;AAAA,MACtB,MAAM,WAAW,YAAY;AAAA,IAC/B;AACA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,OAAO,YAAY;AACvB,UAAM,OAAO,MAAM;AAAA,EACrB;AACA,QAAM,QAAQ,YAAY;AACxB,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,OAAO,EAAE,MAAM,aAAa,KAAK,CAAC;AAC/D,YAAM,OAAO,MAAM;AACnB,aAAO,QAAQ;AACf,cAAQ;AAAA,QACN,kBAAkB,aAAa,IAAI;AAAA,oBAAuB,OAAO;AAAA;AAAA,MACnE;AAAA,IACF,SAAS,KAAK;AACZ,aAAO,IAAI,MAAM,GAAG;AACpB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,OAAO,KAAK;AAC/B;;;AOtFA,eAAe,OAAO;AACpB,QAAM,SAAS,MAAM,aAAa;AAClC,SAAO,MAAM;AACf;AAEA,KAAK;","names":["procedure"]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+
25
+ // src/server/index.ts
26
+ var import_trpc_openapi2 = require("trpc-openapi");
27
+ var import_fastify = __toESM(require("fastify"));
28
+ var import_fastify2 = require("@trpc/server/adapters/fastify");
29
+ var import_runtime_interface3 = require("@flowgram.ai/runtime-interface");
30
+ var import_websocket = __toESM(require("@fastify/websocket"));
31
+ var import_swagger_ui = __toESM(require("@fastify/swagger-ui"));
32
+ var import_swagger = __toESM(require("@fastify/swagger"));
33
+ var import_cors = __toESM(require("@fastify/cors"));
34
+
35
+ // src/config/index.ts
36
+ var ServerConfig = {
37
+ name: "flowgram-runtime",
38
+ title: "FlowGram Runtime",
39
+ description: "FlowGram Runtime Demo",
40
+ runtime: "nodejs",
41
+ version: "0.0.1",
42
+ dev: false,
43
+ port: 4e3,
44
+ basePath: "/api",
45
+ docsPath: "/docs"
46
+ };
47
+
48
+ // src/api/index.ts
49
+ var import_runtime_interface2 = require("@flowgram.ai/runtime-interface");
50
+
51
+ // src/api/trpc.ts
52
+ var import_server = require("@trpc/server");
53
+ var t = import_server.initTRPC.context().meta().create({
54
+ errorFormatter({ shape }) {
55
+ return shape;
56
+ }
57
+ });
58
+ var router = t.router;
59
+ var publicProcedure = t.procedure;
60
+
61
+ // src/api/create-api.ts
62
+ var import_zod = __toESM(require("zod"));
63
+ var import_runtime_js = require("@flowgram.ai/runtime-js");
64
+ var import_runtime_interface = require("@flowgram.ai/runtime-interface");
65
+ var createAPI = (apiName) => {
66
+ const define = import_runtime_interface.FlowGramAPIs[apiName];
67
+ const caller = import_runtime_js.WorkflowRuntimeAPIs[apiName];
68
+ if (define.method === import_runtime_interface.FlowGramAPIMethod.GET) {
69
+ const procedure2 = publicProcedure.meta({
70
+ openapi: {
71
+ method: define.method,
72
+ path: define.path,
73
+ summary: define.name,
74
+ tags: [define.module]
75
+ }
76
+ }).input(define.schema.input).output(import_zod.default.union([define.schema.output, import_zod.default.undefined()])).query(async (opts) => {
77
+ const input = opts.input;
78
+ try {
79
+ const output = await caller(input);
80
+ return output;
81
+ } catch {
82
+ return void 0;
83
+ }
84
+ });
85
+ return {
86
+ define,
87
+ procedure: procedure2
88
+ };
89
+ }
90
+ const procedure = publicProcedure.meta({
91
+ openapi: {
92
+ method: define.method,
93
+ path: define.path,
94
+ summary: define.name,
95
+ tags: [define.module]
96
+ }
97
+ }).input(define.schema.input).output(import_zod.default.union([define.schema.output, import_zod.default.undefined()])).mutation(async (opts) => {
98
+ const input = opts.input;
99
+ try {
100
+ const output = await caller(input);
101
+ return output;
102
+ } catch {
103
+ return void 0;
104
+ }
105
+ });
106
+ return {
107
+ define,
108
+ procedure
109
+ };
110
+ };
111
+
112
+ // src/api/index.ts
113
+ var APIS = import_runtime_interface2.FlowGramAPINames.map((apiName) => createAPI(apiName));
114
+ var routers = APIS.reduce((acc, api) => {
115
+ acc[api.define.path] = api.procedure;
116
+ return acc;
117
+ }, {});
118
+ var appRouter = router(routers);
119
+
120
+ // src/server/docs.ts
121
+ var import_trpc_openapi = require("trpc-openapi");
122
+ var serverDocument = (0, import_trpc_openapi.generateOpenApiDocument)(appRouter, {
123
+ title: ServerConfig.title,
124
+ description: ServerConfig.description,
125
+ version: ServerConfig.version,
126
+ baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,
127
+ docsUrl: "https://flowgram.ai",
128
+ tags: ["Task"]
129
+ });
130
+
131
+ // src/server/context.ts
132
+ function createContext(ctx) {
133
+ const { req, res } = ctx;
134
+ return { req, res };
135
+ }
136
+
137
+ // src/server/index.ts
138
+ async function createServer() {
139
+ const server = (0, import_fastify.default)({ logger: ServerConfig.dev });
140
+ await server.register(import_cors.default);
141
+ await server.register(import_websocket.default);
142
+ await server.register(import_fastify2.fastifyTRPCPlugin, {
143
+ prefix: "/trpc",
144
+ useWss: false,
145
+ trpcOptions: { router: appRouter, createContext }
146
+ });
147
+ await server.register(import_trpc_openapi2.fastifyTRPCOpenApiPlugin, {
148
+ basePath: ServerConfig.basePath,
149
+ router: appRouter,
150
+ createContext
151
+ });
152
+ await server.register(import_swagger.default, {
153
+ mode: "static",
154
+ specification: { document: serverDocument },
155
+ uiConfig: { displayOperationId: true },
156
+ exposeRoute: true
157
+ });
158
+ await server.register(import_swagger_ui.default, {
159
+ routePrefix: ServerConfig.docsPath,
160
+ uiConfig: {
161
+ docExpansion: "full",
162
+ deepLinking: false
163
+ },
164
+ uiHooks: {
165
+ onRequest: function(request, reply, next) {
166
+ next();
167
+ },
168
+ preHandler: function(request, reply, next) {
169
+ next();
170
+ }
171
+ },
172
+ staticCSP: true,
173
+ transformStaticCSP: (header) => header,
174
+ transformSpecification: (swaggerObject, request, reply) => swaggerObject,
175
+ transformSpecificationClone: true
176
+ });
177
+ server.get(import_runtime_interface3.ServerInfoDefine.path, async () => {
178
+ const serverTime = /* @__PURE__ */ new Date();
179
+ const output = {
180
+ name: ServerConfig.name,
181
+ title: ServerConfig.title,
182
+ description: ServerConfig.description,
183
+ runtime: ServerConfig.runtime,
184
+ version: ServerConfig.version,
185
+ time: serverTime.toISOString()
186
+ };
187
+ return output;
188
+ });
189
+ const stop = async () => {
190
+ await server.close();
191
+ };
192
+ const start = async () => {
193
+ try {
194
+ const address = await server.listen({ port: ServerConfig.port });
195
+ await server.ready();
196
+ server.swagger();
197
+ console.log(
198
+ `> Listen Port: ${ServerConfig.port}
199
+ > Server Address: ${address}
200
+ > API Docs: http://localhost:4000/docs`
201
+ );
202
+ } catch (err) {
203
+ server.log.error(err);
204
+ process.exit(1);
205
+ }
206
+ };
207
+ return { server, start, stop };
208
+ }
209
+
210
+ // src/index.ts
211
+ async function main() {
212
+ const server = await createServer();
213
+ server.start();
214
+ }
215
+ main();
216
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/index.ts","../src/config/index.ts","../src/api/index.ts","../src/api/trpc.ts","../src/api/create-api.ts","../src/server/docs.ts","../src/server/context.ts","../src/index.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { fastifyTRPCOpenApiPlugin } from 'trpc-openapi';\nimport fastify from 'fastify';\nimport { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';\nimport { ServerInfoDefine, type ServerInfoOutput } from '@flowgram.ai/runtime-interface';\nimport ws from '@fastify/websocket';\nimport fastifySwaggerUI from '@fastify/swagger-ui';\nimport fastifySwagger from '@fastify/swagger';\nimport cors from '@fastify/cors';\n\nimport { ServerConfig } from '@config/index';\nimport { appRouter } from '@api/index';\nimport { serverDocument } from './docs';\nimport { createContext } from './context';\n\nexport async function createServer() {\n const server = fastify({ logger: ServerConfig.dev });\n\n await server.register(cors);\n await server.register(ws);\n await server.register(fastifyTRPCPlugin, {\n prefix: '/trpc',\n useWss: false,\n trpcOptions: { router: appRouter, createContext },\n });\n await server.register(fastifyTRPCOpenApiPlugin, {\n basePath: ServerConfig.basePath,\n router: appRouter,\n createContext,\n } as any);\n\n await server.register(fastifySwagger, {\n mode: 'static',\n specification: { document: serverDocument },\n uiConfig: { displayOperationId: true },\n exposeRoute: true,\n } as any);\n\n await server.register(fastifySwaggerUI, {\n routePrefix: ServerConfig.docsPath,\n uiConfig: {\n docExpansion: 'full',\n deepLinking: false,\n },\n uiHooks: {\n onRequest: function (request, reply, next) {\n next();\n },\n preHandler: function (request, reply, next) {\n next();\n },\n },\n staticCSP: true,\n transformStaticCSP: (header) => header,\n transformSpecification: (swaggerObject, request, reply) => swaggerObject,\n transformSpecificationClone: true,\n });\n\n server.get(ServerInfoDefine.path, async (): Promise<ServerInfoOutput> => {\n const serverTime = new Date();\n const output: ServerInfoOutput = {\n name: ServerConfig.name,\n title: ServerConfig.title,\n description: ServerConfig.description,\n runtime: ServerConfig.runtime,\n version: ServerConfig.version,\n time: serverTime.toISOString(),\n };\n return output;\n });\n\n const stop = async () => {\n await server.close();\n };\n const start = async () => {\n try {\n const address = await server.listen({ port: ServerConfig.port });\n await server.ready();\n server.swagger();\n console.log(\n `> Listen Port: ${ServerConfig.port}\\n> Server Address: ${address}\\n> API Docs: http://localhost:4000/docs`\n );\n } catch (err) {\n server.log.error(err);\n process.exit(1);\n }\n };\n\n return { server, start, stop };\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { ServerParams } from '@server/type';\n\nexport const ServerConfig: ServerParams = {\n name: 'flowgram-runtime',\n title: 'FlowGram Runtime',\n description: 'FlowGram Runtime Demo',\n runtime: 'nodejs',\n version: '0.0.1',\n dev: false,\n port: 4000,\n basePath: '/api',\n docsPath: '/docs',\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowGramAPINames } from '@flowgram.ai/runtime-interface';\n\nimport { APIRouter } from './type';\nimport { router } from './trpc';\nimport { createAPI } from './create-api';\n\nconst APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));\n\nexport const routers = APIS.reduce((acc, api) => {\n acc[api.define.path] = api.procedure;\n return acc;\n}, {} as APIRouter);\n\nexport const appRouter = router(routers);\n\nexport type AppRouter = typeof appRouter;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { OpenApiMeta } from 'trpc-openapi';\nimport { initTRPC } from '@trpc/server';\n\nimport type { Context } from '../server/context';\n\nconst t = initTRPC\n .context<Context>()\n .meta<OpenApiMeta>()\n .create({\n errorFormatter({ shape }) {\n return shape;\n },\n });\n\nexport const router = t.router;\nexport const publicProcedure = t.procedure;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport z from 'zod';\nimport { WorkflowRuntimeAPIs } from '@flowgram.ai/runtime-js';\nimport { FlowGramAPIMethod, FlowGramAPIName, FlowGramAPIs } from '@flowgram.ai/runtime-interface';\n\nimport { APIHandler } from './type';\nimport { publicProcedure } from './trpc';\n\nexport const createAPI = (apiName: FlowGramAPIName): APIHandler => {\n const define = FlowGramAPIs[apiName];\n const caller = WorkflowRuntimeAPIs[apiName];\n if (define.method === FlowGramAPIMethod.GET) {\n const procedure = publicProcedure\n .meta({\n openapi: {\n method: define.method,\n path: define.path,\n summary: define.name,\n tags: [define.module],\n },\n })\n .input(define.schema.input)\n .output(z.union([define.schema.output, z.undefined()]))\n .query(async (opts) => {\n const input = opts.input;\n try {\n const output = await caller(input);\n return output;\n } catch {\n return undefined;\n }\n });\n\n return {\n define,\n procedure: procedure as any,\n };\n }\n\n const procedure = publicProcedure\n .meta({\n openapi: {\n method: define.method,\n path: define.path,\n summary: define.name,\n tags: [define.module],\n },\n })\n .input(define.schema.input)\n .output(z.union([define.schema.output, z.undefined()]))\n .mutation(async (opts) => {\n const input = opts.input;\n try {\n const output = await caller(input);\n return output;\n } catch {\n return undefined;\n }\n });\n return {\n define,\n procedure: procedure as any,\n };\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { generateOpenApiDocument } from 'trpc-openapi';\n\nimport { ServerConfig } from '@config/index';\nimport { appRouter } from '@api/index';\n\n// Generate OpenAPI schema document\nexport const serverDocument = generateOpenApiDocument(appRouter, {\n title: ServerConfig.title,\n description: ServerConfig.description,\n version: ServerConfig.version,\n baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,\n docsUrl: 'https://flowgram.ai',\n tags: ['Task'],\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';\n\nexport function createContext(ctx: CreateFastifyContextOptions) {\n const { req, res } = ctx;\n return { req, res };\n}\n\nexport type Context = Awaited<ReturnType<typeof createContext>>;\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { createServer } from '@server/index';\n\nasync function main() {\n const server = await createServer();\n server.start();\n}\n\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAAA,uBAAyC;AACzC,qBAAoB;AACpB,IAAAC,kBAAkC;AAClC,IAAAC,4BAAwD;AACxD,uBAAe;AACf,wBAA6B;AAC7B,qBAA2B;AAC3B,kBAAiB;;;ACLV,IAAM,eAA6B;AAAA,EACxC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS;AAAA,EACT,SAAS;AAAA,EACT,KAAK;AAAA,EACL,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ;;;ACZA,IAAAC,4BAAiC;;;ACCjC,oBAAyB;AAIzB,IAAM,IAAI,uBACP,QAAiB,EACjB,KAAkB,EAClB,OAAO;AAAA,EACN,eAAe,EAAE,MAAM,GAAG;AACxB,WAAO;AAAA,EACT;AACF,CAAC;AAEI,IAAM,SAAS,EAAE;AACjB,IAAM,kBAAkB,EAAE;;;ACfjC,iBAAc;AACd,wBAAoC;AACpC,+BAAiE;AAK1D,IAAM,YAAY,CAAC,YAAyC;AACjE,QAAM,SAAS,sCAAa,OAAO;AACnC,QAAM,SAAS,sCAAoB,OAAO;AAC1C,MAAI,OAAO,WAAW,2CAAkB,KAAK;AAC3C,UAAMC,aAAY,gBACf,KAAK;AAAA,MACJ,SAAS;AAAA,QACP,QAAQ,OAAO;AAAA,QACf,MAAM,OAAO;AAAA,QACb,SAAS,OAAO;AAAA,QAChB,MAAM,CAAC,OAAO,MAAM;AAAA,MACtB;AAAA,IACF,CAAC,EACA,MAAM,OAAO,OAAO,KAAK,EACzB,OAAO,WA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2B;AAAA,MAC/B,MAAM,aAAa;AAAA,MACnB,OAAO,aAAa;AAAA,MACpB,aAAa,aAAa;AAAA,MAC1B,SAAS,aAAa;AAAA,MACtB,SAAS,aAAa;AAAA,MACtB,MAAM,WAAW,YAAY;AAAA,IAC/B;AACA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,OAAO,YAAY;AACvB,UAAM,OAAO,MAAM;AAAA,EACrB;AACA,QAAM,QAAQ,YAAY;AACxB,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,OAAO,EAAE,MAAM,aAAa,KAAK,CAAC;AAC/D,YAAM,OAAO,MAAM;AACnB,aAAO,QAAQ;AACf,cAAQ;AAAA,QACN,kBAAkB,aAAa,IAAI;AAAA,oBAAuB,OAAO;AAAA;AAAA,MACnE;AAAA,IACF,SAAS,KAAK;AACZ,aAAO,IAAI,MAAM,GAAG;AACpB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAEA,SAAO,EAAE,QAAQ,OAAO,KAAK;AAC/B;;;AOtFA,eAAe,OAAO;AACpB,QAAM,SAAS,MAAM,aAAa;AAClC,SAAO,MAAM;AACf;AAEA,KAAK;","names":["import_trpc_openapi","import_fastify","import_runtime_interface","import_runtime_interface","procedure","z","fastify","cors","ws","fastifySwagger","fastifySwaggerUI"]}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@flowgram.ai/runtime-nodejs",
3
+ "version": "0.1.0-alpha.10",
4
+ "description": "",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "dependencies": {
8
+ "@fastify/cors": "^8.2.1",
9
+ "@fastify/swagger": "^8.5.1",
10
+ "@fastify/swagger-ui": "4.1.0",
11
+ "@langchain/openai": "^0.5.11",
12
+ "@langchain/core": "^0.3.57",
13
+ "@fastify/websocket": "^10.0.1",
14
+ "@trpc/server": "^10.27.1",
15
+ "trpc-openapi": "^1.2.0",
16
+ "fastify": "^4.17.0",
17
+ "tslib": "^2.8.1",
18
+ "lodash-es": "^4.17.21",
19
+ "ws": "^8.0.0",
20
+ "zod": "^3.24.4",
21
+ "@flowgram.ai/runtime-interface": "0.1.0-alpha.10",
22
+ "@flowgram.ai/runtime-js": "0.1.0-alpha.10"
23
+ },
24
+ "devDependencies": {
25
+ "@types/cors": "^2.8.13",
26
+ "dotenv": "~16.5.0",
27
+ "@types/node": "^18",
28
+ "@types/ws": "^8.2.0",
29
+ "@types/lodash-es": "^4.17.12",
30
+ "eslint": "^8.54.0",
31
+ "npm-run-all": "^4.1.5",
32
+ "@babel/eslint-parser": "~7.19.1",
33
+ "typescript": "^5.0.4",
34
+ "tsup": "^8.0.1",
35
+ "tsx": "~4.19.4",
36
+ "eslint-plugin-json": "^4.0.1",
37
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
38
+ "@typescript-eslint/parser": "^6.10.0",
39
+ "@eslint/eslintrc": "^3",
40
+ "@vitest/coverage-v8": "^0.32.0",
41
+ "vitest": "^0.34.6",
42
+ "wait-port": "^1.0.1",
43
+ "@flowgram.ai/ts-config": "0.1.0-alpha.10",
44
+ "@flowgram.ai/eslint-config": "0.1.0-alpha.10"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public",
48
+ "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "scripts": {
51
+ "dev": "tsx watch src",
52
+ "build": "npm run build:fast -- --dts-resolve",
53
+ "build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
54
+ "build:watch": "npm run build:fast -- --dts-resolve",
55
+ "lint": "eslint --cache src",
56
+ "lint-fix": "eslint --fix src",
57
+ "type-check": "tsc",
58
+ "start": "node dist/index.js",
59
+ "test": "exit 0",
60
+ "test:cov": "exit 0"
61
+ }
62
+ }
File without changes
@@ -0,0 +1,21 @@
1
+ Invoking: npm run build:fast -- --dts-resolve
2
+
3
+ > @flowgram.ai/runtime-nodejs@0.1.0 build:fast
4
+ > tsup src/index.ts --format cjs,esm --sourcemap --legacy-output --dts-resolve
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.3.5
9
+ CLI Target: esnext
10
+ CJS Build start
11
+ ESM Build start
12
+ ESM dist/esm/index.js 5.09 KB
13
+ ESM dist/esm/index.js.map 10.94 KB
14
+ ESM ⚡️ Build success in 55ms
15
+ CJS dist/index.js 6.67 KB
16
+ CJS dist/index.js.map 11.10 KB
17
+ CJS ⚡️ Build success in 56ms
18
+ DTS Build start
19
+ DTS ⚡️ Build success in 5676ms
20
+ DTS dist/index.d.ts 13.00 B
21
+ DTS dist/index.d.mts 13.00 B
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import z from 'zod';
7
+ import { WorkflowRuntimeAPIs } from '@flowgram.ai/runtime-js';
8
+ import { FlowGramAPIMethod, FlowGramAPIName, FlowGramAPIs } from '@flowgram.ai/runtime-interface';
9
+
10
+ import { APIHandler } from './type';
11
+ import { publicProcedure } from './trpc';
12
+
13
+ export const createAPI = (apiName: FlowGramAPIName): APIHandler => {
14
+ const define = FlowGramAPIs[apiName];
15
+ const caller = WorkflowRuntimeAPIs[apiName];
16
+ if (define.method === FlowGramAPIMethod.GET) {
17
+ const procedure = publicProcedure
18
+ .meta({
19
+ openapi: {
20
+ method: define.method,
21
+ path: define.path,
22
+ summary: define.name,
23
+ tags: [define.module],
24
+ },
25
+ })
26
+ .input(define.schema.input)
27
+ .output(z.union([define.schema.output, z.undefined()]))
28
+ .query(async (opts) => {
29
+ const input = opts.input;
30
+ try {
31
+ const output = await caller(input);
32
+ return output;
33
+ } catch {
34
+ return undefined;
35
+ }
36
+ });
37
+
38
+ return {
39
+ define,
40
+ procedure: procedure as any,
41
+ };
42
+ }
43
+
44
+ const procedure = publicProcedure
45
+ .meta({
46
+ openapi: {
47
+ method: define.method,
48
+ path: define.path,
49
+ summary: define.name,
50
+ tags: [define.module],
51
+ },
52
+ })
53
+ .input(define.schema.input)
54
+ .output(z.union([define.schema.output, z.undefined()]))
55
+ .mutation(async (opts) => {
56
+ const input = opts.input;
57
+ try {
58
+ const output = await caller(input);
59
+ return output;
60
+ } catch {
61
+ return undefined;
62
+ }
63
+ });
64
+ return {
65
+ define,
66
+ procedure: procedure as any,
67
+ };
68
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { FlowGramAPINames } from '@flowgram.ai/runtime-interface';
7
+
8
+ import { APIRouter } from './type';
9
+ import { router } from './trpc';
10
+ import { createAPI } from './create-api';
11
+
12
+ const APIS = FlowGramAPINames.map((apiName) => createAPI(apiName));
13
+
14
+ export const routers = APIS.reduce((acc, api) => {
15
+ acc[api.define.path] = api.procedure;
16
+ return acc;
17
+ }, {} as APIRouter);
18
+
19
+ export const appRouter = router(routers);
20
+
21
+ export type AppRouter = typeof appRouter;