@eggjs/controller-decorator 4.0.2-beta.1 → 4.0.2-beta.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.
@@ -0,0 +1,6 @@
1
+ import { EggProtoImplClass } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/agent/AgentController.d.ts
4
+ declare function AgentController(): (constructor: EggProtoImplClass) => void;
5
+ //#endregion
6
+ export { AgentController };
@@ -0,0 +1,141 @@
1
+ import { ControllerInfoUtil } from "../../util/ControllerInfoUtil.js";
2
+ import { MethodInfoUtil } from "../../util/MethodInfoUtil.js";
3
+ import { AgentInfoUtil } from "../../util/AgentInfoUtil.js";
4
+ import { HTTPInfoUtil } from "../../util/HTTPInfoUtil.js";
5
+ import { PrototypeUtil, SingletonProto } from "@eggjs/core-decorator";
6
+ import { AGENT_CONTROLLER_PROTO_IMPL_TYPE, AccessLevel, ControllerType, HTTPMethodEnum, HTTPParamType } from "@eggjs/tegg-types";
7
+ import { StackUtil } from "@eggjs/tegg-common-util";
8
+
9
+ //#region src/decorator/agent/AgentController.ts
10
+ function createNotImplemented(methodName, paramCount) {
11
+ let fn;
12
+ if (paramCount >= 2) fn = async function(_a, _b) {
13
+ throw new Error(`${methodName} not implemented`);
14
+ };
15
+ else if (paramCount === 1) fn = async function(_arg) {
16
+ throw new Error(`${methodName} not implemented`);
17
+ };
18
+ else fn = async function() {
19
+ throw new Error(`${methodName} not implemented`);
20
+ };
21
+ AgentInfoUtil.setNotImplemented(fn);
22
+ return fn;
23
+ }
24
+ const AGENT_ROUTES = [
25
+ {
26
+ methodName: "createThread",
27
+ httpMethod: HTTPMethodEnum.POST,
28
+ path: "/threads",
29
+ params: []
30
+ },
31
+ {
32
+ methodName: "getThread",
33
+ httpMethod: HTTPMethodEnum.GET,
34
+ path: "/threads/:id",
35
+ params: [{
36
+ index: 0,
37
+ type: "pathParam",
38
+ name: "id"
39
+ }]
40
+ },
41
+ {
42
+ methodName: "getLatestRunId",
43
+ httpMethod: HTTPMethodEnum.GET,
44
+ path: "/threads/:id/latest-run",
45
+ params: [{
46
+ index: 0,
47
+ type: "pathParam",
48
+ name: "id"
49
+ }]
50
+ },
51
+ {
52
+ methodName: "asyncRun",
53
+ httpMethod: HTTPMethodEnum.POST,
54
+ path: "/runs",
55
+ params: [{
56
+ index: 0,
57
+ type: "body"
58
+ }]
59
+ },
60
+ {
61
+ methodName: "streamRun",
62
+ httpMethod: HTTPMethodEnum.POST,
63
+ path: "/runs/stream",
64
+ params: [{
65
+ index: 0,
66
+ type: "body"
67
+ }]
68
+ },
69
+ {
70
+ methodName: "getRunStream",
71
+ httpMethod: HTTPMethodEnum.GET,
72
+ path: "/runs/:id/stream",
73
+ params: [{
74
+ index: 0,
75
+ type: "pathParam",
76
+ name: "id"
77
+ }, {
78
+ index: 1,
79
+ type: "query",
80
+ name: "lastSeq"
81
+ }]
82
+ },
83
+ {
84
+ methodName: "syncRun",
85
+ httpMethod: HTTPMethodEnum.POST,
86
+ path: "/runs/wait",
87
+ params: [{
88
+ index: 0,
89
+ type: "body"
90
+ }]
91
+ },
92
+ {
93
+ methodName: "getRun",
94
+ httpMethod: HTTPMethodEnum.GET,
95
+ path: "/runs/:id",
96
+ params: [{
97
+ index: 0,
98
+ type: "pathParam",
99
+ name: "id"
100
+ }]
101
+ },
102
+ {
103
+ methodName: "cancelRun",
104
+ httpMethod: HTTPMethodEnum.POST,
105
+ path: "/runs/:id/cancel",
106
+ params: [{
107
+ index: 0,
108
+ type: "pathParam",
109
+ name: "id"
110
+ }]
111
+ }
112
+ ];
113
+ function AgentController() {
114
+ return function(constructor) {
115
+ ControllerInfoUtil.setControllerType(constructor, ControllerType.HTTP);
116
+ HTTPInfoUtil.setHTTPPath("/api/v1", constructor);
117
+ SingletonProto({
118
+ accessLevel: AccessLevel.PUBLIC,
119
+ protoImplType: AGENT_CONTROLLER_PROTO_IMPL_TYPE
120
+ })(constructor);
121
+ PrototypeUtil.setFilePath(constructor, StackUtil.getCalleeFromStack(false, 5));
122
+ for (const route of AGENT_ROUTES) {
123
+ if (!constructor.prototype[route.methodName]) constructor.prototype[route.methodName] = createNotImplemented(route.methodName, route.params.length);
124
+ MethodInfoUtil.setMethodControllerType(constructor, route.methodName, ControllerType.HTTP);
125
+ HTTPInfoUtil.setHTTPMethodMethod(route.httpMethod, constructor, route.methodName);
126
+ HTTPInfoUtil.setHTTPMethodPath(route.path, constructor, route.methodName);
127
+ for (const param of route.params) if (param.type === "body") HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.BODY, param.index, constructor, route.methodName);
128
+ else if (param.type === "pathParam") {
129
+ HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.PARAM, param.index, constructor, route.methodName);
130
+ HTTPInfoUtil.setHTTPMethodParamName(param.name, param.index, constructor, route.methodName);
131
+ } else if (param.type === "query") {
132
+ HTTPInfoUtil.setHTTPMethodParamType(HTTPParamType.QUERY, param.index, constructor, route.methodName);
133
+ HTTPInfoUtil.setHTTPMethodParamName(param.name, param.index, constructor, route.methodName);
134
+ }
135
+ }
136
+ AgentInfoUtil.setAgentController(constructor);
137
+ };
138
+ }
139
+
140
+ //#endregion
141
+ export { AgentController };
@@ -0,0 +1,33 @@
1
+ import { AgentMessage, CreateRunInput, RunObject, ThreadObject, ThreadObjectWithMessages } from "@eggjs/tegg-types/agent-runtime";
2
+
3
+ //#region src/decorator/agent/AgentHandler.d.ts
4
+ interface AgentHandler {
5
+ execRun(input: CreateRunInput, signal?: AbortSignal): AsyncGenerator<AgentMessage>;
6
+ /** Create the AgentStore used to persist threads and runs. */
7
+ createStore(): Promise<unknown>;
8
+ /**
9
+ * Optional hook to decide whether the executor's underlying session has
10
+ * been committed to persistent storage (for example the Claude Code SDK
11
+ * jsonl file on disk). The runtime calls this each time a new message is
12
+ * yielded from `execRun`; once it returns true, `cancelRun` is allowed to
13
+ * abort and persist the thread.
14
+ *
15
+ * When not implemented, the runtime uses a default heuristic: any message
16
+ * with `type !== 'system'` counts as committed (covers the Claude Code SDK
17
+ * case where `system/init` is emitted before the session is fully written).
18
+ */
19
+ isSessionCommitted?(msg: AgentMessage, history: AgentMessage[]): boolean | Promise<boolean>;
20
+ createThread?(): Promise<ThreadObject>;
21
+ getThread?(threadId: string): Promise<ThreadObjectWithMessages>;
22
+ getLatestRunId?(threadId: string): Promise<{
23
+ threadId: string;
24
+ runId: string | null;
25
+ }>;
26
+ asyncRun?(input: CreateRunInput): Promise<RunObject>;
27
+ streamRun?(input: CreateRunInput): Promise<void>;
28
+ syncRun?(input: CreateRunInput): Promise<RunObject>;
29
+ getRun?(runId: string): Promise<RunObject>;
30
+ cancelRun?(runId: string): Promise<RunObject>;
31
+ }
32
+ //#endregion
33
+ export { AgentHandler };
@@ -0,0 +1,2 @@
1
+ import { AgentController } from "./AgentController.js";
2
+ import { AgentHandler } from "./AgentHandler.js";
@@ -0,0 +1,3 @@
1
+ import { AgentController } from "./AgentController.js";
2
+
3
+ export { };
@@ -10,5 +10,8 @@ import { MCPPrompt, PromptArgsSchema } from "./mcp/MCPPrompt.js";
10
10
  import { MCPResource } from "./mcp/MCPResource.js";
