@djangocfg/ext-knowbase 1.0.8 → 1.0.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.
Files changed (29) hide show
  1. package/dist/config.cjs +3 -1
  2. package/dist/config.js +3 -1
  3. package/dist/hooks.cjs +71 -16
  4. package/dist/hooks.d.cts +6 -5
  5. package/dist/hooks.d.ts +6 -5
  6. package/dist/hooks.js +70 -16
  7. package/dist/index.cjs +67 -13
  8. package/dist/index.d.cts +81 -25
  9. package/dist/index.d.ts +81 -25
  10. package/dist/index.js +68 -15
  11. package/package.json +7 -5
  12. package/src/api/generated/ext_knowbase/CLAUDE.md +2 -9
  13. package/src/api/generated/ext_knowbase/_utils/fetchers/ext_knowbase__knowbase.ts +2 -1
  14. package/src/api/generated/ext_knowbase/_utils/hooks/ext_knowbase__knowbase.ts +2 -1
  15. package/src/api/generated/ext_knowbase/_utils/schemas/ArchiveSearchResult.schema.ts +3 -3
  16. package/src/api/generated/ext_knowbase/_utils/schemas/CfgKnowbaseSystemArchivesCreateRequest.schema.ts +20 -0
  17. package/src/api/generated/ext_knowbase/_utils/schemas/DocumentArchive.schema.ts +1 -1
  18. package/src/api/generated/ext_knowbase/_utils/schemas/DocumentArchiveDetail.schema.ts +1 -1
  19. package/src/api/generated/ext_knowbase/_utils/schemas/index.ts +1 -0
  20. package/src/api/generated/ext_knowbase/api-instance.ts +61 -13
  21. package/src/api/generated/ext_knowbase/client.ts +23 -2
  22. package/src/api/generated/ext_knowbase/ext_knowbase__knowbase/client.ts +9 -2
  23. package/src/api/generated/ext_knowbase/ext_knowbase__knowbase/models.ts +13 -0
  24. package/src/api/generated/ext_knowbase/http.ts +8 -2
  25. package/src/api/generated/ext_knowbase/index.ts +3 -1
  26. package/src/api/index.ts +6 -1
  27. package/src/components/Chat/ChatWidget.tsx +2 -1
  28. package/src/contexts/knowbase/DocumentsContext.tsx +4 -2
  29. package/src/contexts/knowbase/types.ts +1 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createConsola, consola } from 'consola';
2
2
  import pRetry, { AbortError } from 'p-retry';
3
3
  import { z } from 'zod';
4
- import { createExtensionAPI } from '@djangocfg/ext-base/api';
4
+ import { initializeExtensionAPI, createExtensionAPI } from '@djangocfg/ext-base/api';
5
5
  import 'swr';
6
6
  import { createExtensionConfig } from '@djangocfg/ext-base';
7
7
 
