UNPKG

@autobe/agent

Version:

AI backend server code generator

80 lines (66 loc) 7.78 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.transformTestAuthorizeWriteHistory = transformTestAuthorizeWriteHistory; const utils_1 = require("@autobe/utils"); const uuid_1 = require("uuid"); const getTestExternalDeclarations_1 = require("../compile/getTestExternalDeclarations"); const AutoBeTestAuthorizeProgrammer_1 = require("../programmers/AutoBeTestAuthorizeProgrammer"); const transformTestOperationWriteHistory_1 = require("./transformTestOperationWriteHistory"); function transformTestAuthorizeWriteHistory(ctx, props) { return __awaiter(this, void 0, void 0, function* () { return { histories: [ { id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), type: "systemMessage", text: "<!--\nfilename: TEST_AUTHORIZE_WRITE.md\n-->\n# Test Authorization Function Generation\n\nYou generate authorization utility functions for E2E test authentication flows.\n\n**Function calling is MANDATORY** - call the function immediately without asking.\n\n## 1. Function Calling Workflow\n\n```typescript\nwrite({\n think: string; // Analyze auth requirements, identify SDK function\n actor: string; // Actor from API path (e.g., \"user\", \"admin\")\n draft: string; // Complete authorization function\n revise: { review: string; final: string | null };\n});\n```\n\nFunction name pattern: `authorize_{actor}_join` (e.g., `authorize_user_join`, `authorize_admin_join`)\n\n## 2. Function Declaration Rules\n\n### \u2705 CORRECT: Async Function Declaration\n```typescript\nexport async function authorize_user_join(\n connection: api.IConnection,\n props: { body?: DeepPartial<IUser.IJoin> }\n): Promise<IUser.IAuthorized> {\n // ...\n}\n```\n\n### \u274C FORBIDDEN Patterns\n```typescript\n// \u274C Arrow function - COMPILATION WILL FAIL\nexport const authorize_user_join = async (...) => { ... };\n\n// \u274C Namespace wrapper - COMPILATION WILL FAIL\nexport namespace AuthorizeUserJoin {\n export async function authorize_user_join(...) { ... }\n}\n\n// \u274C Class wrapper - COMPILATION WILL FAIL\nexport class AuthorizeUserJoin {\n public static async authorize_user_join(...) { ... }\n}\n```\n\nValidation requires exact pattern: `\"export async function authorize_xxx_join(\"`\n\n## 3. JSDoc Comment Style (CRITICAL)\n\nEvery authorization function MUST have a JSDoc comment. Style: **summary sentence first, `\\n\\n`, then paragraphs grouped by topic**.\n\n---\n\n## 4. Implementation Pattern\n\n```typescript\n/**\n * Register and authenticate a new user for E2E testing.\n *\n * Creates a user account with randomized credentials, mutates the connection with the auth token. ...\n */\nexport async function authorize_user_join(\n connection: api.IConnection,\n props: { body?: DeepPartial<IUser.IJoin> },\n): Promise<IUser.IAuthorized> {\n const joinInput = {\n email: props.body?.email ?? typia.random<string & tags.Format<\"email\">>(),\n password: props.body?.password ?? RandomGenerator.alphaNumeric(16),\n nickname: props.body?.nickname ?? RandomGenerator.name(),\n citizen: {\n mobile: props.body?.citizen?.mobile ?? RandomGenerator.mobile(),\n name: props.body?.citizen?.name ?? RandomGenerator.name(),\n },\n } satisfies IUser.IJoin;\n\n return await api.functional.auth.user.join(connection, { body: joinInput });\n}\n```\n\n## 5. Critical Rules\n\n1. **No imports**: Start directly with `export async function` - all dependencies pre-imported\n2. **No try-catch**: Let errors propagate naturally\n3. **const only**: Never use `let`\n4. **Type safety**: No `any` or type assertions\n5. **Use exact SDK function**: Match the provided SDK function path\n\n## 6. Random Data Generation\n\n```typescript\n// Format-based (typia.random)\nemail: props.body?.email ?? typia.random<string & tags.Format<\"email\">>()\nip: props.body?.ip ?? typia.random<string & tags.Format<\"ip\">>()\nhref: props.body?.href ?? typia.random<string & tags.Format<\"uri\">>()\nreferrer: props.body?.referrer ?? typia.random<string & tags.Format<\"uri\">>()\n\n// RandomGenerator (name, phone, content)\nname: props.body?.name ?? RandomGenerator.name() // Full name\nnickname: props.body?.nickname ?? RandomGenerator.name(1) // Single word\nmobile: props.body?.mobile ?? RandomGenerator.mobile() // \"01012345678\"\npassword: props.body?.password ?? RandomGenerator.alphaNumeric(16)\n\n// Selection\nlanguage: props.body?.language ?? RandomGenerator.pick([\"en\", \"ko\", \"ja\"])\n```\n\n## 7. Immutability (const only)\n\n```typescript\n// \u274C WRONG\nlet result;\nresult = await api.functional.auth.join(...);\n\n// \u2705 CORRECT\nconst result = await api.functional.auth.join(...);\n\n// \u274C WRONG: Conditional with let\nlet value;\nif (condition) { value = a; } else { value = b; }\n\n// \u2705 CORRECT: Use ternary\nconst value = condition ? a : b;\n```" /* AutoBeSystemPromptConstant.TEST_AUTHORIZE_WRITE */, }, { id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), type: "assistantMessage", text: utils_1.StringUtil.trim ` ## Operation Details Method: ${props.operation.method.toUpperCase()} Path: ${props.operation.path} Authorization Type: ${props.operation.authorizationType} Actor: ${props.operation.authorizationActor} ## DTO Definitions You can use these DTO definitions: ${yield transformTestOperationWriteHistory_1.transformTestOperationWriteHistory.structures(ctx, props.artifacts)} ## API (SDK) Functions You can use these API functions: ${transformTestOperationWriteHistory_1.transformTestOperationWriteHistory.functional(props.artifacts, [])} ## External Definitions Here is the external declaration files (d.ts) you can reference. \`\`\`json ${JSON.stringify(yield (0, getTestExternalDeclarations_1.getTestExternalDeclarations)(ctx))} \`\`\` ## Template Code Here is the template code you have to implement. Reference the template code, and implement the authorization utility function. ${AutoBeTestAuthorizeProgrammer_1.AutoBeTestAuthorizeProgrammer.writeTemplate({ operation: props.operation, schema: ctx.state().interface.document.components.schemas[props.operation.requestBody.typeName], })} `, }, ], userMessage: utils_1.StringUtil.trim ` Generate an authorization utility function for ${props.operation.authorizationActor} ${props.operation.authorizationType}. The function should handle the authentication flow. `, }; }); } //# sourceMappingURL=transformTestAuthorizeWriteHistory.js.map