11
11
  import { MCPTool, ToolArgsSchema } from "./mcp/MCPTool.js";
12
12
  import "./mcp/index.js";
13
+ import { AgentController } from "./agent/AgentController.js";
14
+ import { AgentHandler } from "./agent/AgentHandler.js";
15
+ import "./agent/index.js";
13
16
  import { Acl } from "./Acl.js";
14
17
  import { Middleware } from "./Middleware.js";
@@ -10,6 +10,8 @@ import { MCPPrompt, PromptArgsSchema } from "./mcp/MCPPrompt.js";
10
10
  import { MCPResource } from "./mcp/MCPResource.js";
11
11
  import { MCPTool, ToolArgsSchema } from "./mcp/MCPTool.js";
12
12
  import "./mcp/index.js";
13
+ import { AgentController } from "./agent/AgentController.js";
14
+ import "./agent/index.js";
13
15
  import { Acl } from "./Acl.js";
14
16
  import { Middleware } from "./Middleware.js";
15
17
 
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ import { MCPController } from "./decorator/mcp/MCPController.js";
10
10
  import { MCPPrompt, PromptArgsSchema } from "./decorator/mcp/MCPPrompt.js";
11
11
  import { MCPResource } from "./decorator/mcp/MCPResource.js";
12
12
  import { MCPTool, ToolArgsSchema } from "./decorator/mcp/MCPTool.js";
