@mondaydotcomorg/atp-runtime 0.17.16 → 0.18.4-rc.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.
@@ -4,16 +4,72 @@
4
4
 
5
5
  export type { RuntimeAPIParam, RuntimeAPIMethod, RuntimeAPIMetadata } from './types.js';
6
6
  export { RuntimeAPI, RuntimeMethod } from './decorators.js';
7
+ export type { RuntimeAPIName } from './generated.js';
7
8
 
8
9
  import type { RuntimeAPIMetadata } from './types.js';
10
+ import type { RuntimeAPIName } from './generated.js';
11
+ import { TYPE_REGISTRY } from './generated.js';
12
+
13
+ interface ClientServices {
14
+ hasLLM: boolean;
15
+ hasApproval: boolean;
16
+ hasEmbedding: boolean;
17
+ hasTools: boolean;
18
+ }
9
19
 
10
20
  /**
11
21
  * Generates TypeScript definitions from runtime API metadata
22
+ * @param apis - Runtime API metadata
23
+ * @param options - Optional filtering options
12
24
  */
13
- export function generateRuntimeTypes(apis: RuntimeAPIMetadata[]): string {
14
- let typescript = '// Runtime SDK\ndeclare const atp: {\n';
25
+ export function generateRuntimeTypes(
26
+ apis: RuntimeAPIMetadata[],
27
+ options?: {
28
+ clientServices?: ClientServices;
29
+ requestedApis?: RuntimeAPIName[];
30
+ }
31
+ ): string {
32
+ let filteredApis = apis;
33
+
34
+ if (options?.requestedApis && options.requestedApis.length > 0) {
35
+ const requestedApis = options.requestedApis.map((api) => apis.find((a) => a.name === api));
36
+ filteredApis = requestedApis.filter((api) => api !== undefined);
37
+ } else if (options?.clientServices) {
38
+ filteredApis = apis.filter((api) => {
39
+ if (api.name === 'llm' && !options.clientServices!.hasLLM) return false;
40
+ if (api.name === 'approval' && !options.clientServices!.hasApproval) return false;
41
+ if (api.name === 'embedding' && !options.clientServices!.hasEmbedding) return false;
42
+ if (api.name === 'progress') return false;
43
+ return true;
44
+ });
45
+ } else {
46
+ filteredApis = apis.filter((api) => api.name === 'cache');
47
+ }
48
+
49
+ let typescript = '// Runtime SDK Type Definitions\n\n';
50
+
51
+ const usedTypes = new Set<string>();
52
+ for (const api of filteredApis) {
53
+ for (const method of api.methods) {
54
+ const allTypes = [method.returns, ...method.params.map((p) => p.type)].join(' ');
55
+ const typeMatches = allTypes.match(/\b[A-Z][a-zA-Z]+\b/g);
56
+ if (typeMatches) {
57
+ typeMatches.forEach((t) => usedTypes.add(t));
58
+ }
59
+ }
60
+ }
61
+
62
+ for (const type of TYPE_REGISTRY) {
63
+ const typeNameMatch = type.definition.match(/(?:interface|type)\s+([A-Z][a-zA-Z]+)/);
64
+ const typeName = typeNameMatch?.[1];
65
+ if (typeName && usedTypes.has(typeName)) {
66
+ typescript += `${type.definition}\n\n`;
67
+ }
68
+ }
69
+
70
+ typescript += '// Runtime SDK\ndeclare const atp: {\n';
15
71
 
16
- for (const api of apis) {
72
+ for (const api of filteredApis) {
17
73
  typescript += ` /**\n`;
18
74
  for (const line of api.description.split('\n')) {
19
75
  typescript += ` * ${line}\n`;
@@ -3,6 +3,8 @@
3
3
  * Each runtime module exports its metadata for the type generator
4
4
  */
5
5
 
6
+ import { RuntimeAPIName } from './generated';
7
+
6
8
  export interface RuntimeAPIParam {
7
9
  name: string;
8
10
  type: string;
@@ -18,7 +20,7 @@ export interface RuntimeAPIMethod {
18
20
  }
19
21
 
20
22
  export interface RuntimeAPIMetadata {
21
- name: string;
23
+ name: RuntimeAPIName;
22
24
  description: string;
23
25
  methods: RuntimeAPIMethod[];
24
26
  }