@123toto/ai-app-assistant-server 0.1.1 → 0.2.1

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/dist/nest.cjs CHANGED
@@ -20,33 +20,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/nest.ts
21
21
  var nest_exports = {};
22
22
  __export(nest_exports, {
23
- MANAGED_AI_DOCS_SERVER: () => MANAGED_AI_DOCS_SERVER,
24
- createManagedAiDocsNestModule: () => createManagedAiDocsNestModule,
25
- handleManagedAiDocsNestRequest: () => handleManagedAiDocsNestRequest
23
+ MANAGED_AI_APP_ASSISTANT_SERVER: () => MANAGED_AI_APP_ASSISTANT_SERVER,
24
+ createManagedAiAppAssistantNestModule: () => createManagedAiAppAssistantNestModule,
25
+ handleManagedAiAppAssistantNestRequest: () => handleManagedAiAppAssistantNestRequest
26
26
  });
27
27
  module.exports = __toCommonJS(nest_exports);
28
28
  var import_common = require("@nestjs/common");
29
- var MANAGED_AI_DOCS_SERVER = /* @__PURE__ */ Symbol.for("@123toto/ai-app-assistant-server/managed");
30
- function createManagedAiDocsNestModule(options) {
31
- const route = options.path?.replace(/^\/+|\/+$/g, "") || "ai-docs";
32
- class ManagedAiDocsNestController {
29
+ var MANAGED_AI_APP_ASSISTANT_SERVER = /* @__PURE__ */ Symbol.for("@123toto/ai-app-assistant-server/managed");
30
+ function createManagedAiAppAssistantNestModule(options) {
31
+ const route = options.path?.replace(/^\/+|\/+$/g, "") || "ai-app-assistant";
32
+ class ManagedAiAppAssistantNestController {
33
33
  constructor(server) {
34
34
  this.server = server;
35
35
  }
36
36
  server;
37
37
  handle(request, response) {
38
- return handleManagedAiDocsNestRequest(this.server, request, response);
38
+ return handleManagedAiAppAssistantNestRequest(this.server, request, response);
39
39
  }
40
40
  }
41
- (0, import_common.Inject)(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestController, void 0, 0);
42
- (0, import_common.Req)()(ManagedAiDocsNestController.prototype, "handle", 0);
43
- (0, import_common.Res)()(ManagedAiDocsNestController.prototype, "handle", 1);
44
- const descriptor = Object.getOwnPropertyDescriptor(ManagedAiDocsNestController.prototype, "handle");
45
- if (descriptor) (0, import_common.All)(["", "*path"])(ManagedAiDocsNestController.prototype, "handle", descriptor);
46
- (0, import_common.Controller)(route)(ManagedAiDocsNestController);
47
- class ManagedAiDocsNestModule {
41
+ (0, import_common.Inject)(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestController, void 0, 0);
42
+ (0, import_common.Req)()(ManagedAiAppAssistantNestController.prototype, "handle", 0);
43
+ (0, import_common.Res)()(ManagedAiAppAssistantNestController.prototype, "handle", 1);
44
+ const descriptor = Object.getOwnPropertyDescriptor(ManagedAiAppAssistantNestController.prototype, "handle");
45
+ if (descriptor) (0, import_common.All)(["", "*path"])(ManagedAiAppAssistantNestController.prototype, "handle", descriptor);
46
+ (0, import_common.Controller)(route)(ManagedAiAppAssistantNestController);
47
+ class ManagedAiAppAssistantNestModule {
48
48
  }
49
- class ManagedAiDocsNestLifecycle {
49
+ class ManagedAiAppAssistantNestLifecycle {
50
50
  constructor(server) {
51
51
  this.server = server;
52
52
  }
@@ -55,28 +55,28 @@ function createManagedAiDocsNestModule(options) {
55
55
  this.server.dispose();
56
56
  }
57
57
  }
58
- (0, import_common.Inject)(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestLifecycle, void 0, 0);
59
- (0, import_common.Injectable)()(ManagedAiDocsNestLifecycle);
58
+ (0, import_common.Inject)(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestLifecycle, void 0, 0);
59
+ (0, import_common.Injectable)()(ManagedAiAppAssistantNestLifecycle);
60
60
  const serverProvider = {
61
- provide: MANAGED_AI_DOCS_SERVER,
61
+ provide: MANAGED_AI_APP_ASSISTANT_SERVER,
62
62
  inject: options.inject ?? [],
63
63
  useFactory: options.useFactory
64
64
  };
65
65
  (0, import_common.Module)({
66
66
  imports: options.imports ?? [],
67
- controllers: [ManagedAiDocsNestController],
68
- providers: [serverProvider, ManagedAiDocsNestLifecycle],
69
- exports: [MANAGED_AI_DOCS_SERVER]
70
- })(ManagedAiDocsNestModule);
67
+ controllers: [ManagedAiAppAssistantNestController],
68
+ providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],
69
+ exports: [MANAGED_AI_APP_ASSISTANT_SERVER]
70
+ })(ManagedAiAppAssistantNestModule);
71
71
  return {
72
- module: ManagedAiDocsNestModule,
72
+ module: ManagedAiAppAssistantNestModule,
73
73
  imports: options.imports ?? [],
74
- controllers: [ManagedAiDocsNestController],
75
- providers: [serverProvider, ManagedAiDocsNestLifecycle],
76
- exports: [MANAGED_AI_DOCS_SERVER]
74
+ controllers: [ManagedAiAppAssistantNestController],
75
+ providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],
76
+ exports: [MANAGED_AI_APP_ASSISTANT_SERVER]
77
77
  };
78
78
  }