13
+ import { AgentController } from "./decorator/agent/AgentController.js";
14
+ import { AgentHandler } from "./decorator/agent/AgentHandler.js";
13
15
  import { Acl } from "./decorator/Acl.js";
14
16
  import { Middleware } from "./decorator/Middleware.js";
15
17
  import "./decorator/index.js";
@@ -32,6 +34,7 @@ import { MCPControllerToolMetaBuilder } from "./impl/mcp/MCPControllerToolMetaBu
32
34
  import "./impl/index.js";
33
35
  import { ControllerValidator } from "./util/validator/ControllerValidator.js";
34
36
  import { MethodValidator } from "./util/validator/MethodValidator.js";
37
+ import { AgentInfoUtil } from "./util/AgentInfoUtil.js";
35
38
  import { ControllerInfoUtil } from "./util/ControllerInfoUtil.js";
36
39
  import { ControllerMetadataUtil } from "./util/ControllerMetadataUtil.js";
37
40
  import { HTTPInfoUtil } from "./util/HTTPInfoUtil.js";
@@ -39,4 +42,4 @@ import { HTTPPriorityUtil } from "./util/HTTPPriorityUtil.js";
39
42
  import { MethodInfoUtil } from "./util/MethodInfoUtil.js";
40
43
  import "./util/index.js";
41
44
  export * from "@eggjs/tegg-types/controller-decorator";