@@ -309,7 +309,14 @@ var ExtKnowbaseKnowbase = class {
309
309
  * Upload archive file and process it synchronously
310
310
  */
311
311
  async systemArchivesCreate(data) {
312
- const response = await this.client.request("POST", "/cfg/knowbase/system/archives/", { formData: data });
312
+ const formData = new FormData();
313
+ formData.append("file", data.file);
314
+ if (data.title !== void 0) formData.append("title", String(data.title));
315
+ if (data.description !== void 0) formData.append("description", String(data.description));
316
+ if (data.category_ids !== void 0) formData.append("category_ids", String(data.category_ids));
317
+ if (data.is_public !== void 0) formData.append("is_public", String(data.is_public));
318
+ if (data.process_immediately !== void 0) formData.append("process_immediately", String(data.process_immediately));
319
+ const response = await this.client.request("POST", "/cfg/knowbase/system/archives/", { formData });
313
320
  return response;
314
321
  }
315
322
  /**
@@ -576,7 +583,7 @@ var models_exports = {};
576
583
  // src/api/generated/ext_knowbase/http.ts
577
584
  var FetchAdapter = class {
578
585
  async request(request) {
579
- const { method, url, headers, body, params, formData } = request;
586
+ const { method, url, headers, body, params, formData, binaryBody } = request;
580
587
  let finalUrl = url;
581
588
  if (params) {
582
589
  const searchParams = new URLSearchParams();
@@ -594,6 +601,9 @@ var FetchAdapter = class {
594
601
  let requestBody;
595
602
  if (formData) {
596
603
  requestBody = formData;
604
+ } else if (binaryBody) {
605
+ finalHeaders["Content-Type"] = "application/octet-stream";
606
+ requestBody = binaryBody;
597
607
  } else if (body) {
598
608
  finalHeaders["Content-Type"] = "application/json";
599
609
  requestBody = JSON.stringify(body);
@@ -918,11 +928,13 @@ var APIClient = class {
918
928
  httpClient;
919
929
  logger = null;
920
930
  retryConfig = null;
931
+ tokenGetter = null;
921
932
  // Sub-clients
922
933
  ext_knowbase_knowbase;
923
934
  constructor(baseUrl, options) {
924
935
  this.baseUrl = baseUrl.replace(/\/$/, "");
925
936
  this.httpClient = options?.httpClient || new FetchAdapter();
937
+ this.tokenGetter = options?.tokenGetter || null;
926
938
  if (options?.loggerConfig !== void 0) {
927
939
  this.logger = new APILogger(options.loggerConfig);
928
940
  }
@@ -945,6 +957,19 @@ var APIClient = class {
945
957
  }
946
958
  return null;
947
959
  }
960
+ /**
961
+ * Get the base URL for building streaming/download URLs.
962
+ */
963
+ getBaseUrl() {
964
+ return this.baseUrl;
965
+ }
966
+ /**
967
+ * Get JWT token for URL authentication (used in streaming endpoints).
968
+ * Returns null if no token getter is configured or no token is available.
969
+ */
970
+ getToken() {
971
+ return this.tokenGetter ? this.tokenGetter() : null;
972
+ }
948
973
  /**
949
974
  * Make HTTP request with Django CSRF and session handling.
950
975
  * Automatically retries on network errors and 5xx server errors.
@@ -975,7 +1000,7 @@ var APIClient = class {
975
1000
  const headers = {
976
1001
  ...options?.headers || {}
977
1002
  };
978
- if (!options?.formData && !headers["Content-Type"]) {
1003
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
979
1004
  headers["Content-Type"] = "application/json";
980
1005
  }
981
1006
  if (this.logger) {
@@ -994,7 +1019,8 @@ var APIClient = class {
994
1019
  headers,
995
1020
  params: options?.params,
996
1021
  body: options?.body,
997
- formData: options?.formData
1022
+ formData: options?.formData,
1023
+ binaryBody: options?.binaryBody
998
1024
  });
999
1025
  const duration = Date.now() - startTime;
1000
1026
  if (response.status >= 400) {
@@ -1378,6 +1404,7 @@ __export(schemas_exports, {
1378
1404
  ArchiveSearchRequestRequestSchema: () => ArchiveSearchRequestRequestSchema,
1379
1405
  ArchiveSearchResultSchema: () => ArchiveSearchResultSchema,
1380
1406
  ArchiveStatisticsSchema: () => ArchiveStatisticsSchema,
1407
+ CfgKnowbaseSystemArchivesCreateRequestSchema: () => CfgKnowbaseSystemArchivesCreateRequestSchema,
1381
1408
  ChatHistorySchema: () => ChatHistorySchema,
1382
1409
  ChatMessageSchema: () => ChatMessageSchema,
1383
1410
  ChatQueryRequestSchema: () => ChatQueryRequestSchema,
@@ -1513,9 +1540,9 @@ var ArchiveSearchRequestRequestSchema = z.object({
1513
1540
  var ArchiveSearchResultSchema = z.object({
1514
1541
  chunk: ArchiveItemChunkSchema,
1515
1542
  similarity_score: z.number(),
1516
- context_summary: z.record(z.string(), z.record(z.string(), z.any())),
1517
- archive_info: z.record(z.string(), z.record(z.string(), z.any())),
1518
- item_info: z.record(z.string(), z.record(z.string(), z.any()))
1543
+ context_summary: z.record(z.string(), z.any()),
1544
+ archive_info: z.record(z.string(), z.any()),
1545
+ item_info: z.record(z.string(), z.any())
1519
1546
  });
1520
1547
  var ArchiveStatisticsSchema = z.object({
1521
1548
  total_archives: z.int(),
@@ -1529,6 +1556,14 @@ var ArchiveStatisticsSchema = z.object({
1529
1556
  avg_items_per_archive: z.number(),
1530
1557
  avg_chunks_per_archive: z.number()
1531
1558
  });
1559
+ var CfgKnowbaseSystemArchivesCreateRequestSchema = z.object({
1560
+ file: z.union([z.instanceof(File), z.instanceof(Blob)]).optional(),
1561
+ title: z.string().optional(),
1562
+ description: z.string().optional(),
1563
+ category_ids: z.array(z.string()).optional(),
1564
+ is_public: z.boolean().optional(),
1565
+ process_immediately: z.boolean().optional()
1566
+ });
1532
1567
  var ChatMessageSchema = z.object({
1533
1568
  id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1534
1569
  role: z.nativeEnum(ChatMessageRole),
@@ -1647,7 +1682,7 @@ var DocumentArchiveSchema = z.object({
1647
1682
  description: z.string().optional(),
1648
1683
  categories: z.array(DocumentCategorySchema),
1649
1684
  is_public: z.boolean().optional(),
1650
- archive_file: z.url(),
1685
+ archive_file: z.union([z.url(), z.literal("")]),
1651
1686
  original_filename: z.string(),
1652
1687
  file_size: z.int(),
1653
1688
  archive_type: z.nativeEnum(DocumentArchiveArchiveType),
@@ -1673,7 +1708,7 @@ var DocumentArchiveDetailSchema = z.object({
1673
1708
  description: z.string().optional(),
1674
1709
  categories: z.array(DocumentCategorySchema),
1675
1710
  is_public: z.boolean().optional(),
1676
- archive_file: z.url(),
1711
+ archive_file: z.union([z.url(), z.literal("")]),
1677
1712
  original_filename: z.string(),
1678
1713
  file_size: z.int(),
1679
1714
  archive_type: z.nativeEnum(DocumentArchiveDetailArchiveType),
@@ -2043,15 +2078,28 @@ __export(fetchers_exports, {
2043
2078
 
2044
2079
  // src/api/generated/ext_knowbase/api-instance.ts
2045
2080
  var globalAPI = null;
2081
+ var autoConfigAttempted = false;
2082
+ function tryAutoConfigureFromEnv() {
2083
+ if (autoConfigAttempted) return;
2084
+ autoConfigAttempted = true;
2085
+ if (globalAPI) return;
2086
+ if (typeof process === "undefined" || !process.env) return;
2087
+ const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || process.env.REACT_APP_API_URL || process.env.API_URL;
2088
+ if (baseUrl) {
2089
+ globalAPI = new API(baseUrl);
2090
+ }
2091
+ }
2046
2092
  function getAPIInstance() {
2093
+ tryAutoConfigureFromEnv();
2047
2094
  if (!globalAPI) {
2048
2095
  throw new Error(
2049
- 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })'
2096
+ 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })\n\nOr set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
2050
2097
  );
2051
2098
  }
2052
2099
  return globalAPI;
2053
2100
  }
2054
2101
  function isAPIConfigured() {
2102
+ tryAutoConfigureFromEnv();
2055
2103
  return globalAPI !== null;
2056
2104
  }
2057
2105
  function configureAPI(config) {
@@ -4202,7 +4250,8 @@ var API = class {
4202
4250
  this._loadTokensFromStorage();
4203
4251
  this._client = new APIClient(this.baseUrl, {
4204
4252
  retryConfig: this.options?.retryConfig,
4205
- loggerConfig: this.options?.loggerConfig
4253
+ loggerConfig: this.options?.loggerConfig,
4254
+ tokenGetter: () => this.getToken()
4206
4255
  });
4207
4256
  this._injectAuthHeader();
4208
4257
  this.ext_knowbase_knowbase = this._client.ext_knowbase_knowbase;
@@ -4214,7 +4263,8 @@ var API = class {
4214
4263
  _reinitClients() {
4215
4264
  this._client = new APIClient(this.baseUrl, {
4216
4265
  retryConfig: this.options?.retryConfig,
4217
- loggerConfig: this.options?.loggerConfig
4266
+ loggerConfig: this.options?.loggerConfig,
4267
+ tokenGetter: () => this.getToken()
4218
4268
  });
4219
4269
  this._injectAuthHeader();
4220
4270
  this.ext_knowbase_knowbase = this._client.ext_knowbase_knowbase;
@@ -4307,12 +4357,13 @@ var API = class {
4307
4357
  };
4308
4358
 
4309
4359
  // src/api/index.ts
4360
+ initializeExtensionAPI(configureAPI);
4310
4361
  var apiKnowbase = createExtensionAPI(API);
4311
4362
 
4312
4363
  // package.json
4313
4364
  var package_default = {
4314
4365
  name: "@djangocfg/ext-knowbase",
4315
- version: "1.0.8",
4366
+ version: "1.0.10",
4316
4367
  description: "Knowledge base and chat extension for DjangoCFG",
4317
4368
  keywords: [
4318
4369
  "django",
@@ -4373,6 +4424,7 @@ var package_default = {
4373
4424
  peerDependencies: {
4374
4425
  "@djangocfg/api": "workspace:*",
4375
4426
  "@djangocfg/ext-base": "workspace:*",
4427
+ "@djangocfg/ui-core": "workspace:*",
4376
4428
  "@djangocfg/ui-nextjs": "workspace:*",
4377
4429
  consola: "^3.4.2",
4378
4430
  "lucide-react": "^0.545.0",
@@ -4388,6 +4440,7 @@ var package_default = {
4388
4440
  devDependencies: {
4389
4441
  "@djangocfg/api": "workspace:*",
4390
4442
  "@djangocfg/ext-base": "workspace:*",
4443
+ "@djangocfg/ui-core": "workspace:*",
4391
4444
  "@djangocfg/typescript-config": "workspace:*",
4392
4445
  "@types/node": "^24.7.2",
4393
4446
  "@types/react": "^19.0.0",
@@ -4435,4 +4488,4 @@ export default function DocsPage() {
4435
4488
  ]
4436
4489
  });
4437
4490
 
4438
- export { API, APIClient, APIError, APILogger, ArchiveItemChunkDetailSchema, ArchiveItemChunkRequestSchema, ArchiveItemChunkSchema, ArchiveItemDetailSchema, ArchiveItemRequestSchema, ArchiveItemSchema, ArchiveProcessingResultSchema, ArchiveSearchRequestRequestSchema, ArchiveSearchResultSchema, ArchiveStatisticsSchema, ChatHistorySchema, ChatMessageSchema, ChatQueryRequestSchema, ChatResponseRequestSchema, ChatResponseSchema, ChatSessionCreateRequestSchema, ChatSessionRequestSchema, ChatSessionSchema, ChatSourceRequestSchema, ChatSourceSchema, ChunkRevectorizationRequestRequestSchema, CookieStorageAdapter, DEFAULT_RETRY_CONFIG, DocumentArchiveDetailSchema, DocumentArchiveListSchema, DocumentArchiveRequestSchema, DocumentArchiveSchema, DocumentCategoryRequestSchema, DocumentCategorySchema, DocumentCreateRequestSchema, DocumentProcessingStatusSchema, DocumentRequestSchema, DocumentSchema, DocumentStatsSchema, enums_exports as Enums, models_exports as ExtKnowbaseKnowbaseTypes, FetchAdapter, fetchers_exports as Fetchers, LocalStorageAdapter, MemoryStorageAdapter, NetworkError, PaginatedArchiveItemChunkListSchema, PaginatedArchiveItemListSchema, PaginatedArchiveSearchResultListSchema, PaginatedChatResponseListSchema, PaginatedChatSessionListSchema, PaginatedDocumentArchiveListListSchema, PaginatedDocumentListSchema, PaginatedPublicCategoryListSchema, PaginatedPublicDocumentListListSchema, PatchedArchiveItemChunkRequestSchema, PatchedArchiveItemRequestSchema, PatchedChatResponseRequestSchema, PatchedChatSessionRequestSchema, PatchedDocumentArchiveRequestSchema, PatchedDocumentRequestSchema, PublicCategorySchema, PublicDocumentListSchema, PublicDocumentSchema, REFRESH_TOKEN_KEY, schemas_exports as Schemas, TOKEN_KEY, VectorizationResultSchema, VectorizationStatisticsSchema, apiKnowbase, clearAPITokens, configureAPI, createKnowbaseAdminChatCreate, createKnowbaseAdminChatQueryCreate, createKnowbaseAdminDocumentsCreate, createKnowbaseAdminDocumentsReprocessCreate, createKnowbaseAdminSessionsActivateCreate, createKnowbaseAdminSessionsArchiveCreate, createKnowbaseAdminSessionsCreate, createKnowbaseSystemArchivesCreate, createKnowbaseSystemArchivesRevectorizeCreate, createKnowbaseSystemArchivesSearchCreate, createKnowbaseSystemChunksCreate, createKnowbaseSystemChunksVectorizeCreate, createKnowbaseSystemItemsCreate, deleteKnowbaseAdminChatDestroy, deleteKnowbaseAdminDocumentsDestroy, deleteKnowbaseAdminSessionsDestroy, deleteKnowbaseSystemArchivesDestroy, deleteKnowbaseSystemChunksDestroy, deleteKnowbaseSystemItemsDestroy, dispatchValidationError, extensionConfig, formatZodError, getAPIInstance, getKnowbaseAdminChatHistoryRetrieve, getKnowbaseAdminChatList, getKnowbaseAdminChatRetrieve, getKnowbaseAdminDocumentsList, getKnowbaseAdminDocumentsRetrieve, getKnowbaseAdminDocumentsStatsRetrieve, getKnowbaseAdminDocumentsStatusRetrieve, getKnowbaseAdminSessionsList, getKnowbaseAdminSessionsRetrieve, getKnowbaseCategoriesList, getKnowbaseCategoriesRetrieve, getKnowbaseDocumentsList, getKnowbaseDocumentsRetrieve, getKnowbaseSystemArchivesFileTreeRetrieve, getKnowbaseSystemArchivesItemsList, getKnowbaseSystemArchivesList, getKnowbaseSystemArchivesRetrieve, getKnowbaseSystemArchivesStatisticsRetrieve, getKnowbaseSystemArchivesVectorizationStatsRetrieve, getKnowbaseSystemChunksContextRetrieve, getKnowbaseSystemChunksList, getKnowbaseSystemChunksRetrieve, getKnowbaseSystemItemsChunksList, getKnowbaseSystemItemsContentRetrieve, getKnowbaseSystemItemsList, getKnowbaseSystemItemsRetrieve, isAPIConfigured, onValidationError, partialUpdateKnowbaseAdminChatPartialUpdate, partialUpdateKnowbaseAdminDocumentsPartialUpdate, partialUpdateKnowbaseAdminSessionsPartialUpdate, partialUpdateKnowbaseSystemArchivesPartialUpdate, partialUpdateKnowbaseSystemChunksPartialUpdate, partialUpdateKnowbaseSystemItemsPartialUpdate, reconfigureAPI, resetAPI, shouldRetry, updateKnowbaseAdminChatUpdate, updateKnowbaseAdminDocumentsUpdate, updateKnowbaseAdminSessionsUpdate, updateKnowbaseSystemArchivesUpdate, updateKnowbaseSystemChunksUpdate, updateKnowbaseSystemItemsUpdate, withRetry };
4491
+ export { API, APIClient, APIError, APILogger, ArchiveItemChunkDetailSchema, ArchiveItemChunkRequestSchema, ArchiveItemChunkSchema, ArchiveItemDetailSchema, ArchiveItemRequestSchema, ArchiveItemSchema, ArchiveProcessingResultSchema, ArchiveSearchRequestRequestSchema, ArchiveSearchResultSchema, ArchiveStatisticsSchema, CfgKnowbaseSystemArchivesCreateRequestSchema, ChatHistorySchema, ChatMessageSchema, ChatQueryRequestSchema, ChatResponseRequestSchema, ChatResponseSchema, ChatSessionCreateRequestSchema, ChatSessionRequestSchema, ChatSessionSchema, ChatSourceRequestSchema, ChatSourceSchema, ChunkRevectorizationRequestRequestSchema, CookieStorageAdapter, DEFAULT_RETRY_CONFIG, DocumentArchiveDetailSchema, DocumentArchiveListSchema, DocumentArchiveRequestSchema, DocumentArchiveSchema, DocumentCategoryRequestSchema, DocumentCategorySchema, DocumentCreateRequestSchema, DocumentProcessingStatusSchema, DocumentRequestSchema, DocumentSchema, DocumentStatsSchema, enums_exports as Enums, models_exports as ExtKnowbaseKnowbaseTypes, FetchAdapter, fetchers_exports as Fetchers, LocalStorageAdapter, MemoryStorageAdapter, NetworkError, PaginatedArchiveItemChunkListSchema, PaginatedArchiveItemListSchema, PaginatedArchiveSearchResultListSchema, PaginatedChatResponseListSchema, PaginatedChatSessionListSchema, PaginatedDocumentArchiveListListSchema, PaginatedDocumentListSchema, PaginatedPublicCategoryListSchema, PaginatedPublicDocumentListListSchema, PatchedArchiveItemChunkRequestSchema, PatchedArchiveItemRequestSchema, PatchedChatResponseRequestSchema, PatchedChatSessionRequestSchema, PatchedDocumentArchiveRequestSchema, PatchedDocumentRequestSchema, PublicCategorySchema, PublicDocumentListSchema, PublicDocumentSchema, REFRESH_TOKEN_KEY, schemas_exports as Schemas, TOKEN_KEY, VectorizationResultSchema, VectorizationStatisticsSchema, apiKnowbase, clearAPITokens, configureAPI, createKnowbaseAdminChatCreate, createKnowbaseAdminChatQueryCreate, createKnowbaseAdminDocumentsCreate, createKnowbaseAdminDocumentsReprocessCreate, createKnowbaseAdminSessionsActivateCreate, createKnowbaseAdminSessionsArchiveCreate, createKnowbaseAdminSessionsCreate, createKnowbaseSystemArchivesCreate, createKnowbaseSystemArchivesRevectorizeCreate, createKnowbaseSystemArchivesSearchCreate, createKnowbaseSystemChunksCreate, createKnowbaseSystemChunksVectorizeCreate, createKnowbaseSystemItemsCreate, deleteKnowbaseAdminChatDestroy, deleteKnowbaseAdminDocumentsDestroy, deleteKnowbaseAdminSessionsDestroy, deleteKnowbaseSystemArchivesDestroy, deleteKnowbaseSystemChunksDestroy, deleteKnowbaseSystemItemsDestroy, dispatchValidationError, extensionConfig, formatZodError, getAPIInstance, getKnowbaseAdminChatHistoryRetrieve, getKnowbaseAdminChatList, getKnowbaseAdminChatRetrieve, getKnowbaseAdminDocumentsList, getKnowbaseAdminDocumentsRetrieve, getKnowbaseAdminDocumentsStatsRetrieve, getKnowbaseAdminDocumentsStatusRetrieve, getKnowbaseAdminSessionsList, getKnowbaseAdminSessionsRetrieve, getKnowbaseCategoriesList, getKnowbaseCategoriesRetrieve, getKnowbaseDocumentsList, getKnowbaseDocumentsRetrieve, getKnowbaseSystemArchivesFileTreeRetrieve, getKnowbaseSystemArchivesItemsList, getKnowbaseSystemArchivesList, getKnowbaseSystemArchivesRetrieve, getKnowbaseSystemArchivesStatisticsRetrieve, getKnowbaseSystemArchivesVectorizationStatsRetrieve, getKnowbaseSystemChunksContextRetrieve, getKnowbaseSystemChunksList, getKnowbaseSystemChunksRetrieve, getKnowbaseSystemItemsChunksList, getKnowbaseSystemItemsContentRetrieve, getKnowbaseSystemItemsList, getKnowbaseSystemItemsRetrieve, isAPIConfigured, onValidationError, partialUpdateKnowbaseAdminChatPartialUpdate, partialUpdateKnowbaseAdminDocumentsPartialUpdate, partialUpdateKnowbaseAdminSessionsPartialUpdate, partialUpdateKnowbaseSystemArchivesPartialUpdate, partialUpdateKnowbaseSystemChunksPartialUpdate, partialUpdateKnowbaseSystemItemsPartialUpdate, reconfigureAPI, resetAPI, shouldRetry, updateKnowbaseAdminChatUpdate, updateKnowbaseAdminDocumentsUpdate, updateKnowbaseAdminSessionsUpdate, updateKnowbaseSystemArchivesUpdate, updateKnowbaseSystemChunksUpdate, updateKnowbaseSystemItemsUpdate, withRetry };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/ext-knowbase",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Knowledge base and chat extension for DjangoCFG",
5
5
  "keywords": [
6
6
  "django",
@@ -59,9 +59,10 @@
59
59
  "check": "tsc --noEmit"
60
60
  },
61
61
  "peerDependencies": {
62
- "@djangocfg/api": "^2.1.91",
62
+ "@djangocfg/api": "^2.1.107",
63
63
  "@djangocfg/ext-base": "^1.0.8",
64
- "@djangocfg/ui-nextjs": "^2.1.91",
64
+ "@djangocfg/ui-core": "^2.1.107",
65
+ "@djangocfg/ui-nextjs": "^2.1.107",
65
66
  "consola": "^3.4.2",
66
67
  "lucide-react": "^0.545.0",
67
68
  "next": "^15.5.7",
@@ -74,9 +75,10 @@
74
75
  "moment": "^2.30.1"
75
76
  },
76
77
  "devDependencies": {
77
- "@djangocfg/api": "^2.1.91",
78
+ "@djangocfg/api": "^2.1.107",
78
79
  "@djangocfg/ext-base": "^1.0.8",
79
- "@djangocfg/typescript-config": "^2.1.91",
80
+ "@djangocfg/ui-core": "^2.1.107",
81
+ "@djangocfg/typescript-config": "^2.1.107",
80
82
  "@types/node": "^24.7.2",
81
83
  "@types/react": "^19.0.0",
82
84
  "consola": "^3.4.2",
@@ -12,7 +12,7 @@ python manage.py generate_client --groups ext_knowbase --typescript
12
12
  |---|---|
13
13
  | Version | 3.0.3 |
14
14
  | Operations | 57 |
15
- | Schemas | 52 |
15
+ | Schemas | 53 |
16
16
 
17
17
  ## Resources
18
18
 
@@ -53,12 +53,5 @@ openapi_client = OpenAPIClientConfig(
53
53
  )
54
54
  ```
55
55
 
56
- **Copy to Next.js** (if `nextjs_admin` configured):
57
- ```python
58
- nextjs_admin = NextJsAdminConfig(
59
- project_path="../frontend/apps/...",
60
- api_output_path="app/_lib/api/generated",
61
- )
62
- ```
63
-
64
56
  @see https://djangocfg.com/docs/features/api-generation
57
+
@@ -40,6 +40,7 @@ import { ArchiveItemRequestSchema, type ArchiveItemRequest } from '../schemas/Ar
40
40
  import { ArchiveProcessingResultSchema, type ArchiveProcessingResult } from '../schemas/ArchiveProcessingResult.schema'
41
41
  import { ArchiveSearchRequestRequestSchema, type ArchiveSearchRequestRequest } from '../schemas/ArchiveSearchRequestRequest.schema'
42
42
  import { ArchiveStatisticsSchema, type ArchiveStatistics } from '../schemas/ArchiveStatistics.schema'
43
+ import { CfgKnowbaseSystemArchivesCreateRequestSchema, type CfgKnowbaseSystemArchivesCreateRequest } from '../schemas/CfgKnowbaseSystemArchivesCreateRequest.schema'
43
44
  import { ChatHistorySchema, type ChatHistory } from '../schemas/ChatHistory.schema'
44
45
  import { ChatQueryRequestSchema, type ChatQueryRequest } from '../schemas/ChatQueryRequest.schema'
45
46
  import { ChatResponseSchema, type ChatResponse } from '../schemas/ChatResponse.schema'
@@ -1664,7 +1665,7 @@ export async function getKnowbaseSystemArchivesList( params?: { page?: number;
1664
1665
  * @method POST
1665
1666
  * @path /cfg/knowbase/system/archives/
1666
1667
  */
1667
- export async function createKnowbaseSystemArchivesCreate( data: any, client?: any
1668
+ export async function createKnowbaseSystemArchivesCreate( data: CfgKnowbaseSystemArchivesCreateRequest, client?: any
1668
1669
  ): Promise<ArchiveProcessingResult> {
1669
1670
  const api = client || getAPIInstance()
1670
1671
  const response = await api.ext_knowbase_knowbase.systemArchivesCreate(data)
@@ -30,6 +30,7 @@ import type { ArchiveItemRequest } from '../schemas/ArchiveItemRequest.schema'
30
30
  import type { ArchiveProcessingResult } from '../schemas/ArchiveProcessingResult.schema'
31
31
  import type { ArchiveSearchRequestRequest } from '../schemas/ArchiveSearchRequestRequest.schema'
32
32
  import type { ArchiveStatistics } from '../schemas/ArchiveStatistics.schema'
33
+ import type { CfgKnowbaseSystemArchivesCreateRequest } from '../schemas/CfgKnowbaseSystemArchivesCreateRequest.schema'
33
34
  import type { ChatHistory } from '../schemas/ChatHistory.schema'
34
35
  import type { ChatQueryRequest } from '../schemas/ChatQueryRequest.schema'
35
36
  import type { ChatResponse } from '../schemas/ChatResponse.schema'
@@ -563,7 +564,7 @@ export function useKnowbaseSystemArchivesList(params?: { page?: number; page_siz
563
564
  export function useCreateKnowbaseSystemArchivesCreate() {
564
565
  const { mutate } = useSWRConfig()
565
566
 
566
- return async (data: any, client?: API): Promise<ArchiveProcessingResult> => {
567
+ return async (data: CfgKnowbaseSystemArchivesCreateRequest, client?: API): Promise<ArchiveProcessingResult> => {
567
568
  const result = await Fetchers.createKnowbaseSystemArchivesCreate(data, client)
568
569
  // Revalidate related queries
569
570
  mutate('cfg-knowbase-system-archives')
@@ -13,9 +13,9 @@ import { ArchiveItemChunkSchema } from './ArchiveItemChunk.schema'
13
13
  export const ArchiveSearchResultSchema = z.object({
14
14
  chunk: ArchiveItemChunkSchema,
15
15
  similarity_score: z.number(),
16
- context_summary: z.record(z.string(), z.record(z.string(), z.any())),
17
- archive_info: z.record(z.string(), z.record(z.string(), z.any())),
18
- item_info: z.record(z.string(), z.record(z.string(), z.any())),
16
+ context_summary: z.record(z.string(), z.any()),
17
+ archive_info: z.record(z.string(), z.any()),
18
+ item_info: z.record(z.string(), z.any()),
19
19
  })
20
20
 
21
21
  /**
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Zod schema for CfgKnowbaseSystemArchivesCreateRequest
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * */
6
+ import { z } from 'zod'
7
+
8
+ export const CfgKnowbaseSystemArchivesCreateRequestSchema = z.object({
9
+ file: z.union([z.instanceof(File), z.instanceof(Blob)]).optional(),
10
+ title: z.string().optional(),
11
+ description: z.string().optional(),
12
+ category_ids: z.array(z.string()).optional(),
13
+ is_public: z.boolean().optional(),
14
+ process_immediately: z.boolean().optional(),
15
+ })
16
+
17
+ /**
18
+ * Infer TypeScript type from Zod schema
19
+ */
20
+ export type CfgKnowbaseSystemArchivesCreateRequest = z.infer<typeof CfgKnowbaseSystemArchivesCreateRequestSchema>
@@ -17,7 +17,7 @@ export const DocumentArchiveSchema = z.object({
17
17
  description: z.string().optional(),
18
18
  categories: z.array(DocumentCategorySchema),
19
19
  is_public: z.boolean().optional(),
20
- archive_file: z.url(),
20
+ archive_file: z.union([z.url(), z.literal('')]),
21
21
  original_filename: z.string(),
22
22
  file_size: z.int(),
23
23
  archive_type: z.nativeEnum(Enums.DocumentArchiveArchiveType),
@@ -18,7 +18,7 @@ export const DocumentArchiveDetailSchema = z.object({
18
18
  description: z.string().optional(),
19
19
  categories: z.array(DocumentCategorySchema),
20
20
  is_public: z.boolean().optional(),
21
- archive_file: z.url(),
21
+ archive_file: z.union([z.url(), z.literal('')]),
22
22
  original_filename: z.string(),
23
23
  file_size: z.int(),
24
24
  archive_type: z.nativeEnum(Enums.DocumentArchiveDetailArchiveType),
@@ -27,6 +27,7 @@ export * from './ArchiveProcessingResult.schema'
27
27
  export * from './ArchiveSearchRequestRequest.schema'
28
28
  export * from './ArchiveSearchResult.schema'
29
29
  export * from './ArchiveStatistics.schema'
30
+ export * from './CfgKnowbaseSystemArchivesCreateRequest.schema'
30
31
  export * from './ChatHistory.schema'
31
32
  export * from './ChatMessage.schema'
32
33
  export * from './ChatQueryRequest.schema'
@@ -1,29 +1,37 @@
1
1
  // Auto-generated by DjangoCFG - see CLAUDE.md
2
2
  /**
3
- * Global API Instance - Singleton configuration
3
+ * Global API Instance - Singleton configuration with auto-configuration support
4
4
  *
5
- * This module provides a global API instance that can be configured once
6
- * and used throughout your application.
5
+ * This module provides a global API instance that auto-configures from
6
+ * environment variables or can be configured manually.
7
7
  *
8
- * Usage:
8
+ * AUTO-CONFIGURATION (recommended):
9
+ * Set one of these environment variables and the API will auto-configure:
10
+ * - NEXT_PUBLIC_API_URL (Next.js)
11
+ * - VITE_API_URL (Vite)
12
+ * - REACT_APP_API_URL (Create React App)
13
+ * - API_URL (generic)
14
+ *
15
+ * Then just use fetchers and hooks directly:
16
+ * ```typescript
17
+ * import { getUsers } from './_utils/fetchers'
18
+ * const users = await getUsers({ page: 1 })
19
+ * ```
20
+ *
21
+ * MANUAL CONFIGURATION:
9
22
  * ```typescript
10
- * // Configure once (e.g., in your app entry point)
11
23
  * import { configureAPI } from './api-instance'
12
24
  *
13
25
  * configureAPI({
14
26
  * baseUrl: 'https://api.example.com',
15
27
  * token: 'your-jwt-token'
16
28
  * })
17
- *
18
- * // Then use fetchers and hooks anywhere without configuration
19
- * import { getUsers } from './fetchers'
20
- * const users = await getUsers({ page: 1 })
21
29
  * ```
22
30
  *
23
31
  * For SSR or multiple instances:
24
32
  * ```typescript
25
33
  * import { API } from './index'
26
- * import { getUsers } from './fetchers'
34
+ * import { getUsers } from './_utils/fetchers'
27
35
  *
28
36
  * const api = new API('https://api.example.com')
29
37
  * const users = await getUsers({ page: 1 }, api)
@@ -33,27 +41,67 @@
33
41
  import { API, type APIOptions } from './index'
34
42
 
35
43
  let globalAPI: API | null = null
44
+ let autoConfigAttempted = false
45
+
46
+ /**
47
+ * Auto-configure from environment variable if available (Next.js pattern)
48
+ * This allows hooks and fetchers to work without explicit configureAPI() call
49
+ *
50
+ * Supported environment variables:
51
+ * - NEXT_PUBLIC_API_URL (Next.js)
52
+ * - VITE_API_URL (Vite)
53
+ * - REACT_APP_API_URL (Create React App)
54
+ * - API_URL (generic)
55
+ */
56
+ function tryAutoConfigureFromEnv(): void {
57
+ // Only attempt once
58
+ if (autoConfigAttempted) return
59
+ autoConfigAttempted = true
60
+
61
+ // Skip if already configured
62
+ if (globalAPI) return
63
+
64
+ // Skip if process is not available (pure browser without bundler)
65
+ if (typeof process === 'undefined' || !process.env) return
66
+
67
+ // Try different environment variable patterns
68
+ const baseUrl =
69
+ process.env.NEXT_PUBLIC_API_URL ||
70
+ process.env.VITE_API_URL ||
71
+ process.env.REACT_APP_API_URL ||
72
+ process.env.API_URL
73
+
74
+ if (baseUrl) {
75
+ globalAPI = new API(baseUrl)
76
+ }
77
+ }
36
78
 
37
79
  /**
38
80
  * Get the global API instance
39
- * @throws Error if API is not configured
81
+ * Auto-configures from environment variables on first call if not manually configured.
82
+ * @throws Error if API is not configured and no env variable is set
40
83
  */
41
84
  export function getAPIInstance(): API {
85
+ // Try auto-configuration on first access (lazy initialization)
86
+ tryAutoConfigureFromEnv()
87
+
42
88
  if (!globalAPI) {
43
89
  throw new Error(
44
90
  'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\n' +
45
91
  'Example:\n' +
46
92
  ' import { configureAPI } from "./api-instance"\n' +
47
- ' configureAPI({ baseUrl: "https://api.example.com" })'
93
+ ' configureAPI({ baseUrl: "https://api.example.com" })\n\n' +
94
+ 'Or set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
48
95
  )
49
96
  }
50
97
  return globalAPI
51
98
  }
52
99
 
53
100
  /**
54
- * Check if API is configured
101
+ * Check if API is configured (or can be auto-configured)
55
102
  */
56
103
  export function isAPIConfigured(): boolean {
104
+ tryAutoConfigureFromEnv()
57
105
  return globalAPI !== null
58
106
  }
59
107
 
@@ -25,6 +25,7 @@ export class APIClient {
25
25
  private httpClient: HttpClientAdapter;
26
26
  private logger: APILogger | null = null;
27
27
  private retryConfig: RetryConfig | null = null;
28
+ private tokenGetter: (() => string | null) | null = null;
28
29
 
29
30
  // Sub-clients
30
31
  public ext_knowbase_knowbase: ExtKnowbaseKnowbase;
@@ -35,10 +36,12 @@ export class APIClient {
35
36
  httpClient?: HttpClientAdapter;
36
37
  loggerConfig?: Partial<LoggerConfig>;
37
38
  retryConfig?: RetryConfig;
39
+ tokenGetter?: () => string | null;
38
40
  }
39
41
  ) {
40
42
  this.baseUrl = baseUrl.replace(/\/$/, '');
41
43
  this.httpClient = options?.httpClient || new FetchAdapter();
44
+ this.tokenGetter = options?.tokenGetter || null;
42
45
 
43
46
  // Initialize logger if config provided
44
47
  if (options?.loggerConfig !== undefined) {
@@ -69,6 +72,21 @@ export class APIClient {
69
72
  return null;
70
73
  }
71
74
 
75
+ /**
76
+ * Get the base URL for building streaming/download URLs.
77
+ */
78
+ getBaseUrl(): string {
79
+ return this.baseUrl;
80
+ }
81
+
82
+ /**
83
+ * Get JWT token for URL authentication (used in streaming endpoints).
84
+ * Returns null if no token getter is configured or no token is available.
85
+ */
86
+ getToken(): string | null {
87
+ return this.tokenGetter ? this.tokenGetter() : null;
88
+ }
89
+
72
90
  /**
73
91
  * Make HTTP request with Django CSRF and session handling.
74
92
  * Automatically retries on network errors and 5xx server errors.
@@ -80,6 +98,7 @@ export class APIClient {
80
98
  params?: Record<string, any>;
81
99
  body?: any;
82
100
  formData?: FormData;
101
+ binaryBody?: Blob | ArrayBuffer;
83
102
  headers?: Record<string, string>;
84
103
  }
85
104
  ): Promise<T> {
@@ -116,6 +135,7 @@ export class APIClient {
116
135
  params?: Record<string, any>;
117
136
  body?: any;
118
137
  formData?: FormData;
138
+ binaryBody?: Blob | ArrayBuffer;
119
139
  headers?: Record<string, string>;
120
140
  }
121
141
  ): Promise<T> {
@@ -129,8 +149,8 @@ export class APIClient {
129
149
  ...(options?.headers || {})
130
150
  };
131
151
 
132
- // Don't set Content-Type for FormData (browser will set it with boundary)
133
- if (!options?.formData && !headers['Content-Type']) {
152
+ // Don't set Content-Type for FormData/binaryBody (browser will set it with boundary)
153
+ if (!options?.formData && !options?.binaryBody && !headers['Content-Type']) {
134
154
  headers['Content-Type'] = 'application/json';
135
155
  }
136
156
 
@@ -157,6 +177,7 @@ export class APIClient {
157
177
  params: options?.params,
158
178
  body: options?.body,
159
179
  formData: options?.formData,
180
+ binaryBody: options?.binaryBody,
160
181
  });
161
182
 
162
183
  const duration = Date.now() - startTime;
@@ -356,8 +356,15 @@ export class ExtKnowbaseKnowbase {
356
356
  *
357
357
  * Upload archive file and process it synchronously
358
358
  */
359
- async systemArchivesCreate(data: FormData): Promise<Models.ArchiveProcessingResult> {
360
- const response = await this.client.request('POST', "/cfg/knowbase/system/archives/", { formData: data });
359
+ async systemArchivesCreate(data: Models.CfgKnowbaseSystemArchivesCreateRequest): Promise<Models.ArchiveProcessingResult> {
360
+ const formData = new FormData();
361
+ formData.append('file', data.file);
362
+ if (data.title !== undefined) formData.append('title', String(data.title));
363
+ if (data.description !== undefined) formData.append('description', String(data.description));
364
+ if (data.category_ids !== undefined) formData.append('category_ids', String(data.category_ids));
365
+ if (data.is_public !== undefined) formData.append('is_public', String(data.is_public));
366
+ if (data.process_immediately !== undefined) formData.append('process_immediately', String(data.process_immediately));
367
+ const response = await this.client.request('POST', "/cfg/knowbase/system/archives/", { formData });
361
368
  return response;
362
369
  }
363
370
 
@@ -434,6 +434,19 @@ export interface PaginatedDocumentArchiveListList {
434
434
  results: Array<DocumentArchiveList>;
435
435
  }
436
436
 
437
+ /**
438
+ *
439
+ * Request model (no read-only fields).
440
+ */
441
+ export interface CfgKnowbaseSystemArchivesCreateRequest {
442
+ file?: File | Blob;
443
+ title?: string;
444
+ description?: string;
445
+ category_ids?: Array<string>;
446
+ is_public?: boolean;
447
+ process_immediately?: boolean;
448
+ }
449
+
437
450
  /**
438
451
  * Archive processing result serializer.
439
452
  *