agentlang 0.10.8 → 0.11.0

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 (121) hide show
  1. package/README.md +60 -0
  2. package/out/api/http.d.ts.map +1 -1
  3. package/out/api/http.js +64 -39
  4. package/out/api/http.js.map +1 -1
  5. package/out/cli/main.d.ts +1 -1
  6. package/out/cli/main.d.ts.map +1 -1
  7. package/out/cli/main.js +7 -3
  8. package/out/cli/main.js.map +1 -1
  9. package/out/extension/main.cjs +250 -250
  10. package/out/extension/main.cjs.map +2 -2
  11. package/out/language/main.cjs +504 -504
  12. package/out/language/main.cjs.map +3 -3
  13. package/out/runtime/auth/cognito.d.ts.map +1 -1
  14. package/out/runtime/auth/cognito.js +129 -64
  15. package/out/runtime/auth/cognito.js.map +1 -1
  16. package/out/runtime/defs.d.ts +22 -9
  17. package/out/runtime/defs.d.ts.map +1 -1
  18. package/out/runtime/defs.js +44 -9
  19. package/out/runtime/defs.js.map +1 -1
  20. package/out/runtime/document-retriever.d.ts +24 -0
  21. package/out/runtime/document-retriever.d.ts.map +1 -0
  22. package/out/runtime/document-retriever.js +258 -0
  23. package/out/runtime/document-retriever.js.map +1 -0
  24. package/out/runtime/errors/coded-error.d.ts +8 -0
  25. package/out/runtime/errors/coded-error.d.ts.map +1 -0
  26. package/out/runtime/errors/coded-error.js +13 -0
  27. package/out/runtime/errors/coded-error.js.map +1 -0
  28. package/out/runtime/errors/http-error.d.ts +25 -0
  29. package/out/runtime/errors/http-error.d.ts.map +1 -0
  30. package/out/runtime/errors/http-error.js +169 -0
  31. package/out/runtime/errors/http-error.js.map +1 -0
  32. package/out/runtime/excel-resolver.d.ts +4 -0
  33. package/out/runtime/excel-resolver.d.ts.map +1 -0
  34. package/out/runtime/excel-resolver.js +96 -0
  35. package/out/runtime/excel-resolver.js.map +1 -0
  36. package/out/runtime/excel.d.ts +25 -0
  37. package/out/runtime/excel.d.ts.map +1 -0
  38. package/out/runtime/excel.js +127 -0
  39. package/out/runtime/excel.js.map +1 -0
  40. package/out/runtime/exec-graph-cache.d.ts +5 -0
  41. package/out/runtime/exec-graph-cache.d.ts.map +1 -0
  42. package/out/runtime/exec-graph-cache.js +9 -0
  43. package/out/runtime/exec-graph-cache.js.map +1 -0
  44. package/out/runtime/exec-graph.d.ts.map +1 -1
  45. package/out/runtime/exec-graph.js +2 -1
  46. package/out/runtime/exec-graph.js.map +1 -1
  47. package/out/runtime/interpreter.d.ts.map +1 -1
  48. package/out/runtime/interpreter.js +30 -27
  49. package/out/runtime/interpreter.js.map +1 -1
  50. package/out/runtime/loader.d.ts.map +1 -1
  51. package/out/runtime/loader.js +5 -1
  52. package/out/runtime/loader.js.map +1 -1
  53. package/out/runtime/logger.d.ts +6 -0
  54. package/out/runtime/logger.d.ts.map +1 -1
  55. package/out/runtime/logger.js +21 -0
  56. package/out/runtime/logger.js.map +1 -1
  57. package/out/runtime/module.d.ts.map +1 -1
  58. package/out/runtime/module.js +14 -13
  59. package/out/runtime/module.js.map +1 -1
  60. package/out/runtime/modules/ai.d.ts +2 -1
  61. package/out/runtime/modules/ai.d.ts.map +1 -1
  62. package/out/runtime/modules/ai.js +7 -2
  63. package/out/runtime/modules/ai.js.map +1 -1
  64. package/out/runtime/modules/auth.d.ts.map +1 -1
  65. package/out/runtime/modules/auth.js +44 -16
  66. package/out/runtime/modules/auth.js.map +1 -1
  67. package/out/runtime/modules/core.d.ts +6 -0
  68. package/out/runtime/modules/core.d.ts.map +1 -1
  69. package/out/runtime/modules/core.js +20 -0
  70. package/out/runtime/modules/core.js.map +1 -1
  71. package/out/runtime/resolvers/sqldb/database.d.ts.map +1 -1
  72. package/out/runtime/resolvers/sqldb/database.js +76 -39
  73. package/out/runtime/resolvers/sqldb/database.js.map +1 -1
  74. package/out/runtime/resolvers/sqldb/db-errors.d.ts +6 -0
  75. package/out/runtime/resolvers/sqldb/db-errors.d.ts.map +1 -0
  76. package/out/runtime/resolvers/sqldb/db-errors.js +100 -0
  77. package/out/runtime/resolvers/sqldb/db-errors.js.map +1 -0
  78. package/out/runtime/resolvers/vector/lancedb-store.d.ts +16 -0
  79. package/out/runtime/resolvers/vector/lancedb-store.d.ts.map +1 -0
  80. package/out/runtime/resolvers/vector/lancedb-store.js +159 -0
  81. package/out/runtime/resolvers/vector/lancedb-store.js.map +1 -0
  82. package/out/runtime/resolvers/vector/types.d.ts +32 -0
  83. package/out/runtime/resolvers/vector/types.d.ts.map +1 -0
  84. package/out/runtime/resolvers/vector/types.js +2 -0
  85. package/out/runtime/resolvers/vector/types.js.map +1 -0
  86. package/out/runtime/state.d.ts +3 -0
  87. package/out/runtime/state.d.ts.map +1 -1
  88. package/out/runtime/state.js +7 -0
  89. package/out/runtime/state.js.map +1 -1
  90. package/out/setupClassic.d.ts +98 -0
  91. package/out/setupClassic.d.ts.map +1 -0
  92. package/out/setupClassic.js +38 -0
  93. package/out/setupClassic.js.map +1 -0
  94. package/out/setupCommon.d.ts +2 -0
  95. package/out/setupCommon.d.ts.map +1 -0
  96. package/out/setupCommon.js +33 -0
  97. package/out/setupCommon.js.map +1 -0
  98. package/out/setupExtended.d.ts +40 -0
  99. package/out/setupExtended.d.ts.map +1 -0
  100. package/out/setupExtended.js +67 -0
  101. package/out/setupExtended.js.map +1 -0
  102. package/package.json +19 -18
  103. package/src/api/http.ts +71 -37
  104. package/src/cli/main.ts +12 -4
  105. package/src/runtime/auth/cognito.ts +187 -65
  106. package/src/runtime/defs.ts +51 -18
  107. package/src/runtime/errors/coded-error.ts +18 -0
  108. package/src/runtime/errors/http-error.ts +197 -0
  109. package/src/runtime/exec-graph-cache.ts +12 -0
  110. package/src/runtime/exec-graph.ts +2 -2
  111. package/src/runtime/interpreter.ts +73 -28
  112. package/src/runtime/loader.ts +5 -0
  113. package/src/runtime/logger.ts +27 -0
  114. package/src/runtime/module.ts +45 -13
  115. package/src/runtime/modules/ai.ts +11 -2
  116. package/src/runtime/modules/auth.ts +45 -18
  117. package/src/runtime/modules/core.ts +26 -0
  118. package/src/runtime/resolvers/sqldb/database.ts +88 -37
  119. package/src/runtime/resolvers/sqldb/db-errors.ts +113 -0
  120. package/src/runtime/state.ts +7 -0
  121. package/src/xlsx.d.ts +17 -0