42
- export { Acl, BodyParamMeta, ControllerInfoUtil, ControllerMetaBuilderFactory, ControllerMetadataUtil, ControllerValidator, Cookies, CookiesParamMeta, Extra, HTTPBody, InjectContext as HTTPContext, HTTPController, HTTPControllerMeta, HTTPControllerMetaBuilder, HTTPControllerMethodMetaBuilder, HTTPCookies, HTTPHeaders, HTTPInfoUtil, HTTPMethod, HTTPMethodMeta, HTTPParam, HTTPPriorityUtil, HTTPQueries, HTTPQuery, HTTPRequest, HTTPResponse, HeadersParamMeta, Host, InjectContext, MCPController, MCPControllerMeta, MCPControllerMetaBuilder, MCPControllerPromptMetaBuilder, MCPControllerResourceMetaBuilder, MCPControllerToolMetaBuilder, MCPInfoUtil, MCPPrompt, MCPPromptMeta, MCPResource, MCPResourceMeta, MCPTool, MCPToolMeta, MethodInfoUtil, MethodValidator, Middleware, ParamMeta, ParamMetaUtil, PathParamMeta, PromptArgsSchema, PromptArgsSchemaDetail, QueriesParamMeta, QueryParamMeta, RequestParamMeta, ToolArgsSchema, ToolArgsSchemaDetail };
45
+ export { Acl, AgentController, AgentHandler, AgentInfoUtil, BodyParamMeta, ControllerInfoUtil, ControllerMetaBuilderFactory, ControllerMetadataUtil, ControllerValidator, Cookies, CookiesParamMeta, Extra, HTTPBody, InjectContext as HTTPContext, HTTPController, HTTPControllerMeta, HTTPControllerMetaBuilder, HTTPControllerMethodMetaBuilder, HTTPCookies, HTTPHeaders, HTTPInfoUtil, HTTPMethod, HTTPMethodMeta, HTTPParam, HTTPPriorityUtil, HTTPQueries, HTTPQuery, HTTPRequest, HTTPResponse, HeadersParamMeta, Host, InjectContext, MCPController, MCPControllerMeta, MCPControllerMetaBuilder, MCPControllerPromptMetaBuilder, MCPControllerResourceMetaBuilder, MCPControllerToolMetaBuilder, MCPInfoUtil, MCPPrompt, MCPPromptMeta, MCPResource, MCPResourceMeta, MCPTool, MCPToolMeta, MethodInfoUtil, MethodValidator, Middleware, ParamMeta, ParamMetaUtil, PathParamMeta, PromptArgsSchema, PromptArgsSchemaDetail, QueriesParamMeta, QueryParamMeta, RequestParamMeta, ToolArgsSchema, ToolArgsSchemaDetail };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { ControllerInfoUtil } from "./util/ControllerInfoUtil.js";
2
2
  import { ControllerValidator } from "./util/validator/ControllerValidator.js";
3
3
  import { MethodInfoUtil } from "./util/MethodInfoUtil.js";
4
4
  import { MethodValidator } from "./util/validator/MethodValidator.js";
5
+ import { AgentInfoUtil } from "./util/AgentInfoUtil.js";
5
6
  import { ControllerMetadataUtil } from "./util/ControllerMetadataUtil.js";
6
7
  import { HTTPInfoUtil } from "./util/HTTPInfoUtil.js";
7
8
  import { HTTPPriorityUtil } from "./util/HTTPPriorityUtil.js";
@@ -19,6 +20,7 @@ import { MCPController } from "./decorator/mcp/MCPController.js";
19
20
  import { MCPPrompt, PromptArgsSchema } from "./decorator/mcp/MCPPrompt.js";
20
21
  import { MCPResource } from "./decorator/mcp/MCPResource.js";
21
22
  import { MCPTool, ToolArgsSchema } from "./decorator/mcp/MCPTool.js";
23
+ import { AgentController } from "./decorator/agent/AgentController.js";
22
24
  import { Acl } from "./decorator/Acl.js";
23
25
  import { Middleware } from "./decorator/Middleware.js";
24
26
  import "./decorator/index.js";
@@ -41,4 +43,4 @@ import "./impl/index.js";
41
43
 