79
- async function handleManagedAiDocsNestRequest(server, request, response) {
79
+ async function handleManagedAiAppAssistantNestRequest(server, request, response) {
80
80
  const abortController = new AbortController();
81
81
  const abort = () => abortController.abort(new DOMException("Client disconnected", "AbortError"));
82
82
  request.on?.("close", abort);
@@ -134,8 +134,8 @@ async function writeFetchResponse(response, result) {
134
134
  }
135
135
  // Annotate the CommonJS export names for ESM import in node:
136
136
  0 && (module.exports = {
137
- MANAGED_AI_DOCS_SERVER,
138
- createManagedAiDocsNestModule,
139
- handleManagedAiDocsNestRequest
137
+ MANAGED_AI_APP_ASSISTANT_SERVER,
138
+ createManagedAiAppAssistantNestModule,
139
+ handleManagedAiAppAssistantNestRequest
140
140
  });
141
141
  //# sourceMappingURL=nest.cjs.map
package/dist/nest.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/nest.ts"],"sourcesContent":["import {\n All,\n Controller,\n Inject,\n Injectable,\n Module,\n Req,\n Res,\n type DynamicModule,\n type FactoryProvider,\n type ModuleMetadata,\n type Provider\n} from \"@nestjs/common\";\nimport type { ManagedAiDocsServer } from \"./managed-server.js\";\n\n/** Injection token exported so a host can update documents after Swagger bootstrap. */\nexport const MANAGED_AI_DOCS_SERVER = Symbol.for(\"@123toto/ai-app-assistant-server/managed\");\n\nexport interface AiDocsNestRequest {\n method?: string;\n originalUrl?: string;\n url?: string;\n protocol?: string;\n headers: Record<string, string | string[] | undefined>;\n body?: unknown;\n on?(event: string, listener: () => void): unknown;\n off?(event: string, listener: () => void): unknown;\n [key: string]: unknown;\n}\n\nexport interface AiDocsNestResponse {\n statusCode: number;\n setHeader(name: string, value: string): unknown;\n write(chunk: Uint8Array): boolean;\n end(chunk?: string): unknown;\n once?(event: string, listener: () => void): unknown;\n destroyed?: boolean;\n}\n\nexport interface AiDocsNestModuleOptions<\n TRequest extends AiDocsNestRequest = AiDocsNestRequest\n> extends Pick<ModuleMetadata, \"imports\"> {\n /** Nest controller path. The application's global prefix is applied normally. */\n path?: string;\n inject?: FactoryProvider[\"inject\"];\n // Nest factories intentionally accept host-defined constructor signatures.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n useFactory: (...dependencies: any[]) =>\n | AiDocsNestManagedServer<TRequest>\n | Promise<AiDocsNestManagedServer<TRequest>>;\n}\n\n/** Structural server contract avoids leaking framework-internal types across package entry points. */\nexport type AiDocsNestManagedServer<TRequest extends AiDocsNestRequest = AiDocsNestRequest> = Pick<\n ManagedAiDocsServer<{ id: string; label: string }, TRequest>,\n \"fetch\" | \"dispose\"\n>;\n\n/**\n * Creates a dynamic Nest module with one catch-all controller owned by the\n * connector. Consumer applications declare no AI Docs endpoints or DTOs.\n */\nexport function createManagedAiDocsNestModule<\n TRequest extends AiDocsNestRequest = AiDocsNestRequest\n>(options: AiDocsNestModuleOptions<TRequest>): DynamicModule {\n const route = options.path?.replace(/^\\/+|\\/+$/g, \"\") || \"ai-docs\";\n\n class ManagedAiDocsNestController {\n public constructor(\n readonly server: AiDocsNestManagedServer<TRequest>\n ) {}\n\n public handle(request: TRequest, response: AiDocsNestResponse): Promise<void> {\n return handleManagedAiDocsNestRequest(this.server, request, response);\n }\n }\n\n Inject(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestController, undefined, 0);\n Req()(ManagedAiDocsNestController.prototype, \"handle\", 0);\n Res()(ManagedAiDocsNestController.prototype, \"handle\", 1);\n const descriptor = Object.getOwnPropertyDescriptor(ManagedAiDocsNestController.prototype, \"handle\");\n if (descriptor) All([\"\", \"*path\"])(ManagedAiDocsNestController.prototype, \"handle\", descriptor);\n Controller(route)(ManagedAiDocsNestController);\n\n class ManagedAiDocsNestModule {}\n class ManagedAiDocsNestLifecycle {\n public constructor(readonly server: AiDocsNestManagedServer<TRequest>) {}\n public onApplicationShutdown(): void {\n this.server.dispose();\n }\n }\n Inject(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestLifecycle, undefined, 0);\n Injectable()(ManagedAiDocsNestLifecycle);\n const serverProvider: Provider = {\n provide: MANAGED_AI_DOCS_SERVER,\n inject: options.inject ?? [],\n useFactory: options.useFactory\n };\n Module({\n imports: options.imports ?? [],\n controllers: [ManagedAiDocsNestController],\n providers: [serverProvider, ManagedAiDocsNestLifecycle],\n exports: [MANAGED_AI_DOCS_SERVER]\n })(ManagedAiDocsNestModule);\n\n return {\n module: ManagedAiDocsNestModule,\n imports: options.imports ?? [],\n controllers: [ManagedAiDocsNestController],\n providers: [serverProvider, ManagedAiDocsNestLifecycle],\n exports: [MANAGED_AI_DOCS_SERVER]\n };\n}\n\n/** Adapts parsed Nest requests and streamed Fetch responses without Express coupling. */\nexport async function handleManagedAiDocsNestRequest<\n TRequest extends AiDocsNestRequest\n>(\n server: AiDocsNestManagedServer<TRequest>,\n request: TRequest,\n response: AiDocsNestResponse\n): Promise<void> {\n const abortController = new AbortController();\n const abort = (): void => abortController.abort(new DOMException(\"Client disconnected\", \"AbortError\"));\n request.on?.(\"close\", abort);\n try {\n const webRequest = toFetchRequest(request, abortController.signal);\n await writeFetchResponse(response, await server.fetch.handle(webRequest, request));\n } finally {\n request.off?.(\"close\", abort);\n }\n}\n\nfunction toFetchRequest(request: AiDocsNestRequest, signal: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (Array.isArray(value)) value.forEach((item) => headers.append(name, item));\n else if (value !== undefined) headers.set(name, value);\n }\n const method = request.method?.toUpperCase() || \"GET\";\n const host = headers.get(\"host\") || \"localhost\";\n const protocol = request.protocol || headers.get(\"x-forwarded-proto\") || \"http\";\n const url = new URL(request.originalUrl || request.url || \"/\", `${protocol}://${host}`);\n const hasBody = method !== \"GET\" && method !== \"HEAD\" && request.body !== undefined;\n return new Request(url, {\n method,\n headers,\n signal,\n ...(hasBody ? { body: serializeBody(request.body, headers) } : {})\n });\n}\n\nfunction serializeBody(body: unknown, headers: Headers): string {\n if (typeof body === \"string\") return body;\n if (body instanceof Uint8Array) return new TextDecoder().decode(body);\n if (!headers.has(\"content-type\")) headers.set(\"content-type\", \"application/json\");\n return JSON.stringify(body);\n}\n\nasync function writeFetchResponse(response: AiDocsNestResponse, result: Response): Promise<void> {\n response.statusCode = result.status;\n result.headers.forEach((value, name) => response.setHeader(name, value));\n if (!result.body) {\n response.end();\n return;\n }\n const reader = result.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (!response.write(value) && response.once) {\n await new Promise<void>((resolve) => response.once!(\"drain\", resolve));\n }\n }\n if (!response.destroyed) response.end();\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAIA,IAAM,yBAAyB,uBAAO,IAAI,0CAA0C;AA8CpF,SAAS,8BAEd,SAA2D;AAC3D,QAAM,QAAQ,QAAQ,MAAM,QAAQ,cAAc,EAAE,KAAK;AAAA,EAEzD,MAAM,4BAA4B;AAAA,IACzB,YACI,QACT;AADS;AAAA,IACR;AAAA,IADQ;AAA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AAG,SAAQ,IAAI,gBAAgB,kBAAkB;AAChF,SAAO,KAAK,UAAU,IAAI;AAC5B;AAEA,eAAe,mBAAmB,UAA8B,QAAiC;AAC/F,WAAS,aAAa,OAAO;AAC7B,SAAO,QAAQ,QAAQ,CAAC,OAAO,SAAS,SAAS,UAAU,MAAM,KAAK,CAAC;AACvE,MAAI,CAAC,OAAO,MAAM;AAChB,aAAS,IAAI;AACb;AAAA,EACF;AACA,QAAM,SAAS,OAAO,KAAK,UAAU;AACrC,MAAI;AACF,WAAO,MAAM;AACX,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,UAAI,CAAC,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM;AAC3C,cAAM,IAAI,QAAc,CAAC,YAAY,SAAS,KAAM,SAAS,OAAO,CAAC;AAAA,MACvE;AAAA,IACF;AACA,QAAI,CAAC,SAAS,UAAW,UAAS,IAAI;AAAA,EACxC,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/nest.ts"],"sourcesContent":["import {\n All,\n Controller,\n Inject,\n Injectable,\n Module,\n Req,\n Res,\n type DynamicModule,\n type FactoryProvider,\n type ModuleMetadata,\n type Provider\n} from \"@nestjs/common\";\nimport type { ManagedAiAppAssistantServer } from \"./managed-server.js\";\n\n/** Injection token exported so a host can update documents after Swagger bootstrap. */\nexport const MANAGED_AI_APP_ASSISTANT_SERVER = Symbol.for(\"@123toto/ai-app-assistant-server/managed\");\n\nexport interface AiAppAssistantNestRequest {\n method?: string;\n originalUrl?: string;\n url?: string;\n protocol?: string;\n headers: Record<string, string | string[] | undefined>;\n body?: unknown;\n on?(event: string, listener: () => void): unknown;\n off?(event: string, listener: () => void): unknown;\n [key: string]: unknown;\n}\n\nexport interface AiAppAssistantNestResponse {\n statusCode: number;\n setHeader(name: string, value: string): unknown;\n write(chunk: Uint8Array): boolean;\n end(chunk?: string): unknown;\n once?(event: string, listener: () => void): unknown;\n destroyed?: boolean;\n}\n\nexport interface AiAppAssistantNestModuleOptions<\n TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest\n> extends Pick<ModuleMetadata, \"imports\"> {\n /** Nest controller path. The application's global prefix is applied normally. */\n path?: string;\n inject?: FactoryProvider[\"inject\"];\n // Nest factories intentionally accept host-defined constructor signatures.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n useFactory: (...dependencies: any[]) =>\n | AiAppAssistantNestManagedServer<TRequest>\n | Promise<AiAppAssistantNestManagedServer<TRequest>>;\n}\n\n/** Structural server contract avoids leaking framework-internal types across package entry points. */\nexport type AiAppAssistantNestManagedServer<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest> = Pick<\n ManagedAiAppAssistantServer<{ id: string; label: string }, TRequest>,\n \"fetch\" | \"dispose\"\n>;\n\n/**\n * Creates a dynamic Nest module with one catch-all controller owned by the\n * connector. Consumer applications declare no AI App Assistant endpoints or DTOs.\n */\nexport function createManagedAiAppAssistantNestModule<\n TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest\n>(options: AiAppAssistantNestModuleOptions<TRequest>): DynamicModule {\n const route = options.path?.replace(/^\\/+|\\/+$/g, \"\") || \"ai-app-assistant\";\n\n class ManagedAiAppAssistantNestController {\n public constructor(\n readonly server: AiAppAssistantNestManagedServer<TRequest>\n ) {}\n\n public handle(request: TRequest, response: AiAppAssistantNestResponse): Promise<void> {\n return handleManagedAiAppAssistantNestRequest(this.server, request, response);\n }\n }\n\n Inject(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestController, undefined, 0);\n Req()(ManagedAiAppAssistantNestController.prototype, \"handle\", 0);\n Res()(ManagedAiAppAssistantNestController.prototype, \"handle\", 1);\n const descriptor = Object.getOwnPropertyDescriptor(ManagedAiAppAssistantNestController.prototype, \"handle\");\n if (descriptor) All([\"\", \"*path\"])(ManagedAiAppAssistantNestController.prototype, \"handle\", descriptor);\n Controller(route)(ManagedAiAppAssistantNestController);\n\n class ManagedAiAppAssistantNestModule {}\n class ManagedAiAppAssistantNestLifecycle {\n public constructor(readonly server: AiAppAssistantNestManagedServer<TRequest>) {}\n public onApplicationShutdown(): void {\n this.server.dispose();\n }\n }\n Inject(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestLifecycle, undefined, 0);\n Injectable()(ManagedAiAppAssistantNestLifecycle);\n const serverProvider: Provider = {\n provide: MANAGED_AI_APP_ASSISTANT_SERVER,\n inject: options.inject ?? [],\n useFactory: options.useFactory\n };\n Module({\n imports: options.imports ?? [],\n controllers: [ManagedAiAppAssistantNestController],\n providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],\n exports: [MANAGED_AI_APP_ASSISTANT_SERVER]\n })(ManagedAiAppAssistantNestModule);\n\n return {\n module: ManagedAiAppAssistantNestModule,\n imports: options.imports ?? [],\n controllers: [ManagedAiAppAssistantNestController],\n providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],\n exports: [MANAGED_AI_APP_ASSISTANT_SERVER]\n };\n}\n\n/** Adapts parsed Nest requests and streamed Fetch responses without Express coupling. */\nexport async function handleManagedAiAppAssistantNestRequest<\n TRequest extends AiAppAssistantNestRequest\n>(\n server: AiAppAssistantNestManagedServer<TRequest>,\n request: TRequest,\n response: AiAppAssistantNestResponse\n): Promise<void> {\n const abortController = new AbortController();\n const abort = (): void => abortController.abort(new DOMException(\"Client disconnected\", \"AbortError\"));\n request.on?.(\"close\", abort);\n try {\n const webRequest = toFetchRequest(request, abortController.signal);\n await writeFetchResponse(response, await server.fetch.handle(webRequest, request));\n } finally {\n request.off?.(\"close\", abort);\n }\n}\n\nfunction toFetchRequest(request: AiAppAssistantNestRequest, signal: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (Array.isArray(value)) value.forEach((item) => headers.append(name, item));\n else if (value !== undefined) headers.set(name, value);\n }\n const method = request.method?.toUpperCase() || \"GET\";\n const host = headers.get(\"host\") || \"localhost\";\n const protocol = request.protocol || headers.get(\"x-forwarded-proto\") || \"http\";\n const url = new URL(request.originalUrl || request.url || \"/\", `${protocol}://${host}`);\n const hasBody = method !== \"GET\" && method !== \"HEAD\" && request.body !== undefined;\n return new Request(url, {\n method,\n headers,\n signal,\n ...(hasBody ? { body: serializeBody(request.body, headers) } : {})\n });\n}\n\nfunction serializeBody(body: unknown, headers: Headers): string {\n if (typeof body === \"string\") return body;\n if (body instanceof Uint8Array) return new TextDecoder().decode(body);\n if (!headers.has(\"content-type\")) headers.set(\"content-type\", \"application/json\");\n return JSON.stringify(body);\n}\n\nasync function writeFetchResponse(response: AiAppAssistantNestResponse, result: Response): Promise<void> {\n response.statusCode = result.status;\n result.headers.forEach((value, name) => response.setHeader(name, value));\n if (!result.body) {\n response.end();\n return;\n }\n const reader = result.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (!response.write(value) && response.once) {\n await new Promise<void>((resolve) => response.once!(\"drain\", resolve));\n }\n }\n if (!response.destroyed) response.end();\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAIA,IAAM,kCAAkC,uBAAO,IAAI,0CAA0C;AA8C7F,SAAS,sCAEd,SAAmE;AACnE,QAAM,QAAQ,QAAQ,MAAM,QAAQ,cAAc,EAAE,KAAK;AAAA,EAEzD,MAAM,oCAAoC;AAAA,IACjC,YACI,QACT;AADS;AAAA,IACR;AAAA,IADQ;AAAA,IAGJ,OAAO,SAAmB,UAAqD;AACpF,aAAO,uCAAuC,KAAK,QAAQ,SAAS,QAAQ;AAAA,IAC9E;AAAA,EACF;AAEA,4BAAO,+BAA+B,EAAE,qCAAqC,QAAW,CAAC;AACzF,yBAAI,EAAE,oCAAoC,WAAW,UAAU,CAAC;AAChE,yBAAI,EAAE,oCAAoC,WAAW,UAAU,CAAC;AAChE,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AS,IAAI;AACb;AAAA,EACF;AACA,QAAM,SAAS,OAAO,KAAK,UAAU;AACrC,MAAI;AACF,WAAO,MAAM;AACX,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,UAAI,CAAC,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM;AAC3C,cAAM,IAAI,QAAc,CAAC,YAAY,SAAS,KAAM,SAAS,OAAO,CAAC;AAAA,MACvE;AAAA,IACF;AACA,QAAI,CAAC,SAAS,UAAW,UAAS,IAAI;AAAA,EACxC,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACF;","names":[]}
package/dist/nest.d.cts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ModuleMetadata, FactoryProvider, DynamicModule } from '@nestjs/common';
2
- import { M as ManagedAiDocsServer } from './managed-server-7iurKxF1.cjs';
3
- import './ai-sdk-QImICd56.cjs';
2
+ import { M as ManagedAiAppAssistantServer } from './managed-server-CQb-RK-i.cjs';
3
+ import './ai-sdk-qU3KgNu-.cjs';
4
4
  import 'ai';
