agentlang 0.4.3 → 0.4.5

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 (63) hide show
  1. package/out/api/http.d.ts.map +1 -1
  2. package/out/api/http.js +3 -0
  3. package/out/api/http.js.map +1 -1
  4. package/out/language/generated/ast.d.ts +21 -3
  5. package/out/language/generated/ast.d.ts.map +1 -1
  6. package/out/language/generated/ast.js +29 -1
  7. package/out/language/generated/ast.js.map +1 -1
  8. package/out/language/generated/grammar.d.ts.map +1 -1
  9. package/out/language/generated/grammar.js +286 -129
  10. package/out/language/generated/grammar.js.map +1 -1
  11. package/out/language/main.cjs +308 -130
  12. package/out/language/main.cjs.map +2 -2
  13. package/out/language/parser.d.ts +5 -0
  14. package/out/language/parser.d.ts.map +1 -1
  15. package/out/language/parser.js +6 -0
  16. package/out/language/parser.js.map +1 -1
  17. package/out/runtime/loader.d.ts.map +1 -1
  18. package/out/runtime/loader.js +67 -2
  19. package/out/runtime/loader.js.map +1 -1
  20. package/out/runtime/module.d.ts +33 -0
  21. package/out/runtime/module.d.ts.map +1 -1
  22. package/out/runtime/module.js +161 -0
  23. package/out/runtime/module.js.map +1 -1
  24. package/out/runtime/modules/ai.d.ts +6 -0
  25. package/out/runtime/modules/ai.d.ts.map +1 -1
  26. package/out/runtime/modules/ai.js +71 -2
  27. package/out/runtime/modules/ai.js.map +1 -1
  28. package/out/runtime/modules/core.d.ts.map +1 -1
  29. package/out/runtime/modules/core.js +10 -1
  30. package/out/runtime/modules/core.js.map +1 -1
  31. package/out/runtime/util.d.ts.map +1 -1
  32. package/out/runtime/util.js +0 -1
  33. package/out/runtime/util.js.map +1 -1
  34. package/out/syntaxes/agentlang.monarch.js +1 -1
  35. package/out/syntaxes/agentlang.monarch.js.map +1 -1
  36. package/package.json +183 -184
  37. package/src/api/http.ts +3 -0
  38. package/src/language/agentlang.langium +5 -1
  39. package/src/language/generated/ast.ts +54 -4
  40. package/src/language/generated/grammar.ts +286 -129
  41. package/src/language/parser.ts +12 -0
  42. package/src/runtime/loader.ts +66 -0
  43. package/src/runtime/module.ts +187 -0
  44. package/src/runtime/modules/ai.ts +97 -2
  45. package/src/runtime/modules/core.ts +10 -1
  46. package/src/runtime/util.ts +0 -2
  47. package/src/syntaxes/agentlang.monarch.ts +1 -1
  48. package/out/runtime/modules/files.d.ts +0 -18
  49. package/out/runtime/modules/files.d.ts.map +0 -1
  50. package/out/runtime/modules/files.js +0 -116
  51. package/out/runtime/modules/files.js.map +0 -1
  52. package/out/setupClassic.d.ts +0 -98
  53. package/out/setupClassic.d.ts.map +0 -1
  54. package/out/setupClassic.js +0 -38
  55. package/out/setupClassic.js.map +0 -1
  56. package/out/setupCommon.d.ts +0 -2
  57. package/out/setupCommon.d.ts.map +0 -1
  58. package/out/setupCommon.js +0 -33
  59. package/out/setupCommon.js.map +0 -1
  60. package/out/setupExtended.d.ts +0 -40
  61. package/out/setupExtended.d.ts.map +0 -1
  62. package/out/setupExtended.js +0 -67
  63. package/out/setupExtended.js.map +0 -1