42
44
  export * from "@eggjs/tegg-types/controller-decorator"
43
45
 
44
- export { Acl, BodyParamMeta, ControllerInfoUtil, ControllerMetaBuilderFactory, ControllerMetadataUtil, ControllerValidator, Cookies, CookiesParamMeta, Extra, HTTPBody, InjectContext as HTTPContext, HTTPController, HTTPControllerMeta, HTTPControllerMetaBuilder, HTTPControllerMethodMetaBuilder, HTTPCookies, HTTPHeaders, HTTPInfoUtil, HTTPMethod, HTTPMethodMeta, HTTPParam, HTTPPriorityUtil, HTTPQueries, HTTPQuery, HTTPRequest, HTTPResponse, HeadersParamMeta, Host, InjectContext, MCPController, MCPControllerMeta, MCPControllerMetaBuilder, MCPControllerPromptMetaBuilder, MCPControllerResourceMetaBuilder, MCPControllerToolMetaBuilder, MCPInfoUtil, MCPPrompt, MCPPromptMeta, MCPResource, MCPResourceMeta, MCPTool, MCPToolMeta, MethodInfoUtil, MethodValidator, Middleware, ParamMeta, ParamMetaUtil, PathParamMeta, PromptArgsSchema, QueriesParamMeta, QueryParamMeta, RequestParamMeta, ToolArgsSchema };
46
+ export { Acl, AgentController, AgentInfoUtil, BodyParamMeta, ControllerInfoUtil, ControllerMetaBuilderFactory, ControllerMetadataUtil, ControllerValidator, Cookies, CookiesParamMeta, Extra, HTTPBody, InjectContext as HTTPContext, HTTPController, HTTPControllerMeta, HTTPControllerMetaBuilder, HTTPControllerMethodMetaBuilder, HTTPCookies, HTTPHeaders, HTTPInfoUtil, HTTPMethod, HTTPMethodMeta, HTTPParam, HTTPPriorityUtil, HTTPQueries, HTTPQuery, HTTPRequest, HTTPResponse, HeadersParamMeta, Host, InjectContext, MCPController, MCPControllerMeta, MCPControllerMetaBuilder, MCPControllerPromptMetaBuilder, MCPControllerResourceMetaBuilder, MCPControllerToolMetaBuilder, MCPInfoUtil, MCPPrompt, MCPPromptMeta, MCPResource, MCPResourceMeta, MCPTool, MCPToolMeta, MethodInfoUtil, MethodValidator, Middleware, ParamMeta, ParamMetaUtil, PathParamMeta, PromptArgsSchema, QueriesParamMeta, QueryParamMeta, RequestParamMeta, ToolArgsSchema };
@@ -0,0 +1,13 @@
1
+ import { EggProtoImplClass } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/AgentInfoUtil.d.ts
4
+ declare class AgentInfoUtil {
5
+ static setAgentController(clazz: EggProtoImplClass): void;
6
+ static isAgentController(clazz: EggProtoImplClass): boolean;
7
+ static setNotImplemented(fn: Function): void;
8
+ static isNotImplemented(fn: Function): boolean;
9
+ static setEnhanced(clazz: EggProtoImplClass): void;
10
+ static isEnhanced(clazz: EggProtoImplClass): boolean;
11
+ }
12
+ //#endregion
13
+ export { AgentInfoUtil };
@@ -0,0 +1,27 @@
1
+ import { MetadataUtil } from "@eggjs/core-decorator";
2
+ import { CONTROLLER_AGENT_CONTROLLER, CONTROLLER_AGENT_ENHANCED, CONTROLLER_AGENT_NOT_IMPLEMENTED } from "@eggjs/tegg-types";
3
+
4
+ //#region src/util/AgentInfoUtil.ts
5
+ var AgentInfoUtil = class {
6
+ static setAgentController(clazz) {
7
+ MetadataUtil.defineMetaData(CONTROLLER_AGENT_CONTROLLER, true, clazz);
8
+ }
9
+ static isAgentController(clazz) {
10
+ return MetadataUtil.getBooleanMetaData(CONTROLLER_AGENT_CONTROLLER, clazz);
11
+ }
12
+ static setNotImplemented(fn) {
13
+ Reflect.defineMetadata(CONTROLLER_AGENT_NOT_IMPLEMENTED, true, fn);
14
+ }
15
+ static isNotImplemented(fn) {
16
+ return !!Reflect.getMetadata(CONTROLLER_AGENT_NOT_IMPLEMENTED, fn);
17
+ }
18
+ static setEnhanced(clazz) {
19
+ MetadataUtil.defineMetaData(CONTROLLER_AGENT_ENHANCED, true, clazz);
20
+ }
21
+ static isEnhanced(clazz) {
22
+ return MetadataUtil.getBooleanMetaData(CONTROLLER_AGENT_ENHANCED, clazz);
23
+ }
24
+ };
25
+
26
+ //#endregion
27
+ export { AgentInfoUtil };
@@ -2,6 +2,7 @@ import { MCPInfoUtil, PromptArgsSchemaDetail, ToolArgsSchemaDetail } from "./MCP
2
2
  import { ControllerValidator } from "./validator/ControllerValidator.js";