5
5
  import '@123toto/ai-app-assistant-contracts';
6
6
 
7
7
  /** Injection token exported so a host can update documents after Swagger bootstrap. */
8
- declare const MANAGED_AI_DOCS_SERVER: unique symbol;
9
- interface AiDocsNestRequest {
8
+ declare const MANAGED_AI_APP_ASSISTANT_SERVER: unique symbol;
9
+ interface AiAppAssistantNestRequest {
10
10
  method?: string;
11
11
  originalUrl?: string;
12
12
  url?: string;
@@ -17,7 +17,7 @@ interface AiDocsNestRequest {
17
17
  off?(event: string, listener: () => void): unknown;
18
18
  [key: string]: unknown;
19
19
  }
20
- interface AiDocsNestResponse {
20
+ interface AiAppAssistantNestResponse {
21
21
  statusCode: number;
22
22
  setHeader(name: string, value: string): unknown;
23
23
  write(chunk: Uint8Array): boolean;
@@ -25,23 +25,23 @@ interface AiDocsNestResponse {
25
25
  once?(event: string, listener: () => void): unknown;
26
26
  destroyed?: boolean;
27
27
  }
28
- interface AiDocsNestModuleOptions<TRequest extends AiDocsNestRequest = AiDocsNestRequest> extends Pick<ModuleMetadata, "imports"> {
28
+ interface AiAppAssistantNestModuleOptions<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest> extends Pick<ModuleMetadata, "imports"> {
29
29
  /** Nest controller path. The application's global prefix is applied normally. */
30
30
  path?: string;
31
31
  inject?: FactoryProvider["inject"];
32
- useFactory: (...dependencies: any[]) => AiDocsNestManagedServer<TRequest> | Promise<AiDocsNestManagedServer<TRequest>>;
32
+ useFactory: (...dependencies: any[]) => AiAppAssistantNestManagedServer<TRequest> | Promise<AiAppAssistantNestManagedServer<TRequest>>;
33
33
  }
34
34
  /** Structural server contract avoids leaking framework-internal types across package entry points. */
35
- type AiDocsNestManagedServer<TRequest extends AiDocsNestRequest = AiDocsNestRequest> = Pick<ManagedAiDocsServer<{
35
+ type AiAppAssistantNestManagedServer<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest> = Pick<ManagedAiAppAssistantServer<{
36
36
  id: string;
37
37
  label: string;
38
38
  }, TRequest>, "fetch" | "dispose">;
39
39
  /**
40
40
  * Creates a dynamic Nest module with one catch-all controller owned by the
41
- * connector. Consumer applications declare no AI Docs endpoints or DTOs.
41
+ * connector. Consumer applications declare no AI App Assistant endpoints or DTOs.
42
42
  */
43
- declare function createManagedAiDocsNestModule<TRequest extends AiDocsNestRequest = AiDocsNestRequest>(options: AiDocsNestModuleOptions<TRequest>): DynamicModule;
43
+ declare function createManagedAiAppAssistantNestModule<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest>(options: AiAppAssistantNestModuleOptions<TRequest>): DynamicModule;
44
44
  /** Adapts parsed Nest requests and streamed Fetch responses without Express coupling. */
45
- declare function handleManagedAiDocsNestRequest<TRequest extends AiDocsNestRequest>(server: AiDocsNestManagedServer<TRequest>, request: TRequest, response: AiDocsNestResponse): Promise<void>;
45
+ declare function handleManagedAiAppAssistantNestRequest<TRequest extends AiAppAssistantNestRequest>(server: AiAppAssistantNestManagedServer<TRequest>, request: TRequest, response: AiAppAssistantNestResponse): Promise<void>;
46
46
 
47
- export { type AiDocsNestManagedServer, type AiDocsNestModuleOptions, type AiDocsNestRequest, type AiDocsNestResponse, MANAGED_AI_DOCS_SERVER, createManagedAiDocsNestModule, handleManagedAiDocsNestRequest };
47
+ export { type AiAppAssistantNestManagedServer, type AiAppAssistantNestModuleOptions, type AiAppAssistantNestRequest, type AiAppAssistantNestResponse, MANAGED_AI_APP_ASSISTANT_SERVER, createManagedAiAppAssistantNestModule, handleManagedAiAppAssistantNestRequest };
package/dist/nest.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ModuleMetadata, FactoryProvider, DynamicModule } from '@nestjs/common';
2
- import { M as ManagedAiDocsServer } from './managed-server-CrZumvVU.js';
3
- import './ai-sdk-QImICd56.js';
2
+ import { M as ManagedAiAppAssistantServer } from './managed-server-CGmvVYsF.js';
3
+ import './ai-sdk-qU3KgNu-.js';
4
4
  import 'ai';
5
5
  import '@123toto/ai-app-assistant-contracts';
6
6
 
7
7
  /** Injection token exported so a host can update documents after Swagger bootstrap. */
8
- declare const MANAGED_AI_DOCS_SERVER: unique symbol;
9
- interface AiDocsNestRequest {
8
+ declare const MANAGED_AI_APP_ASSISTANT_SERVER: unique symbol;
9
+ interface AiAppAssistantNestRequest {
10
10
  method?: string;
11
11
  originalUrl?: string;
12
12
  url?: string;
@@ -17,7 +17,7 @@ interface AiDocsNestRequest {
17
17
  off?(event: string, listener: () => void): unknown;
18
18
  [key: string]: unknown;
19
19
  }
20
- interface AiDocsNestResponse {
20
+ interface AiAppAssistantNestResponse {
21
21
  statusCode: number;
22
22
  setHeader(name: string, value: string): unknown;
23
23
  write(chunk: Uint8Array): boolean;
@@ -25,23 +25,23 @@ interface AiDocsNestResponse {
25
25
  once?(event: string, listener: () => void): unknown;
26
26
  destroyed?: boolean;
27
27
  }
28
- interface AiDocsNestModuleOptions<TRequest extends AiDocsNestRequest = AiDocsNestRequest> extends Pick<ModuleMetadata, "imports"> {
28
+ interface AiAppAssistantNestModuleOptions<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest> extends Pick<ModuleMetadata, "imports"> {
29
29
  /** Nest controller path. The application's global prefix is applied normally. */
30
30
  path?: string;
31
31
  inject?: FactoryProvider["inject"];
32
- useFactory: (...dependencies: any[]) => AiDocsNestManagedServer<TRequest> | Promise<AiDocsNestManagedServer<TRequest>>;
32
+ useFactory: (...dependencies: any[]) => AiAppAssistantNestManagedServer<TRequest> | Promise<AiAppAssistantNestManagedServer<TRequest>>;
33
33
  }
34
34
  /** Structural server contract avoids leaking framework-internal types across package entry points. */
35
- type AiDocsNestManagedServer<TRequest extends AiDocsNestRequest = AiDocsNestRequest> = Pick<ManagedAiDocsServer<{
35
+ type AiAppAssistantNestManagedServer<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest> = Pick<ManagedAiAppAssistantServer<{
36
36
  id: string;
37
37
  label: string;
38
38
  }, TRequest>, "fetch" | "dispose">;
39
39
  /**
40
40
  * Creates a dynamic Nest module with one catch-all controller owned by the
41
- * connector. Consumer applications declare no AI Docs endpoints or DTOs.
41
+ * connector. Consumer applications declare no AI App Assistant endpoints or DTOs.
42
42
  */
43
- declare function createManagedAiDocsNestModule<TRequest extends AiDocsNestRequest = AiDocsNestRequest>(options: AiDocsNestModuleOptions<TRequest>): DynamicModule;
43
+ declare function createManagedAiAppAssistantNestModule<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest>(options: AiAppAssistantNestModuleOptions<TRequest>): DynamicModule;
44
44
  /** Adapts parsed Nest requests and streamed Fetch responses without Express coupling. */
45
- declare function handleManagedAiDocsNestRequest<TRequest extends AiDocsNestRequest>(server: AiDocsNestManagedServer<TRequest>, request: TRequest, response: AiDocsNestResponse): Promise<void>;
45
+ declare function handleManagedAiAppAssistantNestRequest<TRequest extends AiAppAssistantNestRequest>(server: AiAppAssistantNestManagedServer<TRequest>, request: TRequest, response: AiAppAssistantNestResponse): Promise<void>;
46
46
 
47
- export { type AiDocsNestManagedServer, type AiDocsNestModuleOptions, type AiDocsNestRequest, type AiDocsNestResponse, MANAGED_AI_DOCS_SERVER, createManagedAiDocsNestModule, handleManagedAiDocsNestRequest };
47
+ export { type AiAppAssistantNestManagedServer, type AiAppAssistantNestModuleOptions, type AiAppAssistantNestRequest, type AiAppAssistantNestResponse, MANAGED_AI_APP_ASSISTANT_SERVER, createManagedAiAppAssistantNestModule, handleManagedAiAppAssistantNestRequest };
package/dist/nest.js CHANGED
@@ -8,27 +8,27 @@ import {
8
8
  Req,
9
9
  Res
10
10
  } from "@nestjs/common";
11
- var MANAGED_AI_DOCS_SERVER = /* @__PURE__ */ Symbol.for("@123toto/ai-app-assistant-server/managed");
12
- function createManagedAiDocsNestModule(options) {
13
- const route = options.path?.replace(/^\/+|\/+$/g, "") || "ai-docs";
14
- class ManagedAiDocsNestController {
11
+ var MANAGED_AI_APP_ASSISTANT_SERVER = /* @__PURE__ */ Symbol.for("@123toto/ai-app-assistant-server/managed");
12
+ function createManagedAiAppAssistantNestModule(options) {
13
+ const route = options.path?.replace(/^\/+|\/+$/g, "") || "ai-app-assistant";
14
+ class ManagedAiAppAssistantNestController {
15
15
  constructor(server) {
16
16
  this.server = server;
17
17
  }
18
18
  server;
19
19
  handle(request, response) {
20
- return handleManagedAiDocsNestRequest(this.server, request, response);
20
+ return handleManagedAiAppAssistantNestRequest(this.server, request, response);
21
21
  }
22
22
  }
23
- Inject(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestController, void 0, 0);
24
- Req()(ManagedAiDocsNestController.prototype, "handle", 0);
25
- Res()(ManagedAiDocsNestController.prototype, "handle", 1);
26
- const descriptor = Object.getOwnPropertyDescriptor(ManagedAiDocsNestController.prototype, "handle");
27
- if (descriptor) All(["", "*path"])(ManagedAiDocsNestController.prototype, "handle", descriptor);
28
- Controller(route)(ManagedAiDocsNestController);
29
- class ManagedAiDocsNestModule {
23
+ Inject(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestController, void 0, 0);
24
+ Req()(ManagedAiAppAssistantNestController.prototype, "handle", 0);
25
+ Res()(ManagedAiAppAssistantNestController.prototype, "handle", 1);
26
+ const descriptor = Object.getOwnPropertyDescriptor(ManagedAiAppAssistantNestController.prototype, "handle");
27
+ if (descriptor) All(["", "*path"])(ManagedAiAppAssistantNestController.prototype, "handle", descriptor);
28
+ Controller(route)(ManagedAiAppAssistantNestController);
29
+ class ManagedAiAppAssistantNestModule {
30
30
  }
31
- class ManagedAiDocsNestLifecycle {
31
+ class ManagedAiAppAssistantNestLifecycle {
32
32
  constructor(server) {
33
33
  this.server = server;
34
34
  }
@@ -37,28 +37,28 @@ function createManagedAiDocsNestModule(options) {
37
37
  this.server.dispose();
38
38
  }
39
39
  }
40
- Inject(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestLifecycle, void 0, 0);
41
- Injectable()(ManagedAiDocsNestLifecycle);
40
+ Inject(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestLifecycle, void 0, 0);
41
+ Injectable()(ManagedAiAppAssistantNestLifecycle);
42
42
  const serverProvider = {
43
- provide: MANAGED_AI_DOCS_SERVER,
43
+ provide: MANAGED_AI_APP_ASSISTANT_SERVER,
44
44
  inject: options.inject ?? [],
45
45
  useFactory: options.useFactory
46
46
  };
47
47
  Module({
48
48
  imports: options.imports ?? [],
49
- controllers: [ManagedAiDocsNestController],
50
- providers: [serverProvider, ManagedAiDocsNestLifecycle],
51
- exports: [MANAGED_AI_DOCS_SERVER]
52
- })(ManagedAiDocsNestModule);
49
+ controllers: [ManagedAiAppAssistantNestController],
50
+ providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],
51
+ exports: [MANAGED_AI_APP_ASSISTANT_SERVER]
52
+ })(ManagedAiAppAssistantNestModule);
53
53
  return {
54
- module: ManagedAiDocsNestModule,
54
+ module: ManagedAiAppAssistantNestModule,
55
55
  imports: options.imports ?? [],
56
- controllers: [ManagedAiDocsNestController],
57
- providers: [serverProvider, ManagedAiDocsNestLifecycle],
58
- exports: [MANAGED_AI_DOCS_SERVER]
56
+ controllers: [ManagedAiAppAssistantNestController],
57
+ providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],
58
+ exports: [MANAGED_AI_APP_ASSISTANT_SERVER]
59
59
  };
60
60
  }
61
- async function handleManagedAiDocsNestRequest(server, request, response) {
61
+ async function handleManagedAiAppAssistantNestRequest(server, request, response) {
62
62
  const abortController = new AbortController();
63
63
  const abort = () => abortController.abort(new DOMException("Client disconnected", "AbortError"));
64
64
  request.on?.("close", abort);
@@ -115,8 +115,8 @@ async function writeFetchResponse(response, result) {
115
115
  }
116
116
  }
117
117
  export {
118
- MANAGED_AI_DOCS_SERVER,
119
- createManagedAiDocsNestModule,
120
- handleManagedAiDocsNestRequest
118
+ MANAGED_AI_APP_ASSISTANT_SERVER,
119
+ createManagedAiAppAssistantNestModule,
120
+ handleManagedAiAppAssistantNestRequest
121
121
  };
122
122
  //# sourceMappingURL=nest.js.map
package/dist/nest.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/nest.ts"],"sourcesContent":["import {\n All,\n Controller,\n Inject,\n Injectable,\n Module,\n Req,\n Res,\n type DynamicModule,\n type FactoryProvider,\n type ModuleMetadata,\n type Provider\n} from \"@nestjs/common\";\nimport type { ManagedAiDocsServer } from \"./managed-server.js\";\n\n/** Injection token exported so a host can update documents after Swagger bootstrap. */\nexport const MANAGED_AI_DOCS_SERVER = Symbol.for(\"@123toto/ai-app-assistant-server/managed\");\n\nexport interface AiDocsNestRequest {\n method?: string;\n originalUrl?: string;\n url?: string;\n protocol?: string;\n headers: Record<string, string | string[] | undefined>;\n body?: unknown;\n on?(event: string, listener: () => void): unknown;\n off?(event: string, listener: () => void): unknown;\n [key: string]: unknown;\n}\n\nexport interface AiDocsNestResponse {\n statusCode: number;\n setHeader(name: string, value: string): unknown;\n write(chunk: Uint8Array): boolean;\n end(chunk?: string): unknown;\n once?(event: string, listener: () => void): unknown;\n destroyed?: boolean;\n}\n\nexport interface AiDocsNestModuleOptions<\n TRequest extends AiDocsNestRequest = AiDocsNestRequest\n> extends Pick<ModuleMetadata, \"imports\"> {\n /** Nest controller path. The application's global prefix is applied normally. */\n path?: string;\n inject?: FactoryProvider[\"inject\"];\n // Nest factories intentionally accept host-defined constructor signatures.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n useFactory: (...dependencies: any[]) =>\n | AiDocsNestManagedServer<TRequest>\n | Promise<AiDocsNestManagedServer<TRequest>>;\n}\n\n/** Structural server contract avoids leaking framework-internal types across package entry points. */\nexport type AiDocsNestManagedServer<TRequest extends AiDocsNestRequest = AiDocsNestRequest> = Pick<\n ManagedAiDocsServer<{ id: string; label: string }, TRequest>,\n \"fetch\" | \"dispose\"\n>;\n\n/**\n * Creates a dynamic Nest module with one catch-all controller owned by the\n * connector. Consumer applications declare no AI Docs endpoints or DTOs.\n */\nexport function createManagedAiDocsNestModule<\n TRequest extends AiDocsNestRequest = AiDocsNestRequest\n>(options: AiDocsNestModuleOptions<TRequest>): DynamicModule {\n const route = options.path?.replace(/^\\/+|\\/+$/g, \"\") || \"ai-docs\";\n\n class ManagedAiDocsNestController {\n public constructor(\n readonly server: AiDocsNestManagedServer<TRequest>\n ) {}\n\n public handle(request: TRequest, response: AiDocsNestResponse): Promise<void> {\n return handleManagedAiDocsNestRequest(this.server, request, response);\n }\n }\n\n Inject(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestController, undefined, 0);\n Req()(ManagedAiDocsNestController.prototype, \"handle\", 0);\n Res()(ManagedAiDocsNestController.prototype, \"handle\", 1);\n const descriptor = Object.getOwnPropertyDescriptor(ManagedAiDocsNestController.prototype, \"handle\");\n if (descriptor) All([\"\", \"*path\"])(ManagedAiDocsNestController.prototype, \"handle\", descriptor);\n Controller(route)(ManagedAiDocsNestController);\n\n class ManagedAiDocsNestModule {}\n class ManagedAiDocsNestLifecycle {\n public constructor(readonly server: AiDocsNestManagedServer<TRequest>) {}\n public onApplicationShutdown(): void {\n this.server.dispose();\n }\n }\n Inject(MANAGED_AI_DOCS_SERVER)(ManagedAiDocsNestLifecycle, undefined, 0);\n Injectable()(ManagedAiDocsNestLifecycle);\n const serverProvider: Provider = {\n provide: MANAGED_AI_DOCS_SERVER,\n inject: options.inject ?? [],\n useFactory: options.useFactory\n };\n Module({\n imports: options.imports ?? [],\n controllers: [ManagedAiDocsNestController],\n providers: [serverProvider, ManagedAiDocsNestLifecycle],\n exports: [MANAGED_AI_DOCS_SERVER]\n })(ManagedAiDocsNestModule);\n\n return {\n module: ManagedAiDocsNestModule,\n imports: options.imports ?? [],\n controllers: [ManagedAiDocsNestController],\n providers: [serverProvider, ManagedAiDocsNestLifecycle],\n exports: [MANAGED_AI_DOCS_SERVER]\n };\n}\n\n/** Adapts parsed Nest requests and streamed Fetch responses without Express coupling. */\nexport async function handleManagedAiDocsNestRequest<\n TRequest extends AiDocsNestRequest\n>(\n server: AiDocsNestManagedServer<TRequest>,\n request: TRequest,\n response: AiDocsNestResponse\n): Promise<void> {\n const abortController = new AbortController();\n const abort = (): void => abortController.abort(new DOMException(\"Client disconnected\", \"AbortError\"));\n request.on?.(\"close\", abort);\n try {\n const webRequest = toFetchRequest(request, abortController.signal);\n await writeFetchResponse(response, await server.fetch.handle(webRequest, request));\n } finally {\n request.off?.(\"close\", abort);\n }\n}\n\nfunction toFetchRequest(request: AiDocsNestRequest, signal: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (Array.isArray(value)) value.forEach((item) => headers.append(name, item));\n else if (value !== undefined) headers.set(name, value);\n }\n const method = request.method?.toUpperCase() || \"GET\";\n const host = headers.get(\"host\") || \"localhost\";\n const protocol = request.protocol || headers.get(\"x-forwarded-proto\") || \"http\";\n const url = new URL(request.originalUrl || request.url || \"/\", `${protocol}://${host}`);\n const hasBody = method !== \"GET\" && method !== \"HEAD\" && request.body !== undefined;\n return new Request(url, {\n method,\n headers,\n signal,\n ...(hasBody ? { body: serializeBody(request.body, headers) } : {})\n });\n}\n\nfunction serializeBody(body: unknown, headers: Headers): string {\n if (typeof body === \"string\") return body;\n if (body instanceof Uint8Array) return new TextDecoder().decode(body);\n if (!headers.has(\"content-type\")) headers.set(\"content-type\", \"application/json\");\n return JSON.stringify(body);\n}\n\nasync function writeFetchResponse(response: AiDocsNestResponse, result: Response): Promise<void> {\n response.statusCode = result.status;\n result.headers.forEach((value, name) => response.setHeader(name, value));\n if (!result.body) {\n response.end();\n return;\n }\n const reader = result.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (!response.write(value) && response.once) {\n await new Promise<void>((resolve) => response.once!(\"drain\", resolve));\n }\n }\n if (!response.destroyed) response.end();\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAIA,IAAM,yBAAyB,uBAAO,IAAI,0CAA0C;AA8CpF,SAAS,8BAEd,SAA2D;AAC3D,QAAM,QAAQ,QAAQ,MAAM,QAAQ,cAAc,EAAE,KAAK;AAAA,EAEzD,MAAM,4BAA4B;AAAA,IACzB,YACI,QACT;AADS;AAAA,IACR;AAAA,IADQ;AAAA,IAGJ,OAAO,SAAmB,UAA6C;AAC5E,aAAO,+BAA+B,KAAK,QAAQ,SAAS,QAAQ;AAAA,IACtE;AAAA,EACF;AAEA,SAAO,sBAAsB,EAAE,6BAA6B,QAAW,CAAC;AACxE,MAAI,EAAE,4BAA4B,WAAW,UAAU,CAAC;AACxD,MAAI,EAAE,4BAA4B,WAAW,UAAU,CAAC;AACxD,QAAM,aAAa,OAAO,yBAAyB,4BAA4B,WAAW,QAAQ;AAClG,MAAI,WAAY,KAAI,CAAC,IAAI,OAAO,CAAC,EAAE,4BAA4B,WAAW,UAAU,UAAU;AAC9F,aAAW,KAAK,EAAE,2BAA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,UAAI,CAAC,SAAS,MAAM,KAAK,KAAK,SAAS,MAAM;AAC3C,cAAM,IAAI,QAAc,CAAC,YAAY,SAAS,KAAM,SAAS,OAAO,CAAC;AAAA,MACvE;AAAA,IACF;AACA,QAAI,CAAC,SAAS,UAAW,UAAS,IAAI;AAAA,EACxC,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/nest.ts"],"sourcesContent":["import {\n All,\n Controller,\n Inject,\n Injectable,\n Module,\n Req,\n Res,\n type DynamicModule,\n type FactoryProvider,\n type ModuleMetadata,\n type Provider\n} from \"@nestjs/common\";\nimport type { ManagedAiAppAssistantServer } from \"./managed-server.js\";\n\n/** Injection token exported so a host can update documents after Swagger bootstrap. */\nexport const MANAGED_AI_APP_ASSISTANT_SERVER = Symbol.for(\"@123toto/ai-app-assistant-server/managed\");\n\nexport interface AiAppAssistantNestRequest {\n method?: string;\n originalUrl?: string;\n url?: string;\n protocol?: string;\n headers: Record<string, string | string[] | undefined>;\n body?: unknown;\n on?(event: string, listener: () => void): unknown;\n off?(event: string, listener: () => void): unknown;\n [key: string]: unknown;\n}\n\nexport interface AiAppAssistantNestResponse {\n statusCode: number;\n setHeader(name: string, value: string): unknown;\n write(chunk: Uint8Array): boolean;\n end(chunk?: string): unknown;\n once?(event: string, listener: () => void): unknown;\n destroyed?: boolean;\n}\n\nexport interface AiAppAssistantNestModuleOptions<\n TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest\n> extends Pick<ModuleMetadata, \"imports\"> {\n /** Nest controller path. The application's global prefix is applied normally. */\n path?: string;\n inject?: FactoryProvider[\"inject\"];\n // Nest factories intentionally accept host-defined constructor signatures.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n useFactory: (...dependencies: any[]) =>\n | AiAppAssistantNestManagedServer<TRequest>\n | Promise<AiAppAssistantNestManagedServer<TRequest>>;\n}\n\n/** Structural server contract avoids leaking framework-internal types across package entry points. */\nexport type AiAppAssistantNestManagedServer<TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest> = Pick<\n ManagedAiAppAssistantServer<{ id: string; label: string }, TRequest>,\n \"fetch\" | \"dispose\"\n>;\n\n/**\n * Creates a dynamic Nest module with one catch-all controller owned by the\n * connector. Consumer applications declare no AI App Assistant endpoints or DTOs.\n */\nexport function createManagedAiAppAssistantNestModule<\n TRequest extends AiAppAssistantNestRequest = AiAppAssistantNestRequest\n>(options: AiAppAssistantNestModuleOptions<TRequest>): DynamicModule {\n const route = options.path?.replace(/^\\/+|\\/+$/g, \"\") || \"ai-app-assistant\";\n\n class ManagedAiAppAssistantNestController {\n public constructor(\n readonly server: AiAppAssistantNestManagedServer<TRequest>\n ) {}\n\n public handle(request: TRequest, response: AiAppAssistantNestResponse): Promise<void> {\n return handleManagedAiAppAssistantNestRequest(this.server, request, response);\n }\n }\n\n Inject(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestController, undefined, 0);\n Req()(ManagedAiAppAssistantNestController.prototype, \"handle\", 0);\n Res()(ManagedAiAppAssistantNestController.prototype, \"handle\", 1);\n const descriptor = Object.getOwnPropertyDescriptor(ManagedAiAppAssistantNestController.prototype, \"handle\");\n if (descriptor) All([\"\", \"*path\"])(ManagedAiAppAssistantNestController.prototype, \"handle\", descriptor);\n Controller(route)(ManagedAiAppAssistantNestController);\n\n class ManagedAiAppAssistantNestModule {}\n class ManagedAiAppAssistantNestLifecycle {\n public constructor(readonly server: AiAppAssistantNestManagedServer<TRequest>) {}\n public onApplicationShutdown(): void {\n this.server.dispose();\n }\n }\n Inject(MANAGED_AI_APP_ASSISTANT_SERVER)(ManagedAiAppAssistantNestLifecycle, undefined, 0);\n Injectable()(ManagedAiAppAssistantNestLifecycle);\n const serverProvider: Provider = {\n provide: MANAGED_AI_APP_ASSISTANT_SERVER,\n inject: options.inject ?? [],\n useFactory: options.useFactory\n };\n Module({\n imports: options.imports ?? [],\n controllers: [ManagedAiAppAssistantNestController],\n providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],\n exports: [MANAGED_AI_APP_ASSISTANT_SERVER]\n })(ManagedAiAppAssistantNestModule);\n\n return {\n module: ManagedAiAppAssistantNestModule,\n imports: options.imports ?? [],\n controllers: [ManagedAiAppAssistantNestController],\n providers: [serverProvider, ManagedAiAppAssistantNestLifecycle],\n exports: [MANAGED_AI_APP_ASSISTANT_SERVER]\n };\n}\n\n/** Adapts parsed Nest requests and streamed Fetch responses without Express coupling. */\nexport async function handleManagedAiAppAssistantNestRequest<\n TRequest extends AiAppAssistantNestRequest\n>(\n server: AiAppAssistantNestManagedServer<TRequest>,\n request: TRequest,\n response: AiAppAssistantNestResponse\n): Promise<void> {\n const abortController = new AbortController();\n const abort = (): void => abortController.abort(new DOMException(\"Client disconnected\", \"AbortError\"));\n request.on?.(\"close\", abort);\n try {\n const webRequest = toFetchRequest(request, abortController.signal);\n await writeFetchResponse(response, await server.fetch.handle(webRequest, request));\n } finally {\n request.off?.(\"close\", abort);\n }\n}\n\nfunction toFetchRequest(request: AiAppAssistantNestRequest, signal: AbortSignal): Request {\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (Array.isArray(value)) value.forEach((item) => headers.append(name, item));\n else if (value !== undefined) headers.set(name, value);\n }\n const method = request.method?.toUpperCase() || \"GET\";\n const host = headers.get(\"host\") || \"localhost\";\n const protocol = request.protocol || headers.get(\"x-forwarded-proto\") || \"http\";\n const url = new URL(request.originalUrl || request.url || \"/\", `${protocol}://${host}`);\n const hasBody = method !== \"GET\" && method !== \"HEAD\" && request.body !== undefined;\n return new Request(url, {\n method,\n headers,\n signal,\n ...(hasBody ? { body: serializeBody(request.body, headers) } : {})\n });\n}\n\nfunction serializeBody(body: unknown, headers: Headers): string {\n if (typeof body === \"string\") return body;\n if (body instanceof Uint8Array) return new TextDecoder().decode(body);\n if (!headers.has(\"content-type\")) headers.set(\"content-type\", \"application/json\");\n return JSON.stringify(body);\n}\n\nasync function writeFetchResponse(response: AiAppAssistantNestResponse, result: Response): Promise<void> {\n response.statusCode = result.status;\n result.headers.forEach((value, name) => response.setHeader(name, value));\n if (!result.body) {\n response.end();\n return;\n }\n const reader = result.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (!response.write(value) && response.once) {\n await new Promise<void>((resolve) => response.once!(\"drain\", resolve));\n }\n }\n if (!response.destroyed) response.end();\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAIA,IAAM,kCAAkC,uBAAO,IAAI,0CAA0C;AA8C7F,SAAS,sCAEd,SAAmE;AACnE,QAAM,QAAQ,QAAQ,MAAM,QAAQ,cAAc,EAAE,KAAK;AAAA,EAEzD,MAAM,oCAAoC;AAAA,IACjC,YACI,QACT;AADS;AAAA,IACR;AAAA,IADQ;AAAA,IAGJ,OAAO,SAAmB,UAAqD;AACpF,aAAO,uCAAuC,KAAK,QAAQ,SAAS,QAAQ;AAAA,IAC9E;AAAA,EACF;AAEA,SAAO,+BAA+B,EAAE,qCAAqC,QAAW,CAAC;AACzF,MAAI,EAAE,oCAAoC,WAAW,UAAU,CAAC;AAChE,MAAI,EAAE,oCAAoC,WAAW,UAAU,CAAC;AAChE,QAAM,aAAa,OAAO,yBAAyB,oCAAoC,WAAW,QAAQ;AAC1G,MAAI,WAAY,KAAI,CAAC,IAAI,OAAO,CAAC,EAAE,oCAAoC,WAAW,UAAU,UAAU;AACtG,aAAW,KAAK,EAAE,mCAAmC;AAAA,EAErD,MAAM,gCAAgC;AAAA,EAAC;AAAA,EACvC,MAAM,mCAAmC;AAAA,IAChC,YAAqB,QAAmD;AAAnD;AAAA,IAAoD;AAAA,IAApD;AAAA,IACrB,wBAA8B;AACnC,WAAK,OAAO,QAAQ;AAAA,IACtB;AAAA,EACF;AACA,SAAO,+BAA+B,EAAE,oCAAoC,QAAW,CAAC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package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@123toto/ai-app-assistant-server",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "Framework-neutral Node.js backend for contextual in-app AI assistants",
6
6
  "engines": {
@@ -77,7 +77,7 @@
77
77
  "@ai-sdk/openai": "^3.0.0",
78
78
  "ai": "^6.0.0",
79
79
  "zod": "^4.0.0",
80
- "@123toto/ai-app-assistant-contracts": "0.1.1"
80
+ "@123toto/ai-app-assistant-contracts": "0.2.1"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@nestjs/common": "~11.1.29",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/http.ts"],"sourcesContent":["import {\n askDocumentationRequestSchema,\n type AskDocumentationRequest,\n type AskDocumentationResponse\n} from \"@123toto/ai-app-assistant-contracts\";\nimport { ZodError } from \"zod\";\nimport type { DocsAssistant, DocsAssistantStreamEvent } from \"./assistant.js\";\n\nexport interface AiDocsFetchHandlerOptions<TContext = undefined> {\n assistant: DocsAssistant;\n /** Resolves framework-specific authentication into an application context. */\n resolveContext?: (request: Request) => Promise<TContext> | TContext;\n /** Optional application authorization executed before assistant work. */\n authorize?: (context: TContext, request: Request) => Promise<void> | void;\n /** Explicit opt-in for public prototypes without authentication hooks. */\n allowAnonymous?: boolean;\n /** Optional privacy/input policy applied after protocol validation. */\n transformRequest?: (\n input: AskDocumentationRequest,\n context: TContext\n ) => Promise<AskDocumentationRequest> | AskDocumentationRequest;\n /** Optional privacy/output policy applied before serialization. */\n transformResponse?: (\n response: AskDocumentationResponse,\n context: TContext\n ) => Promise<AskDocumentationResponse> | AskDocumentationResponse;\n /** Applies privacy rules to progressive text before it leaves the backend. */\n transformStreamEvent?: (\n event: DocsAssistantStreamEvent,\n context: TContext\n ) => Promise<DocsAssistantStreamEvent> | DocsAssistantStreamEvent;\n /** Maximum HTTP request size. Defaults slightly above the protocol limit. */\n maxBodyBytes?: number;\n /** Maps application errors without coupling the library to one framework. */\n onError?: (error: unknown, request: Request) => Promise<Response> | Response;\n}\n\nexport interface AiDocsFetchHandlers {\n ask(request: Request): Promise<Response>;\n stream(request: Request): Promise<Response>;\n /** Dispatches to `stream` when the pathname ends in `/stream`, otherwise to `ask`. */\n handle(request: Request): Promise<Response>;\n}\n\n/** Explicit safe HTTP error that host authorization hooks can throw. */\nexport class AiDocsRequestError extends Error {\n public constructor(\n readonly status: number,\n readonly code: string,\n message: string\n ) {\n super(message);\n this.name = \"AiDocsRequestError\";\n }\n}\n\n/**\n * Creates Fetch API handlers usable by standards-based runtimes and thin\n * Express, Fastify, Nest, Next.js, Hono, Bun or serverless adapters.\n */\nexport function createAiDocsFetchHandlers<TContext = undefined>(\n options: AiDocsFetchHandlerOptions<TContext>\n): AiDocsFetchHandlers {\n const prepare = async (request: Request): Promise<{\n input: AskDocumentationRequest;\n context: TContext;\n }> => {\n assertPost(request);\n const raw = await readJson(request, options.maxBodyBytes ?? 8_600_000);\n const validated = askDocumentationRequestSchema.parse(raw);\n if (!options.resolveContext && !options.authorize && !options.allowAnonymous) {\n throw new AiDocsRequestError(401, \"unauthorized\", \"Authentication is required\");\n }\n const context = options.resolveContext\n ? await options.resolveContext(request)\n : undefined as TContext;\n await options.authorize?.(context, request);\n const input = options.transformRequest\n ? await options.transformRequest(validated, context)\n : validated;\n return { input: askDocumentationRequestSchema.parse(input), context };\n };\n\n const present = async (\n response: AskDocumentationResponse,\n context: TContext\n ): Promise<AskDocumentationResponse> => options.transformResponse\n ? options.transformResponse(response, context)\n : response;\n\n const ask = async (request: Request): Promise<Response> => {\n try {\n const { input, context } = await prepare(request);\n return jsonResponse(await present(await options.assistant.answer(input, {\n signal: request.signal\n }), context));\n } catch (error) {\n return mapError(error, request, options.onError);\n }\n };\n\n const stream = async (request: Request): Promise<Response> => {\n try {\n const { input, context } = await prepare(request);\n const encoder = new TextEncoder();\n const body = new ReadableStream<Uint8Array>({\n async start(controller) {\n try {\n const generation = options.assistant.stream(input, { signal: request.signal });\n while (true) {\n const next = await generation.next();\n if (next.done) break;\n let event = next.value.type === \"complete\"\n ? { ...next.value, response: await present(next.value.response, context) }\n : next.value;\n if (options.transformStreamEvent) {\n event = await options.transformStreamEvent(event, context);\n }\n controller.enqueue(encoder.encode(`${JSON.stringify(event)}\\n`));\n }\n } catch {\n controller.enqueue(encoder.encode(`${JSON.stringify({\n type: \"error\",\n message: \"The assistant response could not be generated.\",\n retryable: false\n })}\\n`));\n } finally {\n controller.close();\n }\n }\n });\n return new Response(body, {\n status: 200,\n headers: {\n \"cache-control\": \"no-store\",\n \"content-type\": \"application/x-ndjson; charset=utf-8\",\n \"x-content-type-options\": \"nosniff\"\n }\n });\n } catch (error) {\n return mapError(error, request, options.onError);\n }\n };\n\n return {\n ask,\n stream,\n handle: (request) => new URL(request.url).pathname.endsWith(\"/stream\")\n ? stream(request)\n : ask(request)\n };\n}\n\nfunction assertPost(request: Request): void {\n if (request.method !== \"POST\") {\n throw new AiDocsRequestError(405, \"method_not_allowed\", \"Only POST is supported\");\n }\n}\n\nasync function readJson(request: Request, maxBodyBytes: number): Promise<unknown> {\n const contentLength = Number(request.headers.get(\"content-length\"));\n if (Number.isFinite(contentLength) && contentLength > maxBodyBytes) {\n throw new AiDocsRequestError(413, \"request_too_large\", \"Request body is too large\");\n }\n const text = await request.text();\n if (new TextEncoder().encode(text).byteLength > maxBodyBytes) {\n throw new AiDocsRequestError(413, \"request_too_large\", \"Request body is too large\");\n }\n try {\n return JSON.parse(text) as unknown;\n } catch {\n throw new AiDocsRequestError(400, \"invalid_json\", \"Request body must be valid JSON\");\n }\n}\n\nasync function mapError(\n error: unknown,\n request: Request,\n customMapper?: AiDocsFetchHandlerOptions<unknown>[\"onError\"]\n): Promise<Response> {\n if (customMapper) return customMapper(error, request);\n if (error instanceof AiDocsRequestError) {\n return jsonResponse({ error: error.code, message: error.message }, error.status);\n }\n if (error instanceof ZodError) {\n return jsonResponse({ error: \"invalid_request\", message: \"The assistant request is invalid.\" }, 400);\n }\n return jsonResponse({\n error: \"assistant_error\",\n message: \"The assistant response could not be generated.\"\n }, 500);\n}\n\nfunction jsonResponse(value: unknown, status = 200): Response {\n return new Response(JSON.stringify(value), {\n status,\n headers: {\n \"cache-control\": \"no-store\",\n \"content-type\": \"application/json; charset=utf-8\",\n \"x-content-type-options\": \"nosniff\"\n }\n });\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP,SAAS,gBAAgB;AAwClB,IAAM,qBAAN,cAAiC,MAAM;AAAA,EACrC,YACI,QACA,MACT,SACA;AACA,UAAM,OAAO;AAJJ;AACA;AAIT,SAAK,OAAO;AAAA,EACd;AAAA,EANW;AAAA,EACA;AAMb;AAMO,SAAS,0BACd,SACqB;AACrB,QAAM,UAAU,OAAO,YAGjB;AACJ,eAAW,OAAO;AAClB,UAAM,MAAM,MAAM,SAAS,SAAS,QAAQ,gBAAgB,IAAS;AACrE,UAAM,YAAY,8BAA8B,MAAM,GAAG;AACzD,QAAI,CAAC,QAAQ,kBAAkB,CAAC,QAAQ,aAAa,CAAC,QAAQ,gBAAgB;AAC5E,YAAM,IAAI,mBAAmB,KAAK,gBAAgB,4BAA4B;AAAA,IAChF;AACA,UAAM,UAAU,QAAQ,iBACpB,MAAM,QAAQ,eAAe,OAAO,IACpC;AACJ,UAAM,QAAQ,YAAY,SAAS,OAAO;AAC1C,UAAM,QAAQ,QAAQ,mBAClB,MAAM,QAAQ,iBAAiB,WAAW,OAAO,IACjD;AACJ,WAAO,EAAE,OAAO,8BAA8B,MAAM,KAAK,GAAG,QAAQ;AAAA,EACtE;AAEA,QAAM,UAAU,OACd,UACA,YACsC,QAAQ,oBAC5C,QAAQ,kBAAkB,UAAU,OAAO,IAC3C;AAEJ,QAAM,MAAM,OAAO,YAAwC;AACzD,QAAI;AACF,YAAM,EAAE,OAAO,QAAQ,IAAI,MAAM,QAAQ,OAAO;AAChD,aAAO,aAAa,MAAM,QAAQ,MAAM,QAAQ,UAAU,OAAO,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