@@ -399,3 +399,15 @@ export function introspectIf(ifpat: If): IfPattern {
399
399
  function introspectDelete(deletePat: Delete): DeletePattern {
400
400
  return new DeletePattern(introspectPattern(deletePat.pattern));
401
401
  }
402
+
403
+ export type CasePattern = {
404
+ condition: BasePattern;
405
+ body: BasePattern;
406
+ };
407
+
408
+ export async function introspectCase(caseStr: string): Promise<CasePattern> {
409
+ const s = `if ${caseStr.trim().substring(4).trimStart()}`;
410
+ const pat = await introspect(s);
411
+ const ifPat = pat[0] as IfPattern;
412
+ return { condition: ifPat.condition, body: ifPat.body[0] };
413
+ }
@@ -44,6 +44,9 @@ import {
44
44
  isPublicEventDefinition,
45
45
  AgentXtraAttribute,
46
46
  If,
47
+ isRetryDefinition,
48
+ RetryDefinition,
49
+ SetAttribute,
47
50
  } from '../language/generated/ast.js';
48
51
  import {
49
52
  addEntity,
@@ -64,6 +67,7 @@ import {
64
67
  newInstanceAttributes,
65
68
  addAgent,
66
69
  fetchModule,
70
+ Retry,
67
71
  } from './module.js';
68
72
  import {
69
73
  asStringLiteralsMap,
@@ -915,6 +919,67 @@ function addGlossaryEntryDefintion(def: GlossaryEntryDefinition, moduleName: str
915
919
  }
916
920
  }
917
921
 
922
+ function addRetryDefinition(def: RetryDefinition, moduleName: string) {
923
+ const retry = new Retry(def.name, moduleName, def.attempts !== undefined ? def.attempts : 0);
924
+ if (def.backoff) {
925
+ def.backoff.attributes.forEach((attr: SetAttribute) => {
926
+ if (isLiteral(attr.value)) {
927
+ switch (attr.name) {
928
+ case 'strategy':
929
+ switch (attr.value.id || attr.value.str) {
930
+ case 'exponential':
931
+ retry.setExponentialBackoff();
932
+ break;
933
+ case 'linear':
934
+ retry.setLinearBackoff();
935
+ break;
936
+ case 'constant':
937
+ retry.setConstantBackoff();
938
+ break;
939
+ default:
940
+ throw new Error(`Invalid backoff strategy ${attr.value} specified for ${def.name}`);
941
+ }
942
+ break;
943
+ case 'delay':
944
+ if (attr.value.num) {
945
+ retry.setBackoffDelay(attr.value.num);
946
+ } else {
947
+ throw new Error(`Backoff delay must be a numeric value for ${def.name}`);
948
+ }
949
+ break;
950
+ case 'magnitude':
951
+ switch (attr.value.id || attr.value.str) {
952
+ case 'milliseconds':
953
+ retry.setBackoffMagnitudeAsMilliseconds();
954
+ break;
955
+ case 'seconds':
956
+ retry.setBackoffMagnitudeAsSeconds();
957
+ break;
958
+ case 'minutes':
959
+ retry.setBackoffMagnitudeAsMinutes();
960
+ break;
961
+ default:
962
+ throw new Error(`Invalid backoff magnitude ${attr.value} set for ${def.name}`);
963
+ }
964
+ break;
965
+ case 'factor':
966
+ if (attr.value.num) {
967
+ retry.setBackoffFactor(attr.value.num);
968
+ } else {
969
+ throw new Error(`Backoff factor must be a number for ${def.name}`);
970
+ }
971
+ break;
972
+ default:
973
+ throw new Error(`Invalid backoff option ${attr.name} specified for ${def.name}`);
974
+ }
975
+ } else {
976
+ throw new Error(`strategy must be a string in ${def.name}`);
977
+ }
978
+ });
979
+ }
980
+ fetchModule(moduleName).addRetry(retry);
981
+ }
982
+
918
983
  function addResolverDefinition(def: ResolverDefinition, moduleName: string) {
919
984
  const resolverName = `${moduleName}/${def.name}`;
920
985
  const paths = def.paths;
@@ -981,6 +1046,7 @@ export async function addFromDef(def: Definition, moduleName: string) {
981
1046
  else if (isScenarioDefinition(def)) addScenarioDefintion(def, moduleName);
982
1047
  else if (isDirectiveDefinition(def)) addDirectiveDefintion(def, moduleName);
983
1048
  else if (isGlossaryEntryDefinition(def)) addGlossaryEntryDefintion(def, moduleName);
1049
+ else if (isRetryDefinition(def)) addRetryDefinition(def, moduleName);
984
1050
  }
985
1051
 
986
1052
  export async function parseAndIntern(code: string, moduleName?: string) {
@@ -1689,6 +1689,178 @@ export function flowGraphNext(
1689
1689
  return undefined;
1690
1690
  }
1691
1691
 
1692
+ type BackoffStrategy = 'e' | 'l' | 'c'; // exponential, linear, constant
1693
+ type BackoffMagnitude = 'ms' | 's' | 'm'; // milliseconds, seconds, minutes
1694
+
1695
+ export type RetryBackoff = {
1696
+ strategy: BackoffStrategy | undefined;
1697
+ delay: number | undefined;
1698
+ magnitude: BackoffMagnitude | undefined;
1699
+ factor: number | undefined;
1700
+ };
1701
+
1702
+ export class Retry extends ModuleEntry {
1703
+ attempts: number;
1704
+ private backoff: RetryBackoff;
1705
+
1706
+ constructor(name: string, moduleName: string, attempts: number) {
1707
+ super(name, moduleName);
1708
+ this.attempts = attempts <= 0 ? 0 : attempts;
1709
+ this.backoff = {
1710
+ strategy: undefined,
1711
+ delay: undefined,
1712
+ magnitude: undefined,
1713
+ factor: undefined,
1714
+ };
1715
+ }
1716
+
1717
+ setExponentialBackoff(): Retry {
1718
+ this.backoff.strategy = 'e';
1719
+ return this;
1720
+ }
1721
+
1722
+ isExponentialBackoff(): boolean {
1723
+ return this.backoff.strategy === 'e';
1724
+ }
1725
+
1726
+ setLinearBackoff(): Retry {
1727
+ this.backoff.strategy = 'l';
1728
+ return this;
1729
+ }
1730
+
1731
+ isLinearBackoff(): boolean {
1732
+ return this.backoff.strategy === 'l';
1733
+ }
1734
+
1735
+ setConstantBackoff(): Retry {
1736
+ this.backoff.strategy = 'c';
1737
+ return this;
1738
+ }
1739
+
1740
+ isConstantBackoff(): boolean {
1741
+ return this.backoff.strategy === undefined || this.backoff.strategy === 'c';
1742
+ }
1743
+
1744
+ setBackoffDelay(n: number): Retry {
1745
+ if (n > 0) {
1746
+ this.backoff.delay = n;
1747
+ }
1748
+ return this;
1749
+ }
1750
+
1751
+ setBackoffMagnitudeAsMilliseconds(): Retry {
1752
+ this.backoff.magnitude = 'ms';
1753
+ return this;
1754
+ }
1755
+
1756
+ backoffMagnitudeIsMilliseconds(): boolean {
1757
+ return this.backoff.magnitude === 'ms';
1758
+ }
1759
+
1760
+ setBackoffMagnitudeAsSeconds(): Retry {
1761
+ this.backoff.magnitude = 's';
1762
+ return this;
1763
+ }
1764
+
1765
+ backoffMagnitudeIsSeconds(): boolean {
1766
+ return this.backoff.magnitude === 's';
1767
+ }
1768
+
1769
+ setBackoffMagnitudeAsMinutes(): Retry {
1770
+ this.backoff.magnitude = 'm';
1771
+ return this;
1772
+ }
1773
+
1774
+ backoffMagnitudeIsMinutes(): boolean {
1775
+ return this.backoff.magnitude === 'm';
1776
+ }
1777
+
1778
+ setBackoffFactor(n: number): Retry {
1779
+ if (n !== 0) this.backoff.factor = n;
1780
+ return this;
1781
+ }
1782
+
1783
+ getNextDelayMs(attempt: number): number {
1784
+ if (attempt >= this.attempts) {
1785
+ return 0;
1786
+ }
1787
+ const delay = this.backoff.delay === undefined ? 2 : this.backoff.delay;
1788
+ if (attempt <= 0 || this.isConstantBackoff()) {
1789
+ return this.normalizeDelay(delay);
1790
+ }
1791
+ let d = delay;
1792
+ let i = 0;
1793
+ const factor = this.backoff.factor === undefined ? 1 : this.backoff.factor;
1794
+ if (this.isExponentialBackoff()) {
1795
+ while (i < attempt) {
1796
+ d *= factor;
1797
+ ++i;
1798
+ }
1799
+ } else {
1800
+ while (i < attempt) {
1801
+ d += factor;
1802
+ ++i;
1803
+ }
1804
+ }
1805
+ return this.normalizeDelay(d);
1806
+ }
1807
+
1808
+ private normalizeDelay(d: number): number {
1809
+ if (this.backoffMagnitudeIsMilliseconds()) return d;
1810
+ else if (this.backoffMagnitudeIsSeconds()) return d * 1000;
1811
+ else return d * 60 * 1000;
1812
+ }
1813
+
1814
+ private backoffToString(): string | undefined {
1815
+ const strat = this.backoff.strategy;
1816
+ const delay = this.backoff.delay;
1817
+ const mag = this.backoff.magnitude;
1818
+ const fact = this.backoff.factor;
1819
+ if (strat === undefined && delay === undefined && mag === undefined && fact === undefined) {
1820
+ return undefined;
1821
+ }
1822
+ const ss = new Array<string>();
1823
+ if (strat !== undefined) {
1824
+ let s = 'constant';
1825
+ if (this.isExponentialBackoff()) {
1826
+ s = 'exponential';
1827
+ } else if (this.isLinearBackoff()) {
1828
+ s = 'linear';
1829
+ }
1830
+ ss.push(`strategy ${s}`);
1831
+ }
1832
+ if (delay !== undefined) {
1833
+ ss.push(`delay ${delay}`);
1834
+ }
1835
+ if (mag !== undefined) {
1836
+ let s = 'milliseconds';
1837
+ if (this.backoffMagnitudeIsSeconds()) {
1838
+ s = 'seconds';
1839
+ } else if (this.backoffMagnitudeIsMinutes()) {
1840
+ s = 'minutes';
1841
+ }
1842
+ ss.push(`magnitude ${s}`);
1843
+ }
1844
+ if (fact !== undefined) {
1845
+ ss.push(`factor ${fact}`);
1846
+ }
1847
+ return `backoff {
1848
+ ${ss.join(',\n ')}
1849
+ }`;
1850
+ }
1851
+
1852
+ override toString(): string {
1853
+ const s = `agentlang/retry ${this.name} {
1854
+ attempts ${this.attempts}`;
1855
+ const b = this.backoffToString();
1856
+ if (b) {
1857
+ return `${s},\n ${b}\n}`;
1858
+ } else {
1859
+ return `${s}\n}`;
1860
+ }
1861
+ }
1862
+ }
1863
+
1692
1864
  export class Decision extends ModuleEntry {
1693
1865
  cases: string[];
1694
1866
 
@@ -1959,6 +2131,21 @@ export class Module {
1959
2131
  return this;
1960
2132
  }
1961
2133
 
2134
+ addRetry(retry: Retry): Module {
2135
+ this.addEntry(retry);
2136
+ return this;
2137
+ }
2138
+
2139
+ getRetry(name: string): Retry | undefined {
2140
+ if (this.hasEntry(name)) {
2141
+ const e = this.getEntry(name);
2142
+ if (e instanceof Retry) {
2143
+ return e as Retry;
2144
+ }
2145
+ }
2146
+ return undefined;
2147
+ }
2148
+
1962
2149
  addStandaloneStatement(stmt: Statement): StandaloneStatement {
1963
2150
  const s = new StandaloneStatement(stmt, this.name);
1964
2151
  this.addEntry(s);
@@ -1,4 +1,13 @@
1
- import { isFqName, makeCoreModuleName, makeFqName, nameToPath, splitFqName } from '../util.js';
1
+ import {
2
+ escapeSpecialChars,
3
+ isFqName,
4
+ isString,
5
+ makeCoreModuleName,
6
+ makeFqName,
7
+ nameToPath,
8
+ sleepMilliseconds,
9
+ splitFqName,
10
+ } from '../util.js';
2
11
  import {
3
12
  Environment,
4
13
  GlobalEnvironment,
@@ -16,6 +25,7 @@ import {
16
25
  makeInstance,
17
26
  newInstanceAttributes,
18
27
  Record,
28
+ Retry,
19
29
  } from '../module.js';
20
30
  import { provider } from '../agents/registry.js';
21
31
  import {
@@ -68,6 +78,8 @@ entity ${AgentEntityName} {
68
78
  channels String @optional, // comma-separated list of channel names
69
79
  role String @optional,
70
80
  flows String @optional,
81
+ validate String @optional,
82
+ retry String @optional,
71
83
  llm String
72
84
  }
73
85
 
@@ -113,11 +125,14 @@ export class AgentInstance {
113
125
  runWorkflows: boolean = true;
114
126
  role: string | undefined;
115
127
  flows: string | undefined;
128
+ validate: string | undefined;
129
+ retry: string | undefined;
116
130
  private toolsArray: string[] | undefined = undefined;
117
131
  private hasModuleTools = false;
118
132
  private withSession = true;
119
133
  private fqName: string | undefined;
120
134
  private decisionExecutor = false;
135
+ private retryObj: Retry | undefined;
121
136
 
122
137
  private constructor() {}
123
138
 
@@ -150,6 +165,15 @@ export class AgentInstance {
150
165
  if (agent.hasModuleTools) break;
151
166
  }
152
167
  }
168
+ if (agent.retry) {
169
+ let n = agent.retry;
170
+ if (!isFqName(n)) {
171
+ n = `${agent.moduleName}/${n}`;
172
+ }
173
+ const parts = splitFqName(n);
174
+ const m = fetchModule(parts[0]);
175
+ agent.retryObj = m.getRetry(parts[1]);
176
+ }
153
177
  return agent;
154
178
  }
155
179
 
@@ -404,7 +428,11 @@ Only return a pure JSON object with no extra text, annotations etc.`;
404
428
  })
405
429
  .join('\n')}`
406
430
  );
407
- const response: AIResponse = await p.invoke(msgs, externalToolSpecs);
431
+ let response: AIResponse = await p.invoke(msgs, externalToolSpecs);
432
+ const v = this.getValidationEvent();
433
+ if (v) {
434
+ response = await this.handleValidation(response, v, msgs, p);
435
+ }
408
436
  msgs.push(assistantMessage(response.content));
409
437
  if (isplnr) {
410
438
  msgs[0] = sysMsg;
@@ -422,6 +450,73 @@ Only return a pure JSON object with no extra text, annotations etc.`;
422
450
  }
423
451
  }
424
452
 
453
+ private async invokeValidator(
454
+ response: AIResponse,
455
+ validationEventName: string
456
+ ): Promise<Instance> {
457
+ let isstr = false;
458
+ try {
459
+ const c = JSON.parse(response.content);
460
+ isstr = isString(c);
461
+ } catch (reason: any) {
462
+ logger.debug(`invokeValidator json/parse - ${reason}`);
463
+ }
464
+ const d = isstr ? `"${escapeSpecialChars(response.content)}"` : response.content;
465
+ const r: Instance = await parseAndEvaluateStatement(`{${validationEventName} {data ${d}}}`);
466
+ return r;
467
+ }
468
+
469
+ private async handleValidation(
470
+ response: AIResponse,
471
+ validationEventName: string,
472
+ msgs: BaseMessage[],
473
+ provider: AgentServiceProvider
474
+ ): Promise<AIResponse> {
475
+ let r: Instance = await this.invokeValidator(response, validationEventName);
476
+ const status = r.lookup('status');
477
+ if (status === 'ok') {
478
+ return response;
479
+ } else {
480
+ if (this.retryObj) {
481
+ let resp = response;
482
+ let attempt = 0;
483
+ let delay = this.retryObj.getNextDelayMs(attempt);
484
+ while (delay) {
485
+ msgs.push(assistantMessage(resp.content));
486
+ const vs = JSON.stringify(r.asSerializableObject());
487
+ msgs.push(
488
+ humanMessage(
489
+ `Validation for your last response failed with this result: \n${vs}\n\nFix the errors.`
490
+ )
491
+ );
492
+ await sleepMilliseconds(delay);
493
+ resp = await provider.invoke(msgs, undefined);
494
+ r = await this.invokeValidator(resp, validationEventName);
495
+ if (r.lookup('status') === 'ok') {
496
+ return resp;
497
+ }
498
+ delay = this.retryObj.getNextDelayMs(++attempt);
499
+ }
500
+ throw new Error(
501
+ `Agent ${this.name} failed to generate a valid response after ${attempt} attempts`
502
+ );
503
+ } else {
504
+ return response;
505
+ }
506
+ }
507
+ }
508
+
509
+ private getValidationEvent(): string | undefined {
510
+ if (this.validate) {
511
+ if (isFqName(this.validate)) {
512
+ return this.validate;
513
+ } else {
514
+ return `${this.moduleName}/${this.validate}`;
515
+ }
516
+ }
517
+ return undefined;
518
+ }
519
+
425
520
  private getExternalToolSpecs(): any[] | undefined {
426
521
  let result: any[] | undefined = undefined;
427
522
  if (this.toolsArray) {
@@ -54,7 +54,7 @@ resolver suspensionResolver ["${DefaultModuleName}/activeSuspension"] {
54
54
  }
55
55
 
56
56
  workflow createSuspension {
57
- {suspension
57
+ {suspension
58
58
  {id createSuspension.id
59
59
  continuation createSuspension.continuation,
60
60
  env createSuspension.env,
@@ -64,6 +64,15 @@ workflow createSuspension {
64
64
  @public workflow restartSuspension {
65
65
  await Core.restartSuspension(restartSuspension.id, restartSuspension.data)
66
66
  }
67
+
68
+ record ValidationRequest {
69
+ data Any
70
+ }
71
+
72
+ record ValidationResult {
73
+ status @enum("ok", "error"),
74
+ reason String @optional
75
+ }
67
76
  `;
68
77
 
69
78
  export const CoreModules: string[] = [];
@@ -230,12 +230,10 @@ export function makeCoreModuleName(n: string): string {
230
230
  const InitFunctions: Function[] = [];
231
231
 
232
232
  export function registerInitFunction(f: Function) {
233
-
234
233
  InitFunctions.push(f);
235
234
  }
236
235
 
237
236
  export async function runInitFunctions() {
238
- console.log('Running init functions', InitFunctions.length, InitFunctions);
239
237
  for (let i = 0; i < InitFunctions.length; ++i) {
240
238
  await InitFunctions[i]();
241
239
  }
@@ -1,7 +1,7 @@
1
1
  // Monarch syntax highlighting for the agentlang language.
2
2
  export default {
3
3
  keywords: [
4
- '@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@into','@meta','@oneof','@public','@rbac','@ref','@then','@upsert','@with_unique','agent','allow','and','await','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','true','update','upsert','where','workflow'
4
+ '@actions','@after','@as','@async','@before','@catch','@distinct','@enum','@expr','@from','@into','@meta','@oneof','@public','@rbac','@ref','@then','@upsert','@with_unique','agent','agentlang/retry','allow','and','attempts','await','backoff','between','case','commitTransaction','contains','create','decision','delete','directive','else','entity','error','event','extends','false','flow','for','glossaryEntry','if','import','in','like','module','not','not_found','onSubscription','or','purge','query','read','record','relationship','resolver','return','roles','rollbackTransaction','scenario','startTransaction','subscribe','true','update','upsert','where','workflow'
5
5
  ],
6
6
  operators: [
7
7
  '!=','*','+',',','-','-->','.','/',':',';','<','<=','<>','=','==','>','>=','?','@'
@@ -1,18 +0,0 @@
1
- import { Result, Environment } from '../interpreter.js';
2
- import { ActiveSessionInfo } from '../auth/defs.js';
3
- export declare const CoreFilesModuleName: string;
4
- declare const _default: string;
5
- export default _default;
6
- export declare function createFileRecord(fileInfo: {
7
- filename: string;
8
- originalName: string;
9
- mimetype: string;
10
- size: number;
11
- path: string;
12
- uploadedBy?: string;
13
- }, sessionInfo?: ActiveSessionInfo, callback?: (result: Result) => void, env?: Environment): Promise<Result>;
14
- export declare function findFileByFilename(filename: string, sessionInfo?: ActiveSessionInfo, callback?: (result: Result) => void, env?: Environment): Promise<Result>;
15
- export declare function deleteFileRecord(filename: string, sessionInfo?: ActiveSessionInfo, callback?: (result: Result) => void, env?: Environment): Promise<Result>;
16
- export declare function listAllFiles(sessionInfo?: ActiveSessionInfo, callback?: (result: Result) => void, env?: Environment): Promise<Result>;
17
- export declare function listUserFiles(userId: string, sessionInfo?: ActiveSessionInfo, callback?: (result: Result) => void, env?: Environment): Promise<Result>;
18
- //# sourceMappingURL=files.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/runtime/modules/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAY,MAAM,mBAAmB,CAAC;AAIlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,mBAAmB,QAA8B,CAAC;;AAE/D,wBA2DE;AAEF,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE;IACR,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,WAAW,CAAC,EAAE,iBAAiB,EAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACnC,GAAG,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAqBjB;AAED,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,iBAAiB,EAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACnC,GAAG,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,iBAAiB,EAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACnC,GAAG,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED,wBAAsB,YAAY,CAChC,WAAW,CAAC,EAAE,iBAAiB,EAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACnC,GAAG,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,iBAAiB,EAC/B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACnC,GAAG,CAAC,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAcjB"}
@@ -1,116 +0,0 @@
1
- import { evaluate } from '../interpreter.js';
2
- import { makeCoreModuleName } from '../util.js';
3
- import { makeInstance, objectAsInstanceAttributes } from '../module.js';
4
- import crypto from 'crypto';
5
- export const CoreFilesModuleName = makeCoreModuleName('files');
6
- export default `module ${CoreFilesModuleName}
7
-
8
- entity File {
9
- id String @id,
10
- filename String @unique @indexed,
11
- originalName String @optional,
12
- mimetype String @default("application/octet-stream"),
13
- size Int @optional,
14
- uploadedBy String @optional,
15
- uploadedAt DateTime @default(now()),
16
- path String @optional,
17
- @rbac [(roles: [*], allow: [create])
18
- (allow: [read, delete], where: auth.user = this.uploadedBy)]
19
- }
20
-
21
- workflow CreateFile {
22
- {File {id CreateFile.id,
23
- filename CreateFile.filename,
24
- originalName CreateFile.originalName,
25
- mimetype CreateFile.mimetype,
26
- size CreateFile.size,
27
- uploadedBy CreateFile.uploadedBy,
28
- uploadedAt CreateFile.uploadedAt,
29
- path CreateFile.path},
30
- @upsert}
31
- }
32
-
33
- workflow FindFile {
34
- {File {id? FindFile.id}} @as [file];
35
- file
36
- }
37
-
38
- workflow FindFileByFilename {
39
- {File {filename? FindFileByFilename.filename}} @as [file];
40
- file
41
- }
42
-
43
- workflow ListFiles {
44
- {File? {}}
45
- }
46
-
47
- workflow ListUserFiles {
48
- {File {uploadedBy? ListUserFiles.userId}}
49
- }
50
-
51
- workflow DeleteFile {
52
- delete {File {id? DeleteFile.id}}
53
- }
54
-
55
- workflow DeleteFileByFilename {
56
- delete {File {filename? DeleteFileByFilename.filename}}
57
- }
58
-
59
- workflow UpdateFile {
60
- {File {id? UpdateFile.id,
61
- originalName UpdateFile.originalName,
62
- mimetype UpdateFile.mimetype,
63
- size UpdateFile.size}}
64
- }
65
- `;
66
- export async function createFileRecord(fileInfo, sessionInfo, callback, env) {
67
- let inst = makeInstance(CoreFilesModuleName, 'CreateFile', objectAsInstanceAttributes({
68
- id: crypto.randomUUID(),
69
- filename: fileInfo.filename,
70
- originalName: fileInfo.originalName,
71
- mimetype: fileInfo.mimetype,
72
- size: fileInfo.size,
73
- path: fileInfo.path,
74
- uploadedBy: fileInfo.uploadedBy || '',
75
- uploadedAt: new Date().toISOString(),
76
- }));
77
- if (sessionInfo) {
78
- inst = inst.setAuthContext(sessionInfo);
79
- }
80
- return await evaluate(inst, callback, env);
81
- }
82
- export async function findFileByFilename(filename, sessionInfo, callback, env) {
83
- let inst = makeInstance(CoreFilesModuleName, 'FindFileByFilename', objectAsInstanceAttributes({
84
- filename: filename,
85
- }));
86
- if (sessionInfo) {
87
- inst = inst.setAuthContext(sessionInfo);
88
- }
89
- return await evaluate(inst, callback, env);
90
- }
91
- export async function deleteFileRecord(filename, sessionInfo, callback, env) {
92
- let inst = makeInstance(CoreFilesModuleName, 'DeleteFileByFilename', objectAsInstanceAttributes({
93
- filename: filename,
94
- }));
95
- if (sessionInfo) {
96
- inst = inst.setAuthContext(sessionInfo);
97
- }
98
- return await evaluate(inst, callback, env);
99
- }
100
- export async function listAllFiles(sessionInfo, callback, env) {
101
- let inst = makeInstance(CoreFilesModuleName, 'ListFiles', objectAsInstanceAttributes({}));
102
- if (sessionInfo) {
103
- inst = inst.setAuthContext(sessionInfo);
104
- }
105
- return await evaluate(inst, callback, env);
106
- }
107
- export async function listUserFiles(userId, sessionInfo, callback, env) {
108
- let inst = makeInstance(CoreFilesModuleName, 'ListUserFiles', objectAsInstanceAttributes({
109
- userId: userId,
110
- }));
111
- if (sessionInfo) {
112
- inst = inst.setAuthContext(sessionInfo);
113
- }
114
- return await evaluate(inst, callback, env);
115
- }
116
- //# sourceMappingURL=files.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/runtime/modules/files.ts"],"names":[],"mappings":"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"}