3
3
  import { MethodValidator } from "./validator/MethodValidator.js";
4
4
  import "./validator/index.js";
5
+ import { AgentInfoUtil } from "./AgentInfoUtil.js";
5
6
  import { ControllerInfoUtil } from "./ControllerInfoUtil.js";
6
7
  import { ControllerMetadataUtil } from "./ControllerMetadataUtil.js";
7
8
  import { HTTPInfoUtil } from "./HTTPInfoUtil.js";
@@ -3,6 +3,7 @@ import { ControllerValidator } from "./validator/ControllerValidator.js";
3
3
  import { MethodInfoUtil } from "./MethodInfoUtil.js";
4
4
  import { MethodValidator } from "./validator/MethodValidator.js";
5
5
  import "./validator/index.js";
6
+ import { AgentInfoUtil } from "./AgentInfoUtil.js";
6
7
  import { ControllerMetadataUtil } from "./ControllerMetadataUtil.js";
7
8
  import { HTTPInfoUtil } from "./HTTPInfoUtil.js";
8
9
  import { HTTPPriorityUtil } from "./HTTPPriorityUtil.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/controller-decorator",
3
- "version": "4.0.2-beta.1",
3
+ "version": "4.0.2-beta.10",
4
4
  "description": "tegg controller decorator",
5
5
  "keywords": [
6
6
  "controller",
@@ -38,17 +38,17 @@
38
38
  "@modelcontextprotocol/sdk": "^1.23.0",
39
39
  "is-type-of": "^2.2.0",
40
40
  "path-to-regexp": "^1.9.0",
41
- "@eggjs/aop-decorator": "4.0.2-beta.1",
42
- "@eggjs/cookies": "4.0.2-beta.1",
43
- "@eggjs/metadata": "4.0.2-beta.1",
44
- "@eggjs/core-decorator": "4.0.2-beta.1",
45
- "@eggjs/tegg-common-util": "4.0.2-beta.1",
46
- "@eggjs/tegg-types": "4.0.2-beta.1"
41
+ "@eggjs/aop-decorator": "4.0.2-beta.10",
42
+ "@eggjs/core-decorator": "4.0.2-beta.10",
43
+ "@eggjs/metadata": "4.0.2-beta.10",
44
+ "@eggjs/tegg-common-util": "4.0.2-beta.10",
45
+ "@eggjs/cookies": "4.0.2-beta.10",
46
+ "@eggjs/tegg-types": "4.0.2-beta.10"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^24.10.2",
50
50
  "typescript": "^5.9.3",
51
- "egg": "4.1.2-beta.1"
51
+ "egg": "4.1.2-beta.10"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22.18.0"