@flowgram.ai/runtime-nodejs 0.2.23 → 0.2.25
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 +1 -1
- package/dist/index.js +30 -54
- package/dist/index.js.map +1 -1
- package/package.json +18 -8
- package/.eslintignore +0 -1
- package/.eslintrc.cjs +0 -29
- package/.rush/temp/chunked-rush-logs/runtime-nodejs.build.chunks.jsonl +0 -21
- package/.rush/temp/package-deps_build.json +0 -23
- package/.rush/temp/shrinkwrap-deps.json +0 -718
- package/CHANGELOG.json +0 -11
- package/CHANGELOG.md +0 -9
- package/dist/esm/index.js +0 -192
- package/dist/esm/index.js.map +0 -1
- package/dist/index.d.mts +0 -2
- package/rush-logs/runtime-nodejs.build.error.log +0 -0
- package/rush-logs/runtime-nodejs.build.log +0 -21
- package/src/api/create-api.ts +0 -68
- package/src/api/index.ts +0 -21
- package/src/api/trpc.ts +0 -21
- package/src/api/type.ts +0 -14
- package/src/config/index.ts +0 -18
- package/src/index.ts +0 -13
- package/src/server/context.ts +0 -13
- package/src/server/docs.ts +0 -19
- package/src/server/index.ts +0 -94
- package/src/server/type.ts +0 -13
- package/tsconfig.json +0 -48
- package/vitest.config.ts +0 -45
package/CHANGELOG.json
DELETED
package/CHANGELOG.md
DELETED
package/dist/esm/index.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
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
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AA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AAE,QAAQ,OAAO,KAAK;AAC/B;;;AOtFA,eAAe,OAAO;AACpB,QAAM,SAAS,MAAM,aAAa;AAClC,SAAO,MAAM;AACf;AAEA,KAAK;","names":["procedure"]}
|
package/dist/index.d.mts
DELETED
|
File without changes
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
CJS dist/index.js 6.67 KB
|
|
13
|
-
CJS dist/index.js.map 11.10 KB
|
|
14
|
-
CJS ⚡️ Build success in 73ms
|
|
15
|
-
ESM dist/esm/index.js 5.09 KB
|
|
16
|
-
ESM dist/esm/index.js.map 10.94 KB
|
|
17
|
-
ESM ⚡️ Build success in 78ms
|
|
18
|
-
DTS Build start
|
|
19
|
-
DTS ⚡️ Build success in 5593ms
|
|
20
|
-
DTS dist/index.d.ts 13.00 B
|
|
21
|
-
DTS dist/index.d.mts 13.00 B
|
package/src/api/create-api.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
};
|
package/src/api/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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;
|
package/src/api/trpc.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { OpenApiMeta } from 'trpc-openapi';
|
|
7
|
-
import { initTRPC } from '@trpc/server';
|
|
8
|
-
|
|
9
|
-
import type { Context } from '../server/context';
|
|
10
|
-
|
|
11
|
-
const t = initTRPC
|
|
12
|
-
.context<Context>()
|
|
13
|
-
.meta<OpenApiMeta>()
|
|
14
|
-
.create({
|
|
15
|
-
errorFormatter({ shape }) {
|
|
16
|
-
return shape;
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export const router = t.router;
|
|
21
|
-
export const publicProcedure = t.procedure;
|
package/src/api/type.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { BuildProcedure } from '@trpc/server';
|
|
7
|
-
import { FlowGramAPIDefine } from '@flowgram.ai/runtime-interface';
|
|
8
|
-
|
|
9
|
-
export interface APIHandler {
|
|
10
|
-
define: FlowGramAPIDefine;
|
|
11
|
-
procedure: BuildProcedure<any, any, any>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type APIRouter = Record<FlowGramAPIDefine['path'], APIHandler['procedure']>;
|
package/src/config/index.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { ServerParams } from '@server/type';
|
|
7
|
-
|
|
8
|
-
export const ServerConfig: ServerParams = {
|
|
9
|
-
name: 'flowgram-runtime',
|
|
10
|
-
title: 'FlowGram Runtime',
|
|
11
|
-
description: 'FlowGram Runtime Demo',
|
|
12
|
-
runtime: 'nodejs',
|
|
13
|
-
version: '0.0.1',
|
|
14
|
-
dev: false,
|
|
15
|
-
port: 4000,
|
|
16
|
-
basePath: '/api',
|
|
17
|
-
docsPath: '/docs',
|
|
18
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createServer } from '@server/index';
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
const server = await createServer();
|
|
10
|
-
server.start();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
main();
|
package/src/server/context.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { CreateFastifyContextOptions } from '@trpc/server/adapters/fastify';
|
|
7
|
-
|
|
8
|
-
export function createContext(ctx: CreateFastifyContextOptions) {
|
|
9
|
-
const { req, res } = ctx;
|
|
10
|
-
return { req, res };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type Context = Awaited<ReturnType<typeof createContext>>;
|
package/src/server/docs.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { generateOpenApiDocument } from 'trpc-openapi';
|
|
7
|
-
|
|
8
|
-
import { ServerConfig } from '@config/index';
|
|
9
|
-
import { appRouter } from '@api/index';
|
|
10
|
-
|
|
11
|
-
// Generate OpenAPI schema document
|
|
12
|
-
export const serverDocument = generateOpenApiDocument(appRouter, {
|
|
13
|
-
title: ServerConfig.title,
|
|
14
|
-
description: ServerConfig.description,
|
|
15
|
-
version: ServerConfig.version,
|
|
16
|
-
baseUrl: `http://localhost:${ServerConfig.port}${ServerConfig.basePath}`,
|
|
17
|
-
docsUrl: 'https://flowgram.ai',
|
|
18
|
-
tags: ['Task'],
|
|
19
|
-
});
|
package/src/server/index.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { fastifyTRPCOpenApiPlugin } from 'trpc-openapi';
|
|
7
|
-
import fastify from 'fastify';
|
|
8
|
-
import { fastifyTRPCPlugin } from '@trpc/server/adapters/fastify';
|
|
9
|
-
import { ServerInfoDefine, type ServerInfoOutput } from '@flowgram.ai/runtime-interface';
|
|
10
|
-
import ws from '@fastify/websocket';
|
|
11
|
-
import fastifySwaggerUI from '@fastify/swagger-ui';
|
|
12
|
-
import fastifySwagger from '@fastify/swagger';
|
|
13
|
-
import cors from '@fastify/cors';
|
|
14
|
-
|
|
15
|
-
import { ServerConfig } from '@config/index';
|
|
16
|
-
import { appRouter } from '@api/index';
|
|
17
|
-
import { serverDocument } from './docs';
|
|
18
|
-
import { createContext } from './context';
|
|
19
|
-
|
|
20
|
-
export async function createServer() {
|
|
21
|
-
const server = fastify({ logger: ServerConfig.dev });
|
|
22
|
-
|
|
23
|
-
await server.register(cors);
|
|
24
|
-
await server.register(ws);
|
|
25
|
-
await server.register(fastifyTRPCPlugin, {
|
|
26
|
-
prefix: '/trpc',
|
|
27
|
-
useWss: false,
|
|
28
|
-
trpcOptions: { router: appRouter, createContext },
|
|
29
|
-
});
|
|
30
|
-
await server.register(fastifyTRPCOpenApiPlugin, {
|
|
31
|
-
basePath: ServerConfig.basePath,
|
|
32
|
-
router: appRouter,
|
|
33
|
-
createContext,
|
|
34
|
-
} as any);
|
|
35
|
-
|
|
36
|
-
await server.register(fastifySwagger, {
|
|
37
|
-
mode: 'static',
|
|
38
|
-
specification: { document: serverDocument },
|
|
39
|
-
uiConfig: { displayOperationId: true },
|
|
40
|
-
exposeRoute: true,
|
|
41
|
-
} as any);
|
|
42
|
-
|
|
43
|
-
await server.register(fastifySwaggerUI, {
|
|
44
|
-
routePrefix: ServerConfig.docsPath,
|
|
45
|
-
uiConfig: {
|
|
46
|
-
docExpansion: 'full',
|
|
47
|
-
deepLinking: false,
|
|
48
|
-
},
|
|
49
|
-
uiHooks: {
|
|
50
|
-
onRequest: function (request, reply, next) {
|
|
51
|
-
next();
|
|
52
|
-
},
|
|
53
|
-
preHandler: function (request, reply, next) {
|
|
54
|
-
next();
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
staticCSP: true,
|
|
58
|
-
transformStaticCSP: (header) => header,
|
|
59
|
-
transformSpecification: (swaggerObject, request, reply) => swaggerObject,
|
|
60
|
-
transformSpecificationClone: true,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
server.get(ServerInfoDefine.path, async (): Promise<ServerInfoOutput> => {
|
|
64
|
-
const serverTime = new Date();
|
|
65
|
-
const output: ServerInfoOutput = {
|
|
66
|
-
name: ServerConfig.name,
|
|
67
|
-
title: ServerConfig.title,
|
|
68
|
-
description: ServerConfig.description,
|
|
69
|
-
runtime: ServerConfig.runtime,
|
|
70
|
-
version: ServerConfig.version,
|
|
71
|
-
time: serverTime.toISOString(),
|
|
72
|
-
};
|
|
73
|
-
return output;
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const stop = async () => {
|
|
77
|
-
await server.close();
|
|
78
|
-
};
|
|
79
|
-
const start = async () => {
|
|
80
|
-
try {
|
|
81
|
-
const address = await server.listen({ port: ServerConfig.port });
|
|
82
|
-
await server.ready();
|
|
83
|
-
server.swagger();
|
|
84
|
-
console.log(
|
|
85
|
-
`> Listen Port: ${ServerConfig.port}\n> Server Address: ${address}\n> API Docs: http://localhost:4000/docs`
|
|
86
|
-
);
|
|
87
|
-
} catch (err) {
|
|
88
|
-
server.log.error(err);
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return { server, start, stop };
|
|
94
|
-
}
|
package/src/server/type.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ServerInfoOutput } from '@flowgram.ai/runtime-interface';
|
|
7
|
-
|
|
8
|
-
export interface ServerParams extends Omit<ServerInfoOutput, 'time'> {
|
|
9
|
-
dev: boolean;
|
|
10
|
-
port: number;
|
|
11
|
-
basePath: string;
|
|
12
|
-
docsPath: string;
|
|
13
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@flowgram.ai/ts-config/tsconfig.flow.path.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"target": "esnext",
|
|
5
|
-
"lib": [
|
|
6
|
-
"dom",
|
|
7
|
-
"dom.iterable",
|
|
8
|
-
"esnext"
|
|
9
|
-
],
|
|
10
|
-
"allowJs": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"noEmit": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"module": "esnext",
|
|
16
|
-
"moduleResolution": "bundler",
|
|
17
|
-
"resolveJsonModule": true,
|
|
18
|
-
"isolatedModules": true,
|
|
19
|
-
"jsx": "preserve",
|
|
20
|
-
"plugins": [],
|
|
21
|
-
"baseUrl": "src",
|
|
22
|
-
"paths": {
|
|
23
|
-
"@api/*": [
|
|
24
|
-
"api/*"
|
|
25
|
-
],
|
|
26
|
-
"@application/*": [
|
|
27
|
-
"application/*"
|
|
28
|
-
],
|
|
29
|
-
"@server/*": [
|
|
30
|
-
"server/*"
|
|
31
|
-
],
|
|
32
|
-
"@config/*": [
|
|
33
|
-
"config/*"
|
|
34
|
-
],
|
|
35
|
-
"@workflow/*": [
|
|
36
|
-
"workflow/*"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"include": [
|
|
41
|
-
"**/*.ts",
|
|
42
|
-
"**/*.tsx",
|
|
43
|
-
"src/workflow/executor/condition/constant.ts"
|
|
44
|
-
],
|
|
45
|
-
"exclude": [
|
|
46
|
-
"node_modules"
|
|
47
|
-
]
|
|
48
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { config } from "dotenv";
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { defineConfig } from 'vitest/config';
|
|
9
|
-
|
|
10
|
-
export default defineConfig({
|
|
11
|
-
build: {
|
|
12
|
-
commonjsOptions: {
|
|
13
|
-
transformMixedEsModules: true,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
resolve: {
|
|
17
|
-
alias: [
|
|
18
|
-
{find: "@api", replacement: path.resolve(__dirname, './src/api') },
|
|
19
|
-
{find: "@application", replacement: path.resolve(__dirname, './src/application') },
|
|
20
|
-
{find: "@server", replacement: path.resolve(__dirname, './src/server') },
|
|
21
|
-
{find: "@config", replacement: path.resolve(__dirname, './src/config') },
|
|
22
|
-
{find: "@workflow", replacement: path.resolve(__dirname, './src/workflow') },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
test: {
|
|
26
|
-
globals: true,
|
|
27
|
-
mockReset: false,
|
|
28
|
-
environment: 'jsdom',
|
|
29
|
-
testTimeout: 15000,
|
|
30
|
-
setupFiles: [path.resolve(__dirname, './src/workflow/__tests__/setup.ts')],
|
|
31
|
-
include: ['**/?(*.){test,spec}.?(c|m)[jt]s?(x)'],
|
|
32
|
-
exclude: [
|
|
33
|
-
'**/__mocks__**',
|
|
34
|
-
'**/node_modules/**',
|
|
35
|
-
'**/dist/**',
|
|
36
|
-
'**/lib/**', // lib 编译结果忽略掉
|
|
37
|
-
'**/cypress/**',
|
|
38
|
-
'**/.{idea,git,cache,output,temp}/**',
|
|
39
|
-
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
|
|
40
|
-
],
|
|
41
|
-
env: {
|
|
42
|
-
...config({ path: path.resolve(__dirname, './.env/.env.test') }).parsed
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
});
|