@@ -0,0 +1,113 @@
1
+ import { QueryFailedError } from 'typeorm';
2
+ import { createCodedError, isCodedError } from '../../errors/coded-error.js';
3
+
4
+ /**
5
+ * Normalize TypeORM / driver failures into stable Agentlang codes for HTTP and logging.
6
+ * Preserves the original message text on the thrown Error.
7
+ */
8
+ export function mapDatabaseError(err: unknown): never {
9
+ if (isCodedError(err)) {
10
+ throw err;
11
+ }
12
+
13
+ const anyErr = err as any;
14
+ const msg = anyErr instanceof Error ? anyErr.message : String(err);
15
+ const driver = anyErr?.driverError ?? anyErr;
16
+ const sqlState =
17
+ driver?.code !== undefined && driver?.code !== null
18
+ ? String(driver.code)
19
+ : anyErr?.code !== undefined && anyErr?.code !== null
20
+ ? String(anyErr.code)
21
+ : undefined;
22
+ const errno = driver?.errno ?? anyErr?.errno;
23
+
24
+ // PostgreSQL (SQLSTATE)
25
+ if (sqlState === '23505') {
26
+ throw createCodedError(msg, 'AL_DB_UNIQUE_VIOLATION');
27
+ }
28
+ if (sqlState === '23503') {
29
+ throw createCodedError(msg, 'AL_DB_FOREIGN_KEY_VIOLATION');
30
+ }
31
+ if (sqlState === '23502') {
32
+ throw createCodedError(msg, 'AL_DB_NOT_NULL_VIOLATION');
33
+ }
34
+ if (sqlState === '23514') {
35
+ throw createCodedError(msg, 'AL_DB_CHECK_VIOLATION');
36
+ }
37
+ // Invalid text representation / datetime / numeric range (e.g. non-UUID passed to a UUID column).
38
+ if (sqlState === '22P02' || sqlState === '22007' || sqlState === '22003') {
39
+ throw createCodedError(msg, 'AL_DB_INVALID_TYPE');
40
+ }
41
+ if (sqlState === '40P01') {
42
+ throw createCodedError(msg, 'AL_DB_DEADLOCK');
43
+ }
44
+ if (sqlState === '40001' || sqlState === '25P02') {
45
+ throw createCodedError(msg, 'AL_DB_SERIALIZATION_FAILURE');
46
+ }
47
+
48
+ // MySQL / MariaDB (errno)
49
+ if (errno === 1062) {
50
+ throw createCodedError(msg, 'AL_DB_UNIQUE_VIOLATION');
51
+ }
52
+ if (errno === 1451 || errno === 1452) {
53
+ throw createCodedError(msg, 'AL_DB_FOREIGN_KEY_VIOLATION');
54
+ }
55
+ if (errno === 1048) {
56
+ throw createCodedError(msg, 'AL_DB_NOT_NULL_VIOLATION');
57
+ }
58
+ if (errno === 1213) {
59
+ throw createCodedError(msg, 'AL_DB_DEADLOCK');
60
+ }
61
+ if (errno === 1205) {
62
+ throw createCodedError(msg, 'AL_DB_LOCK_WAIT_TIMEOUT');
63
+ }
64
+ if (errno === 1366 || errno === 1292) {
65
+ throw createCodedError(msg, 'AL_DB_INVALID_TYPE');
66
+ }
67
+
68
+ const m = msg.toLowerCase();
69
+
70
+ // Cross-driver message heuristics (SQLite, sql.js, edge cases)
71
+ if (
72
+ /unique constraint|duplicate key value|duplicate entry|unique failed|constraint failed.*unique/i.test(
73
+ m
74
+ )
75
+ ) {
76
+ throw createCodedError(msg, 'AL_DB_UNIQUE_VIOLATION');
77
+ }
78
+ if (/foreign key constraint|foreign key mismatch|references.*fails/i.test(m)) {
79
+ throw createCodedError(msg, 'AL_DB_FOREIGN_KEY_VIOLATION');
80
+ }
81
+ if (/not-null constraint|null value in column|cannot be null|not null constraint/i.test(m)) {
82
+ throw createCodedError(msg, 'AL_DB_NOT_NULL_VIOLATION');
83
+ }
84
+ if (/check constraint/i.test(m)) {
85
+ throw createCodedError(msg, 'AL_DB_CHECK_VIOLATION');
86
+ }
87
+ if (/deadlock/i.test(m)) {
88
+ throw createCodedError(msg, 'AL_DB_DEADLOCK');
89
+ }
90
+ if (/lock wait timeout|could not obtain lock/i.test(m)) {
91
+ throw createCodedError(msg, 'AL_DB_LOCK_WAIT_TIMEOUT');
92
+ }
93
+ if (/could not serialize|serialization failure/i.test(m)) {
94
+ throw createCodedError(msg, 'AL_DB_SERIALIZATION_FAILURE');
95
+ }
96
+ if (/invalid input syntax|incorrect .* value|out of range|datatype mismatch/i.test(m)) {
97
+ throw createCodedError(msg, 'AL_DB_INVALID_TYPE');
98
+ }
99
+
100
+ if (anyErr instanceof QueryFailedError && /syntax error|parse error/i.test(m)) {
101
+ throw createCodedError(msg, 'AL_DB_SYNTAX_ERROR');
102
+ }
103
+
104
+ if (anyErr instanceof QueryFailedError) {
105
+ throw createCodedError(msg, 'AL_DB_QUERY_FAILED');
106
+ }
107
+
108
+ if (anyErr instanceof Error) {
109
+ throw createCodedError(msg, 'AL_DB_QUERY_FAILED');
110
+ }
111
+
112
+ throw createCodedError(String(err), 'AL_DB_QUERY_FAILED');
113
+ }
@@ -140,6 +140,13 @@ export const ConfigSchema = z.object({
140
140
  })
141
141
  )
142
142
  .optional(),
143
+ customErrorMessages: z
144
+ .object({
145
+ // When true, error responses are resolved against the `agentlang/errorMessage`
146
+ // system entity before falling back to the default message.
147
+ enabled: z.boolean().default(false),
148
+ })
149
+ .optional(),
143
150
  });
144
151
 
145
152
  export type Config = z.infer<typeof ConfigSchema>;
package/src/xlsx.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ declare module 'xlsx' {
2
+ interface WorkSheet {}
3
+ interface WorkBook {
4
+ SheetNames: string[];
5
+ Sheets: { [name: string]: WorkSheet };
6
+ }
7
+ export const utils: {
8
+ book_new(): WorkBook;
9
+ json_to_sheet<T extends object>(data: T[]): WorkSheet;
10
+ aoa_to_sheet(data: unknown[][]): WorkSheet;
11
+ book_append_sheet(workbook: WorkBook, sheet: WorkSheet, name: string): void;
12
+ };
13
+ export function write(
14
+ workbook: WorkBook,
15
+ opts: { type: 'buffer'; bookType: 'xlsx' | 'csv' }
16
+ ): Buffer;
17
+ }