@23blocks/block-jarvis 3.3.0 → 5.0.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 (122) hide show
  1. package/dist/index.esm.js +1223 -1104
  2. package/dist/src/index.d.ts +1 -1
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/lib/jarvis.block.d.ts +13 -38
  5. package/dist/src/lib/jarvis.block.d.ts.map +1 -1
  6. package/dist/src/lib/mappers/agent-tool-assignment.mapper.d.ts +4 -0
  7. package/dist/src/lib/mappers/agent-tool-assignment.mapper.d.ts.map +1 -0
  8. package/dist/src/lib/mappers/agent-tool.mapper.d.ts +4 -0
  9. package/dist/src/lib/mappers/agent-tool.mapper.d.ts.map +1 -0
  10. package/dist/src/lib/mappers/agent.mapper.d.ts.map +1 -1
  11. package/dist/src/lib/mappers/ai-model.mapper.d.ts.map +1 -1
  12. package/dist/src/lib/mappers/cluster.mapper.d.ts.map +1 -1
  13. package/dist/src/lib/mappers/comment.mapper.d.ts.map +1 -1
  14. package/dist/src/lib/mappers/condition.mapper.d.ts +4 -0
  15. package/dist/src/lib/mappers/condition.mapper.d.ts.map +1 -0
  16. package/dist/src/lib/mappers/conversation.mapper.d.ts.map +1 -1
  17. package/dist/src/lib/mappers/entity.mapper.d.ts.map +1 -1
  18. package/dist/src/lib/mappers/execution.mapper.d.ts.map +1 -1
  19. package/dist/src/lib/mappers/index.d.ts +5 -0
  20. package/dist/src/lib/mappers/index.d.ts.map +1 -1
  21. package/dist/src/lib/mappers/mail-template.mapper.d.ts.map +1 -1
  22. package/dist/src/lib/mappers/prompt.mapper.d.ts.map +1 -1
  23. package/dist/src/lib/mappers/step-transition.mapper.d.ts +4 -0
  24. package/dist/src/lib/mappers/step-transition.mapper.d.ts.map +1 -0
  25. package/dist/src/lib/mappers/tool.mapper.d.ts +4 -0
  26. package/dist/src/lib/mappers/tool.mapper.d.ts.map +1 -0
  27. package/dist/src/lib/mappers/user.mapper.d.ts.map +1 -1
  28. package/dist/src/lib/mappers/utils.d.ts +2 -2
  29. package/dist/src/lib/mappers/utils.d.ts.map +1 -1
  30. package/dist/src/lib/mappers/workflow-instance.mapper.d.ts.map +1 -1
  31. package/dist/src/lib/mappers/workflow-participant.mapper.d.ts.map +1 -1
  32. package/dist/src/lib/mappers/workflow-step.mapper.d.ts.map +1 -1
  33. package/dist/src/lib/mappers/workflow.mapper.d.ts.map +1 -1
  34. package/dist/src/lib/services/agent-runtime.service.d.ts +5 -55
  35. package/dist/src/lib/services/agent-runtime.service.d.ts.map +1 -1
  36. package/dist/src/lib/services/agent-tool-assignments.service.d.ts +13 -0
  37. package/dist/src/lib/services/agent-tool-assignments.service.d.ts.map +1 -0
  38. package/dist/src/lib/services/agent-tools.service.d.ts +13 -0
  39. package/dist/src/lib/services/agent-tools.service.d.ts.map +1 -0
  40. package/dist/src/lib/services/agents.service.d.ts +5 -31
  41. package/dist/src/lib/services/agents.service.d.ts.map +1 -1
  42. package/dist/src/lib/services/ai-models.service.d.ts +1 -20
  43. package/dist/src/lib/services/ai-models.service.d.ts.map +1 -1
  44. package/dist/src/lib/services/clusters.service.d.ts +5 -53
  45. package/dist/src/lib/services/clusters.service.d.ts.map +1 -1
  46. package/dist/src/lib/services/conditions.service.d.ts +13 -0
  47. package/dist/src/lib/services/conditions.service.d.ts.map +1 -0
  48. package/dist/src/lib/services/conversations.service.d.ts +3 -27
  49. package/dist/src/lib/services/conversations.service.d.ts.map +1 -1
  50. package/dist/src/lib/services/entities.service.d.ts +9 -50
  51. package/dist/src/lib/services/entities.service.d.ts.map +1 -1
  52. package/dist/src/lib/services/execution-comments.service.d.ts +1 -30
  53. package/dist/src/lib/services/execution-comments.service.d.ts.map +1 -1
  54. package/dist/src/lib/services/executions.service.d.ts +1 -1
  55. package/dist/src/lib/services/executions.service.d.ts.map +1 -1
  56. package/dist/src/lib/services/index.d.ts +5 -0
  57. package/dist/src/lib/services/index.d.ts.map +1 -1
  58. package/dist/src/lib/services/mail-templates.service.d.ts +3 -35
  59. package/dist/src/lib/services/mail-templates.service.d.ts.map +1 -1
  60. package/dist/src/lib/services/marvin-chat.service.d.ts +1 -1
  61. package/dist/src/lib/services/marvin-chat.service.d.ts.map +1 -1
  62. package/dist/src/lib/services/prompt-comments.service.d.ts +1 -30
  63. package/dist/src/lib/services/prompt-comments.service.d.ts.map +1 -1
  64. package/dist/src/lib/services/prompts.service.d.ts +2 -34
  65. package/dist/src/lib/services/prompts.service.d.ts.map +1 -1
  66. package/dist/src/lib/services/step-transitions.service.d.ts +13 -0
  67. package/dist/src/lib/services/step-transitions.service.d.ts.map +1 -0
  68. package/dist/src/lib/services/tools.service.d.ts +13 -0
  69. package/dist/src/lib/services/tools.service.d.ts.map +1 -0
  70. package/dist/src/lib/services/users.service.d.ts +4 -61
  71. package/dist/src/lib/services/users.service.d.ts.map +1 -1
  72. package/dist/src/lib/services/workflow-instances.service.d.ts +5 -31
  73. package/dist/src/lib/services/workflow-instances.service.d.ts.map +1 -1
  74. package/dist/src/lib/services/workflow-participants.service.d.ts +1 -20
  75. package/dist/src/lib/services/workflow-participants.service.d.ts.map +1 -1
  76. package/dist/src/lib/services/workflow-steps.service.d.ts +1 -22
  77. package/dist/src/lib/services/workflow-steps.service.d.ts.map +1 -1
  78. package/dist/src/lib/services/workflows.service.d.ts +6 -36
  79. package/dist/src/lib/services/workflows.service.d.ts.map +1 -1
  80. package/dist/src/lib/types/agent-runtime.d.ts +35 -47
  81. package/dist/src/lib/types/agent-runtime.d.ts.map +1 -1
  82. package/dist/src/lib/types/agent-tool-assignment.d.ts +30 -0
  83. package/dist/src/lib/types/agent-tool-assignment.d.ts.map +1 -0
  84. package/dist/src/lib/types/agent-tool.d.ts +42 -0
  85. package/dist/src/lib/types/agent-tool.d.ts.map +1 -0
  86. package/dist/src/lib/types/agent.d.ts +83 -51
  87. package/dist/src/lib/types/agent.d.ts.map +1 -1
  88. package/dist/src/lib/types/ai-model.d.ts +17 -23
  89. package/dist/src/lib/types/ai-model.d.ts.map +1 -1
  90. package/dist/src/lib/types/cluster.d.ts +35 -47
  91. package/dist/src/lib/types/cluster.d.ts.map +1 -1
  92. package/dist/src/lib/types/comment.d.ts +42 -39
  93. package/dist/src/lib/types/comment.d.ts.map +1 -1
  94. package/dist/src/lib/types/condition.d.ts +39 -0
  95. package/dist/src/lib/types/condition.d.ts.map +1 -0
  96. package/dist/src/lib/types/conversation.d.ts +9 -10
  97. package/dist/src/lib/types/conversation.d.ts.map +1 -1
  98. package/dist/src/lib/types/entity.d.ts +60 -56
  99. package/dist/src/lib/types/entity.d.ts.map +1 -1
  100. package/dist/src/lib/types/execution.d.ts +7 -6
  101. package/dist/src/lib/types/execution.d.ts.map +1 -1
  102. package/dist/src/lib/types/index.d.ts +5 -0
  103. package/dist/src/lib/types/index.d.ts.map +1 -1
  104. package/dist/src/lib/types/mail-template.d.ts +36 -45
  105. package/dist/src/lib/types/mail-template.d.ts.map +1 -1
  106. package/dist/src/lib/types/prompt.d.ts +24 -125
  107. package/dist/src/lib/types/prompt.d.ts.map +1 -1
  108. package/dist/src/lib/types/step-transition.d.ts +36 -0
  109. package/dist/src/lib/types/step-transition.d.ts.map +1 -0
  110. package/dist/src/lib/types/tool.d.ts +41 -0
  111. package/dist/src/lib/types/tool.d.ts.map +1 -0
  112. package/dist/src/lib/types/user.d.ts +26 -57
  113. package/dist/src/lib/types/user.d.ts.map +1 -1
  114. package/dist/src/lib/types/workflow-instance.d.ts +24 -14
  115. package/dist/src/lib/types/workflow-instance.d.ts.map +1 -1
  116. package/dist/src/lib/types/workflow-participant.d.ts +9 -16
  117. package/dist/src/lib/types/workflow-participant.d.ts.map +1 -1
  118. package/dist/src/lib/types/workflow-step.d.ts +36 -22
  119. package/dist/src/lib/types/workflow-step.d.ts.map +1 -1
  120. package/dist/src/lib/types/workflow.d.ts +25 -42
  121. package/dist/src/lib/types/workflow.d.ts.map +1 -1
  122. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -1,28 +1,29 @@
1
+ import { _ } from '@swc/helpers/_/_extends';
1
2
  import { decodeOne, decodePageResult } from '@23blocks/jsonapi-codec';
2
3
 
3
4
  /**
4
5
  * Parse a string value, returning undefined for empty/undefined
5
6
  */ function parseString(value) {
6
7
  if (value === null || value === undefined) {
7
- return undefined;
8
+ return '';
8
9
  }
9
10
  const str = String(value);
10
- return str.length > 0 ? str : undefined;
11
+ return str.length > 0 ? str : '';
11
12
  }
12
13
  /**
13
14
  * Parse a date value
14
15
  */ function parseDate(value) {
15
16
  if (value === null || value === undefined) {
16
- return undefined;
17
+ return new Date();
17
18
  }
18
19
  if (value instanceof Date) {
19
20
  return value;
20
21
  }
21
22
  if (typeof value === 'string' || typeof value === 'number') {
22
23
  const date = new Date(value);
23
- return isNaN(date.getTime()) ? undefined : date;
24
+ return isNaN(date.getTime()) ? new Date() : date;
24
25
  }
25
- return undefined;
26
+ return new Date();
26
27
  }
27
28
  /**
28
29
  * Parse a boolean value
@@ -35,17 +36,6 @@ import { decodeOne, decodePageResult } from '@23blocks/jsonapi-codec';
35
36
  }
36
37
  return false;
37
38
  }
38
- /**
39
- * Parse an array of strings
40
- */ function parseStringArray(value) {
41
- if (value === null || value === undefined) {
42
- return undefined;
43
- }
44
- if (Array.isArray(value)) {
45
- return value.map(String);
46
- }
47
- return undefined;
48
- }
49
39
  /**
50
40
  * Parse an optional number value
51
41
  */ function parseOptionalNumber(value) {
@@ -64,46 +54,95 @@ import { decodeOne, decodePageResult } from '@23blocks/jsonapi-codec';
64
54
  }
65
55
  return 'active';
66
56
  }
67
- /**
68
- * Parse execution status
69
- */ function parseExecutionStatus(value) {
70
- const status = parseString(value);
71
- if (status === 'pending' || status === 'running' || status === 'completed' || status === 'failed') {
72
- return status;
73
- }
74
- return 'pending';
75
- }
76
- /**
77
- * Parse message role
78
- */ function parseMessageRole(value) {
79
- const role = parseString(value);
80
- if (role === 'user' || role === 'assistant' || role === 'system') {
81
- return role;
82
- }
83
- return 'user';
84
- }
85
57
 
86
58
  const agentMapper = {
87
59
  type: 'Agent',
88
60
  map: (resource)=>({
89
61
  id: resource.id,
90
- uniqueId: parseString(resource.attributes['unique_id']),
91
- createdAt: parseDate(resource.attributes['created_at']) || new Date(),
92
- updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
93
- code: parseString(resource.attributes['code']) || '',
62
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
94
63
  name: parseString(resource.attributes['name']) || '',
95
64
  description: parseString(resource.attributes['description']),
96
- systemPrompt: parseString(resource.attributes['system_prompt']),
65
+ instructions: parseString(resource.attributes['instructions']),
97
66
  model: parseString(resource.attributes['model']),
98
- temperature: parseOptionalNumber(resource.attributes['temperature']),
99
- maxTokens: parseOptionalNumber(resource.attributes['max_tokens']),
100
- tools: parseStringArray(resource.attributes['tools']),
101
- status: parseStatus(resource.attributes['status']),
102
- enabled: parseBoolean(resource.attributes['enabled']),
103
- payload: resource.attributes['payload']
67
+ source: parseString(resource.attributes['source']),
68
+ sourceId: parseString(resource.attributes['source_id']),
69
+ sourceType: parseString(resource.attributes['source_type']),
70
+ sourceAlias: parseString(resource.attributes['source_alias']),
71
+ contentUrl: parseString(resource.attributes['content_url']),
72
+ imageUrl: parseString(resource.attributes['image_url']),
73
+ videoUrl: parseString(resource.attributes['video_url']),
74
+ agentIdentifier: parseString(resource.attributes['agent_identifier']),
75
+ ragEnabled: resource.attributes['rag_enabled'] != null ? parseBoolean(resource.attributes['rag_enabled']) : undefined,
76
+ contextWindow: parseOptionalNumber(resource.attributes['context_window']),
77
+ encryptionKey: parseString(resource.attributes['encryption_key']),
78
+ rateLimitPerHour: parseOptionalNumber(resource.attributes['rate_limit_per_hour']),
79
+ communicationEnabled: resource.attributes['communication_enabled'] != null ? parseBoolean(resource.attributes['communication_enabled']) : undefined,
80
+ email: parseString(resource.attributes['email']),
81
+ emailProcessorUrl: parseString(resource.attributes['email_processor_url']),
82
+ allowedDomains: parseString(resource.attributes['allowed_domains']),
83
+ phoneNumber: parseString(resource.attributes['phone_number']),
84
+ smsProcessorUrl: parseString(resource.attributes['sms_processor_url']),
85
+ integrationServicesEnabled: resource.attributes['integration_services_enabled'] != null ? parseBoolean(resource.attributes['integration_services_enabled']) : undefined,
86
+ webhookUrl: parseString(resource.attributes['webhook_url']),
87
+ webhookSecret: parseString(resource.attributes['webhook_secret']),
88
+ apiUrl: parseString(resource.attributes['api_url']),
89
+ imEnabled: resource.attributes['im_enabled'] != null ? parseBoolean(resource.attributes['im_enabled']) : undefined,
90
+ imAppsConfig: parseString(resource.attributes['im_apps_config']),
91
+ supervisorEnabled: resource.attributes['supervisor_enabled'] != null ? parseBoolean(resource.attributes['supervisor_enabled']) : undefined,
92
+ supervisorEmail: parseString(resource.attributes['supervisor_email']),
93
+ supervisorPhoneNumber: parseString(resource.attributes['supervisor_phone_number']),
94
+ lastActivityAt: parseDate(resource.attributes['last_activity_at']),
95
+ totalMessagesProcessed: parseOptionalNumber(resource.attributes['total_messages_processed']),
96
+ averageResponseTime: parseOptionalNumber(resource.attributes['average_response_time']),
97
+ errorCount: parseOptionalNumber(resource.attributes['error_count']),
98
+ successRate: parseOptionalNumber(resource.attributes['success_rate']),
99
+ status: parseString(resource.attributes['status']) || 'active',
100
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
101
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
102
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
104
103
  })
105
104
  };
106
105
 
106
+ function buildAgentBody(data) {
107
+ const body = {};
108
+ if (data.name) body['name'] = data.name;
109
+ if (data.description) body['description'] = data.description;
110
+ if (data.instructions) body['instructions'] = data.instructions;
111
+ if (data.model) body['model'] = data.model;
112
+ if (data.source) body['source'] = data.source;
113
+ if (data.sourceId) body['source_id'] = data.sourceId;
114
+ if (data.sourceType) body['source_type'] = data.sourceType;
115
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
116
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
117
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
118
+ if (data.videoUrl) body['video_url'] = data.videoUrl;
119
+ if (data.agentIdentifier) body['agent_identifier'] = data.agentIdentifier;
120
+ if (data.ragEnabled !== undefined) body['rag_enabled'] = data.ragEnabled;
121
+ if (data.contextWindow !== undefined) body['context_window'] = data.contextWindow;
122
+ if (data.encryptionKey) body['encryption_key'] = data.encryptionKey;
123
+ if (data.rateLimitPerHour !== undefined) body['rate_limit_per_hour'] = data.rateLimitPerHour;
124
+ if (data.communicationEnabled !== undefined) body['communication_enabled'] = data.communicationEnabled;
125
+ if (data.email) body['email'] = data.email;
126
+ if (data.emailProcessorUrl) body['email_processor_url'] = data.emailProcessorUrl;
127
+ if (data.allowedDomains) body['allowed_domains'] = data.allowedDomains;
128
+ if (data.phoneNumber) body['phone_number'] = data.phoneNumber;
129
+ if (data.smsProcessorUrl) body['sms_processor_url'] = data.smsProcessorUrl;
130
+ if (data.integrationServicesEnabled !== undefined) body['integration_services_enabled'] = data.integrationServicesEnabled;
131
+ if (data.webhookUrl) body['webhook_url'] = data.webhookUrl;
132
+ if (data.webhookSecret) body['webhook_secret'] = data.webhookSecret;
133
+ if (data.apiUrl) body['api_url'] = data.apiUrl;
134
+ if (data.imEnabled !== undefined) body['im_enabled'] = data.imEnabled;
135
+ if (data.imAppsConfig) body['im_apps_config'] = data.imAppsConfig;
136
+ if (data.supervisorEnabled !== undefined) body['supervisor_enabled'] = data.supervisorEnabled;
137
+ if (data.supervisorEmail) body['supervisor_email'] = data.supervisorEmail;
138
+ if (data.supervisorPhoneNumber) body['supervisor_phone_number'] = data.supervisorPhoneNumber;
139
+ if (data.lastActivityAt) body['last_activity_at'] = data.lastActivityAt;
140
+ if (data.totalMessagesProcessed !== undefined) body['total_messages_processed'] = data.totalMessagesProcessed;
141
+ if (data.averageResponseTime !== undefined) body['average_response_time'] = data.averageResponseTime;
142
+ if (data.errorCount !== undefined) body['error_count'] = data.errorCount;
143
+ if (data.successRate !== undefined) body['success_rate'] = data.successRate;
144
+ return body;
145
+ }
107
146
  function createAgentsService(transport, _config) {
108
147
  return {
109
148
  async list (params) {
@@ -124,121 +163,73 @@ function createAgentsService(transport, _config) {
124
163
  },
125
164
  async create (data) {
126
165
  const response = await transport.post('/agents', {
127
- agent: {
128
- code: data.code,
129
- name: data.name,
130
- description: data.description,
131
- system_prompt: data.systemPrompt,
132
- model: data.model,
133
- temperature: data.temperature,
134
- max_tokens: data.maxTokens,
135
- tools: data.tools,
136
- payload: data.payload
137
- }
166
+ agent: buildAgentBody(data)
138
167
  });
139
168
  return decodeOne(response, agentMapper);
140
169
  },
141
170
  async update (uniqueId, data) {
142
171
  const response = await transport.put(`/agents/${uniqueId}`, {
143
- agent: {
144
- name: data.name,
145
- description: data.description,
146
- system_prompt: data.systemPrompt,
147
- model: data.model,
148
- temperature: data.temperature,
149
- max_tokens: data.maxTokens,
150
- tools: data.tools,
151
- enabled: data.enabled,
152
- status: data.status,
153
- payload: data.payload
154
- }
172
+ agent: buildAgentBody(data)
155
173
  });
156
174
  return decodeOne(response, agentMapper);
157
175
  },
158
176
  async delete (uniqueId) {
159
177
  await transport.delete(`/agents/${uniqueId}`);
160
178
  },
161
- async chat (uniqueId, data) {
162
- const response = await transport.post(`/agents/${uniqueId}/chat`, {
163
- message: data.message,
164
- conversation_unique_id: data.conversationUniqueId,
165
- user_unique_id: data.userUniqueId,
166
- payload: data.payload
179
+ async addPrompt (uniqueId, data) {
180
+ const response = await transport.post(`/agents/${uniqueId}/add_prompt`, {
181
+ prompt: {
182
+ unique_id: data.uniqueId
183
+ }
167
184
  });
168
- return {
169
- response: response.response,
170
- conversationUniqueId: response.conversation_unique_id,
171
- executionUniqueId: response.execution_unique_id,
172
- tokens: response.tokens,
173
- cost: response.cost
174
- };
185
+ return decodeOne(response, agentMapper);
175
186
  },
176
- async complete (uniqueId, data) {
177
- const response = await transport.post(`/agents/${uniqueId}/complete`, {
178
- input: data.input,
179
- payload: data.payload
187
+ async addEntity (uniqueId, data) {
188
+ const response = await transport.post(`/agents/${uniqueId}/add_entity`, {
189
+ entity: _({
190
+ entity_unique_id: data.entityUniqueId
191
+ }, data.relationType && {
192
+ relation_type: data.relationType
193
+ })
180
194
  });
181
- return {
182
- output: response.output,
183
- executionUniqueId: response.execution_unique_id,
184
- tokens: response.tokens,
185
- cost: response.cost,
186
- duration: response.duration
187
- };
195
+ return decodeOne(response, agentMapper);
196
+ },
197
+ async removeEntity (uniqueId, data) {
198
+ const response = await transport.post(`/agents/${uniqueId}/remove_entity`, {
199
+ entity: _({
200
+ entity_unique_id: data.entityUniqueId
201
+ }, data.relationType && {
202
+ relation_type: data.relationType
203
+ })
204
+ });
205
+ return decodeOne(response, agentMapper);
188
206
  }
189
207
  };
190
208
  }
191
209
 
192
- function parseTemplateInfo(value) {
193
- if (value && typeof value === 'object') {
194
- const obj = value;
195
- return {
196
- name: parseString(obj['name']),
197
- type: parseString(obj['type']),
198
- description: parseString(obj['description'])
199
- };
200
- }
201
- return undefined;
202
- }
203
210
  const promptMapper = {
204
211
  type: 'Prompt',
205
212
  map: (resource)=>({
206
213
  id: resource.id,
207
- uniqueId: parseString(resource.attributes['unique_id']),
214
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
208
215
  createdAt: parseDate(resource.attributes['created_at']) || new Date(),
209
216
  updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
210
- // Core identifiers
211
217
  promptVersionUniqueId: parseString(resource.attributes['prompt_version_unique_id']),
212
218
  agentUniqueId: parseString(resource.attributes['agent_unique_id']),
213
- // Basic info
214
219
  name: parseString(resource.attributes['name']) || '',
215
- code: parseString(resource.attributes['code']),
216
220
  promptType: parseString(resource.attributes['prompt_type']),
217
221
  abstract: parseString(resource.attributes['abstract']),
218
222
  keywords: parseString(resource.attributes['keywords']),
219
- description: parseString(resource.attributes['description']),
220
- // Content
221
223
  content: parseString(resource.attributes['content']),
222
- template: parseString(resource.attributes['template']),
223
- variables: parseStringArray(resource.attributes['variables']),
224
- // Template system
225
- templateData: resource.attributes['template_data'],
226
- templateSchema: resource.attributes['template_schema'],
227
- templateInfo: parseTemplateInfo(resource.attributes['template_info']),
228
- placeholders: parseStringArray(resource.attributes['placeholders']),
229
- provider: parseString(resource.attributes['provider']),
230
- // Media
231
224
  thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
232
225
  imageUrl: parseString(resource.attributes['image_url']),
233
226
  mediaUrl: parseString(resource.attributes['media_url']),
234
227
  contentUrl: parseString(resource.attributes['content_url']),
235
228
  repoUrl: parseString(resource.attributes['repo_url']),
236
- // Publishing
237
229
  publishAt: parseDate(resource.attributes['publish_at']),
238
230
  publishUntil: parseDate(resource.attributes['publish_until']),
239
231
  isPublic: parseBoolean(resource.attributes['is_public']),
240
232
  source: parseString(resource.attributes['source']),
241
- // AI Model Settings
242
233
  model: parseString(resource.attributes['model']),
243
234
  frequencyPenalty: parseOptionalNumber(resource.attributes['frequency_penalty']),
244
235
  maxTokens: parseOptionalNumber(resource.attributes['max_tokens']),
@@ -247,7 +238,6 @@ const promptMapper = {
247
238
  seed: parseOptionalNumber(resource.attributes['seed']),
248
239
  temperature: parseOptionalNumber(resource.attributes['temperature']),
249
240
  topP: parseOptionalNumber(resource.attributes['top_p']),
250
- // Prompt Components
251
241
  user: parseString(resource.attributes['user']),
252
242
  persona: parseString(resource.attributes['persona']),
253
243
  guidelines: parseString(resource.attributes['guidelines']),
@@ -256,24 +246,58 @@ const promptMapper = {
256
246
  sample: parseString(resource.attributes['sample']),
257
247
  outputTemplate: parseString(resource.attributes['output_template']),
258
248
  safeguard: parseString(resource.attributes['safeguard']),
259
- // Versioning & Status
249
+ promptTemplateId: parseString(resource.attributes['prompt_template_id']),
250
+ templateData: resource.attributes['template_data'],
260
251
  version: parseOptionalNumber(resource.attributes['version']),
261
252
  status: parseStatus(resource.attributes['status']),
262
253
  enabled: parseBoolean(resource.attributes['enabled']),
263
- // Engagement
264
254
  likes: parseOptionalNumber(resource.attributes['likes']),
265
255
  dislikes: parseOptionalNumber(resource.attributes['dislikes']),
266
256
  comments: parseOptionalNumber(resource.attributes['comments']),
267
- // Author info
268
257
  userUniqueId: parseString(resource.attributes['user_unique_id']),
269
258
  userName: parseString(resource.attributes['user_name']),
270
259
  userAlias: parseString(resource.attributes['user_alias']),
271
- userAvatarUrl: parseString(resource.attributes['user_avatar_url']),
272
- // Custom data
273
- payload: resource.attributes['payload']
260
+ userAvatarUrl: parseString(resource.attributes['user_avatar_url'])
274
261
  })
275
262
  };
276
263
 
264
+ function buildPromptBody(data) {
265
+ const body = {};
266
+ if (data.name) body['name'] = data.name;
267
+ if (data.promptType) body['prompt_type'] = data.promptType;
268
+ if (data.abstract) body['abstract'] = data.abstract;
269
+ if (data.keywords) body['keywords'] = data.keywords;
270
+ if (data.content) body['content'] = data.content;
271
+ if (data.thumbnailUrl) body['thumbnail_url'] = data.thumbnailUrl;
272
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
273
+ if (data.mediaUrl) body['media_url'] = data.mediaUrl;
274
+ if (data.publishAt) body['publish_at'] = data.publishAt;
275
+ if (data.publishUntil) body['publish_until'] = data.publishUntil;
276
+ if (data.model) body['model'] = data.model;
277
+ if (data.frequencyPenalty !== undefined) body['frequency_penalty'] = data.frequencyPenalty;
278
+ if (data.maxTokens !== undefined) body['max_tokens'] = data.maxTokens;
279
+ if (data.responses !== undefined) body['responses'] = data.responses;
280
+ if (data.responseFormat) body['response_format'] = data.responseFormat;
281
+ if (data.seed !== undefined) body['seed'] = data.seed;
282
+ if (data.temperature !== undefined) body['temperature'] = data.temperature;
283
+ if (data.topP !== undefined) body['top_p'] = data.topP;
284
+ if (data.user) body['user'] = data.user;
285
+ if (data.persona) body['persona'] = data.persona;
286
+ if (data.guidelines) body['guidelines'] = data.guidelines;
287
+ if (data.actions) body['actions'] = data.actions;
288
+ if (data.references) body['references'] = data.references;
289
+ if (data.sample) body['sample'] = data.sample;
290
+ if (data.outputTemplate) body['output_template'] = data.outputTemplate;
291
+ if (data.safeguard) body['safeguard'] = data.safeguard;
292
+ if (data.promptTemplateId) body['prompt_template_id'] = data.promptTemplateId;
293
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
294
+ if (data.repoUrl) body['repo_url'] = data.repoUrl;
295
+ if (data.status) body['status'] = data.status;
296
+ if (data.isPublic !== undefined) body['is_public'] = data.isPublic;
297
+ if (data.source) body['source'] = data.source;
298
+ if (data.templateData) body['template_data'] = data.templateData;
299
+ return body;
300
+ }
277
301
  function createPromptsService(transport, _config) {
278
302
  return {
279
303
  async list (params) {
@@ -295,39 +319,13 @@ function createPromptsService(transport, _config) {
295
319
  },
296
320
  async create (data) {
297
321
  const response = await transport.post('/prompts', {
298
- prompt: {
299
- agent_unique_id: data.agentUniqueId,
300
- code: data.code,
301
- name: data.name,
302
- description: data.description,
303
- template: data.template,
304
- variables: data.variables,
305
- template_data: data.templateData,
306
- template_schema: data.templateSchema,
307
- template_info: data.templateInfo,
308
- placeholders: data.placeholders,
309
- provider: data.provider,
310
- payload: data.payload
311
- }
322
+ prompt: buildPromptBody(data)
312
323
  });
313
324
  return decodeOne(response, promptMapper);
314
325
  },
315
326
  async update (uniqueId, data) {
316
327
  const response = await transport.put(`/prompts/${uniqueId}`, {
317
- prompt: {
318
- name: data.name,
319
- description: data.description,
320
- template: data.template,
321
- variables: data.variables,
322
- template_data: data.templateData,
323
- template_schema: data.templateSchema,
324
- template_info: data.templateInfo,
325
- placeholders: data.placeholders,
326
- provider: data.provider,
327
- enabled: data.enabled,
328
- status: data.status,
329
- payload: data.payload
330
- }
328
+ prompt: buildPromptBody(data)
331
329
  });
332
330
  return decodeOne(response, promptMapper);
333
331
  },
@@ -337,8 +335,7 @@ function createPromptsService(transport, _config) {
337
335
  async execute (uniqueId, data) {
338
336
  const response = await transport.post(`/prompts/${uniqueId}/execute`, {
339
337
  agent_unique_id: data.agentUniqueId,
340
- variables: data.variables,
341
- payload: data.payload
338
+ variables: data.variables
342
339
  });
343
340
  return {
344
341
  output: response.output,
@@ -348,24 +345,11 @@ function createPromptsService(transport, _config) {
348
345
  duration: response.duration
349
346
  };
350
347
  },
351
- async test (data) {
352
- const response = await transport.post('/prompts/test', {
353
- template: data.template,
354
- variables: data.variables,
355
- agent_unique_id: data.agentUniqueId
356
- });
357
- return {
358
- renderedPrompt: response.rendered_prompt,
359
- isValid: response.is_valid,
360
- errors: response.errors
361
- };
362
- },
363
348
  async render (uniqueId, data) {
364
349
  var _response_data, _response_data1, _response_data_meta, _response_data2, _response_meta, _response_data_meta1, _response_data3, _response_meta1, _response_data_meta2, _response_data4, _response_meta2, _response_data_meta3, _response_data5, _response_meta3;
365
350
  const response = await transport.post(`/prompts/${uniqueId}/render`, {
366
351
  placeholders: data.placeholders
367
352
  });
368
- // Parse JSON:API response - the rendered prompt comes in data.attributes
369
353
  const attributes = ((_response_data = response.data) == null ? void 0 : _response_data.attributes) || response;
370
354
  var _response_data_id;
371
355
  return {
@@ -378,7 +362,6 @@ function createPromptsService(transport, _config) {
378
362
  model: attributes.model,
379
363
  temperature: attributes.temperature,
380
364
  maxTokens: attributes.max_tokens || attributes.maxTokens,
381
- provider: attributes.provider,
382
365
  meta: {
383
366
  placeholdersProvided: ((_response_data2 = response.data) == null ? void 0 : (_response_data_meta = _response_data2.meta) == null ? void 0 : _response_data_meta.placeholders_provided) || ((_response_meta = response.meta) == null ? void 0 : _response_meta.placeholders_provided) || [],
384
367
  placeholdersMissing: ((_response_data3 = response.data) == null ? void 0 : (_response_data_meta1 = _response_data3.meta) == null ? void 0 : _response_data_meta1.placeholders_missing) || ((_response_meta1 = response.meta) == null ? void 0 : _response_meta1.placeholders_missing) || [],
@@ -394,20 +377,90 @@ const workflowMapper = {
394
377
  type: 'Workflow',
395
378
  map: (resource)=>({
396
379
  id: resource.id,
397
- uniqueId: parseString(resource.attributes['unique_id']),
380
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
381
+ name: parseString(resource.attributes['name']) || '',
382
+ description: parseString(resource.attributes['description']),
383
+ source: parseString(resource.attributes['source']),
384
+ sourceId: parseString(resource.attributes['source_id']),
385
+ sourceType: parseString(resource.attributes['source_type']),
386
+ sourceAlias: parseString(resource.attributes['source_alias']),
387
+ contentUrl: parseString(resource.attributes['content_url']),
388
+ imageUrl: parseString(resource.attributes['image_url']),
389
+ videoUrl: parseString(resource.attributes['video_url']),
390
+ status: parseString(resource.attributes['status']) || 'active',
391
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
398
392
  createdAt: parseDate(resource.attributes['created_at']) || new Date(),
399
- updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
400
- code: parseString(resource.attributes['code']) || '',
393
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
394
+ })
395
+ };
396
+
397
+ const workflowStepMapper = {
398
+ type: 'workflow_step',
399
+ map: (resource)=>({
400
+ id: resource.id,
401
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
402
+ workflowUniqueId: parseString(resource.attributes['workflow_unique_id']) || '',
401
403
  name: parseString(resource.attributes['name']) || '',
402
404
  description: parseString(resource.attributes['description']),
403
- steps: resource.attributes['steps'] || [],
404
- triggers: resource.attributes['triggers'],
405
- status: parseStatus(resource.attributes['status']),
406
- enabled: parseBoolean(resource.attributes['enabled']),
407
- payload: resource.attributes['payload']
405
+ source: parseString(resource.attributes['source']),
406
+ sourceId: parseString(resource.attributes['source_id']),
407
+ sourceType: parseString(resource.attributes['source_type']),
408
+ sourceAlias: parseString(resource.attributes['source_alias']),
409
+ order: parseOptionalNumber(resource.attributes['order']),
410
+ stepUrl: parseString(resource.attributes['step_url']),
411
+ stepParams: parseString(resource.attributes['step_params']),
412
+ agentUniqueId: parseString(resource.attributes['agent_unique_id']),
413
+ agentName: parseString(resource.attributes['agent_name']),
414
+ promptUniqueId: parseString(resource.attributes['prompt_unique_id']),
415
+ promptName: parseString(resource.attributes['prompt_name']),
416
+ customPrompt: parseString(resource.attributes['custom_prompt']),
417
+ contentUrl: parseString(resource.attributes['content_url']),
418
+ imageUrl: parseString(resource.attributes['image_url']),
419
+ videoUrl: parseString(resource.attributes['video_url']),
420
+ status: parseString(resource.attributes['status']) || 'active',
421
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
422
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
423
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
408
424
  })
409
425
  };
410
426
 
427
+ function buildWorkflowBody(data) {
428
+ const body = {};
429
+ if (data.name) body['name'] = data.name;
430
+ if (data.description) body['description'] = data.description;
431
+ if (data.source) body['source'] = data.source;
432
+ if (data.sourceId) body['source_id'] = data.sourceId;
433
+ if (data.sourceType) body['source_type'] = data.sourceType;
434
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
435
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
436
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
437
+ if (data.videoUrl) body['video_url'] = data.videoUrl;
438
+ if (data.status) body['status'] = data.status;
439
+ return body;
440
+ }
441
+ function buildStepBody$2(data) {
442
+ const body = {};
443
+ if (data.name) body['name'] = data.name;
444
+ if (data.description) body['description'] = data.description;
445
+ if (data.source) body['source'] = data.source;
446
+ if (data.sourceId) body['source_id'] = data.sourceId;
447
+ if (data.sourceType) body['source_type'] = data.sourceType;
448
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
449
+ if (data.order !== undefined) body['order'] = data.order;
450
+ if (data.stepUrl) body['step_url'] = data.stepUrl;
451
+ if (data.stepParams) body['step_params'] = data.stepParams;
452
+ if (data.agentUniqueId) body['agent_unique_id'] = data.agentUniqueId;
453
+ if (data.agentName) body['agent_name'] = data.agentName;
454
+ if (data.promptUniqueId) body['prompt_unique_id'] = data.promptUniqueId;
455
+ if (data.promptName) body['prompt_name'] = data.promptName;
456
+ if (data.customPrompt) body['custom_prompt'] = data.customPrompt;
457
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
458
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
459
+ if (data.videoUrl) body['video_url'] = data.videoUrl;
460
+ if (data.status) body['status'] = data.status;
461
+ if (data.enabled !== undefined) body['enabled'] = data.enabled;
462
+ return body;
463
+ }
411
464
  function createWorkflowsService(transport, _config) {
412
465
  return {
413
466
  async list (params) {
@@ -428,63 +481,42 @@ function createWorkflowsService(transport, _config) {
428
481
  },
429
482
  async create (data) {
430
483
  const response = await transport.post('/workflows', {
431
- workflow: {
432
- code: data.code,
433
- name: data.name,
434
- description: data.description,
435
- steps: data.steps,
436
- triggers: data.triggers,
437
- payload: data.payload
438
- }
484
+ workflow: buildWorkflowBody(data)
439
485
  });
440
486
  return decodeOne(response, workflowMapper);
441
487
  },
442
488
  async update (uniqueId, data) {
443
489
  const response = await transport.put(`/workflows/${uniqueId}`, {
444
- workflow: {
445
- name: data.name,
446
- description: data.description,
447
- steps: data.steps,
448
- triggers: data.triggers,
449
- enabled: data.enabled,
450
- status: data.status,
451
- payload: data.payload
452
- }
490
+ workflow: buildWorkflowBody(data)
453
491
  });
454
492
  return decodeOne(response, workflowMapper);
455
493
  },
456
494
  async delete (uniqueId) {
457
495
  await transport.delete(`/workflows/${uniqueId}`);
458
496
  },
459
- async run (uniqueId, data) {
460
- const response = await transport.post(`/workflows/${uniqueId}/run`, {
461
- input: data.input,
462
- payload: data.payload
497
+ async addStep (uniqueId, data) {
498
+ const response = await transport.post(`/workflows/${uniqueId}/add_step`, {
499
+ step: buildStepBody$2(data)
463
500
  });
464
- return {
465
- executionUniqueId: response.execution_unique_id,
466
- status: response.status,
467
- output: response.output
468
- };
501
+ return decodeOne(response, workflowStepMapper);
469
502
  },
470
- async pause (uniqueId) {
471
- const response = await transport.post(`/workflows/${uniqueId}/pause`, {});
472
- return decodeOne(response, workflowMapper);
503
+ async updateStep (uniqueId, stepUniqueId, data) {
504
+ const response = await transport.put(`/workflows/${uniqueId}/steps/${stepUniqueId}`, {
505
+ step: buildStepBody$2(data)
506
+ });
507
+ return decodeOne(response, workflowStepMapper);
473
508
  },
474
- async resume (uniqueId) {
475
- const response = await transport.post(`/workflows/${uniqueId}/resume`, {});
476
- return decodeOne(response, workflowMapper);
509
+ async removeStep (uniqueId, stepUniqueId) {
510
+ await transport.delete(`/workflows/${uniqueId}/steps/${stepUniqueId}`);
477
511
  }
478
512
  };
479
513
  }
480
514
 
481
515
  const executionMapper = {
482
- type: 'Execution',
516
+ type: 'execution',
483
517
  map: (resource)=>({
484
518
  id: resource.id,
485
- uniqueId: parseString(resource.attributes['unique_id']),
486
- createdAt: parseDate(resource.attributes['created_at']) || new Date(),
487
- updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
519
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
488
520
  agentUniqueId: parseString(resource.attributes['agent_unique_id']),
489
521
  promptUniqueId: parseString(resource.attributes['prompt_unique_id']),
490
522
  input: parseString(resource.attributes['input']),
@@ -492,10 +524,11 @@ const executionMapper = {
492
524
  tokens: parseOptionalNumber(resource.attributes['tokens']),
493
525
  cost: parseOptionalNumber(resource.attributes['cost']),
494
526
  duration: parseOptionalNumber(resource.attributes['duration']),
495
- status: parseExecutionStatus(resource.attributes['status']),
527
+ status: parseString(resource.attributes['status']) || 'pending',
496
528
  startedAt: parseDate(resource.attributes['started_at']),
497
529
  completedAt: parseDate(resource.attributes['completed_at']),
498
- payload: resource.attributes['payload']
530
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
531
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
499
532
  })
500
533
  };
501
534
 
@@ -548,18 +581,17 @@ function createExecutionsService(transport, _config) {
548
581
  }
549
582
 
550
583
  const conversationMapper = {
551
- type: 'Conversation',
584
+ type: 'conversation',
552
585
  map: (resource)=>({
553
586
  id: resource.id,
554
- uniqueId: parseString(resource.attributes['unique_id']),
555
- createdAt: parseDate(resource.attributes['created_at']) || new Date(),
556
- updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
587
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
557
588
  agentUniqueId: parseString(resource.attributes['agent_unique_id']),
558
589
  userUniqueId: parseString(resource.attributes['user_unique_id']),
559
590
  title: parseString(resource.attributes['title']),
560
591
  messages: parseMessages(resource.attributes['messages']),
561
- status: parseStatus(resource.attributes['status']),
562
- payload: resource.attributes['payload']
592
+ status: parseString(resource.attributes['status']) || 'active',
593
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
594
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
563
595
  })
564
596
  };
565
597
  function parseMessages(value) {
@@ -567,10 +599,9 @@ function parseMessages(value) {
567
599
  return [];
568
600
  }
569
601
  return value.map((msg)=>({
570
- role: parseMessageRole(msg.role),
602
+ role: msg.role || 'user',
571
603
  content: parseString(msg.content) || '',
572
- timestamp: parseDate(msg.timestamp) || new Date(),
573
- payload: msg.payload
604
+ timestamp: parseDate(msg.timestamp) || new Date()
574
605
  }));
575
606
  }
576
607
 
@@ -594,34 +625,33 @@ function createConversationsService(transport, _config) {
594
625
  return decodeOne(response, conversationMapper);
595
626
  },
596
627
  async create (data) {
628
+ const body = {};
629
+ if (data.agentUniqueId) body['agent_unique_id'] = data.agentUniqueId;
630
+ if (data.userUniqueId) body['user_unique_id'] = data.userUniqueId;
631
+ if (data.title) body['title'] = data.title;
597
632
  const response = await transport.post('/conversations', {
598
- conversation: {
599
- agent_unique_id: data.agentUniqueId,
600
- user_unique_id: data.userUniqueId,
601
- title: data.title,
602
- payload: data.payload
603
- }
633
+ conversation: body
604
634
  });
605
635
  return decodeOne(response, conversationMapper);
606
636
  },
607
637
  async sendMessage (uniqueId, data) {
638
+ var _response_message, _response_message1, _response_message2;
639
+ const body = {};
640
+ if (data.message) body['content'] = data.message;
641
+ if (data.role) body['role'] = data.role;
608
642
  const response = await transport.post(`/conversations/${uniqueId}/messages`, {
609
- message: data.message,
610
- role: data.role,
611
- payload: data.payload
643
+ message: body
612
644
  });
613
645
  return {
614
646
  message: {
615
- role: response.message.role,
616
- content: response.message.content,
617
- timestamp: new Date(response.message.timestamp),
618
- payload: response.message.payload
647
+ role: ((_response_message = response.message) == null ? void 0 : _response_message.role) || 'user',
648
+ content: ((_response_message1 = response.message) == null ? void 0 : _response_message1.content) || '',
649
+ timestamp: new Date(((_response_message2 = response.message) == null ? void 0 : _response_message2.timestamp) || Date.now())
619
650
  },
620
651
  response: response.response ? {
621
- role: response.response.role,
622
- content: response.response.content,
623
- timestamp: new Date(response.response.timestamp),
624
- payload: response.response.payload
652
+ role: response.response.role || 'assistant',
653
+ content: response.response.content || '',
654
+ timestamp: new Date(response.response.timestamp || Date.now())
625
655
  } : undefined,
626
656
  executionUniqueId: response.execution_unique_id,
627
657
  tokens: response.tokens,
@@ -649,35 +679,47 @@ function createConversationsService(transport, _config) {
649
679
 
650
680
  const aiModelMapper = {
651
681
  type: 'ai_model',
652
- map: (resource)=>{
653
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13;
654
- return {
682
+ map: (resource)=>({
655
683
  id: resource.id,
656
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
657
- code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
658
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
659
- provider: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['provider'],
660
- modelId: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['model_id'],
661
- description: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['description'],
662
- inputTokenCost: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['input_token_cost'],
663
- outputTokenCost: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['output_token_cost'],
664
- maxTokens: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['max_tokens'],
665
- enabled: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['enabled'],
666
- status: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['status'],
667
- payload: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['payload'],
668
- createdAt: parseDate((_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['created_at']),
669
- updatedAt: parseDate((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['updated_at'])
670
- };
671
- }
684
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
685
+ name: parseString(resource.attributes['name']) || '',
686
+ vendorName: parseString(resource.attributes['vendor_name']),
687
+ vendorUniqueId: parseString(resource.attributes['vendor_unique_id']),
688
+ contentUrl: parseString(resource.attributes['content_url']),
689
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
690
+ imageUrl: parseString(resource.attributes['image_url']),
691
+ videoUrl: parseString(resource.attributes['video_url']),
692
+ inputTokenCost: parseOptionalNumber(resource.attributes['input_token_cost']),
693
+ outputTokenCost: parseOptionalNumber(resource.attributes['output_token_cost']),
694
+ apiUrl: parseString(resource.attributes['api_url']),
695
+ status: parseString(resource.attributes['status']) || 'active',
696
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
697
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
698
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
699
+ })
672
700
  };
673
701
 
702
+ function buildAIModelBody(data) {
703
+ const body = {};
704
+ if (data.name) body['name'] = data.name;
705
+ if (data.vendorName) body['vendor_name'] = data.vendorName;
706
+ if (data.vendorUniqueId) body['vendor_unique_id'] = data.vendorUniqueId;
707
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
708
+ if (data.thumbnailUrl) body['thumbnail_url'] = data.thumbnailUrl;
709
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
710
+ if (data.videoUrl) body['video_url'] = data.videoUrl;
711
+ if (data.inputTokenCost !== undefined) body['input_token_cost'] = data.inputTokenCost;
712
+ if (data.outputTokenCost !== undefined) body['output_token_cost'] = data.outputTokenCost;
713
+ if (data.apiUrl) body['api_url'] = data.apiUrl;
714
+ if (data.status) body['status'] = data.status;
715
+ return body;
716
+ }
674
717
  function createAIModelsService(transport, _config) {
675
718
  return {
676
719
  async list (params) {
677
720
  const queryParams = {};
678
721
  if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
679
722
  if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
680
- if (params == null ? void 0 : params.provider) queryParams['provider'] = params.provider;
681
723
  if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
682
724
  if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
683
725
  if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
@@ -692,32 +734,13 @@ function createAIModelsService(transport, _config) {
692
734
  },
693
735
  async create (data) {
694
736
  const response = await transport.post('/ai_models', {
695
- ai_model: {
696
- code: data.code,
697
- name: data.name,
698
- provider: data.provider,
699
- model_id: data.modelId,
700
- description: data.description,
701
- input_token_cost: data.inputTokenCost,
702
- output_token_cost: data.outputTokenCost,
703
- max_tokens: data.maxTokens,
704
- payload: data.payload
705
- }
737
+ ai_model: buildAIModelBody(data)
706
738
  });
707
739
  return decodeOne(response, aiModelMapper);
708
740
  },
709
741
  async update (uniqueId, data) {
710
742
  const response = await transport.put(`/ai_models/${uniqueId}`, {
711
- ai_model: {
712
- name: data.name,
713
- description: data.description,
714
- input_token_cost: data.inputTokenCost,
715
- output_token_cost: data.outputTokenCost,
716
- max_tokens: data.maxTokens,
717
- enabled: data.enabled,
718
- status: data.status,
719
- payload: data.payload
720
- }
743
+ ai_model: buildAIModelBody(data)
721
744
  });
722
745
  return decodeOne(response, aiModelMapper);
723
746
  },
@@ -729,26 +752,85 @@ function createAIModelsService(transport, _config) {
729
752
 
730
753
  const entityMapper = {
731
754
  type: 'entity',
732
- map: (resource)=>{
733
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10;
734
- return {
755
+ map: (resource)=>({
735
756
  id: resource.id,
736
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
737
- code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
738
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
739
- description: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['description'],
740
- systemPrompt: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['system_prompt'],
741
- model: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['model'],
742
- enabled: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['enabled'],
743
- status: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['status'],
744
- payload: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['payload'],
745
- createdAt: parseDate((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['created_at']),
746
- updatedAt: parseDate((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['updated_at'])
747
- };
748
- }
757
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
758
+ code: parseString(resource.attributes['code']),
759
+ entityType: parseString(resource.attributes['entity_type']),
760
+ entityAlias: parseString(resource.attributes['entity_alias']),
761
+ entitySource: parseString(resource.attributes['entity_source']),
762
+ entityUrl: parseString(resource.attributes['entity_url']),
763
+ content: parseString(resource.attributes['content']),
764
+ stripeId: parseString(resource.attributes['stripe_id']),
765
+ status: parseString(resource.attributes['status']) || 'active',
766
+ timeZone: parseString(resource.attributes['time_zone']),
767
+ preferredLanguage: parseString(resource.attributes['preferred_language']),
768
+ entityAvatarUrl: parseString(resource.attributes['entity_avatar_url']),
769
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
770
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
771
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
772
+ })
749
773
  };
750
774
 
751
- function createEntitiesService(transport, _config) {
775
+ function buildEntityBody(data) {
776
+ const body = {};
777
+ if (data.code) body['code'] = data.code;
778
+ if (data.entityType) body['entity_type'] = data.entityType;
779
+ if (data.entityAlias) body['entity_alias'] = data.entityAlias;
780
+ if (data.entitySource) body['entity_source'] = data.entitySource;
781
+ if (data.entityUrl) body['entity_url'] = data.entityUrl;
782
+ if (data.content) body['content'] = data.content;
783
+ if (data.stripeId) body['stripe_id'] = data.stripeId;
784
+ if (data.status) body['status'] = data.status;
785
+ if (data.timeZone) body['time_zone'] = data.timeZone;
786
+ if (data.preferredLanguage) body['preferred_language'] = data.preferredLanguage;
787
+ if (data.entityAvatarUrl) body['entity_avatar_url'] = data.entityAvatarUrl;
788
+ return body;
789
+ }
790
+ function buildContextBody(data) {
791
+ const body = {};
792
+ if (data.uniqueId) body['unique_id'] = data.uniqueId;
793
+ if (data.name) body['name'] = data.name;
794
+ if (data.reference) body['reference'] = data.reference;
795
+ if (data.source) body['source'] = data.source;
796
+ if (data.sourceId) body['source_id'] = data.sourceId;
797
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
798
+ if (data.sourceType) body['source_type'] = data.sourceType;
799
+ if (data.members) body['members'] = data.members;
800
+ return body;
801
+ }
802
+ function buildMessageBody(data) {
803
+ const body = {};
804
+ if (data.role) body['role'] = data.role;
805
+ if (data.content) body['content'] = data.content;
806
+ if (data.fileIds) body['file_ids'] = data.fileIds;
807
+ if (data.metadata) body['metadata'] = data.metadata;
808
+ if (data.source) body['source'] = data.source;
809
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
810
+ if (data.sourceId) body['source_id'] = data.sourceId;
811
+ if (data.sourceType) body['source_type'] = data.sourceType;
812
+ if (data.sourceEmail) body['source_email'] = data.sourceEmail;
813
+ if (data.sourcePhone) body['source_phone'] = data.sourcePhone;
814
+ if (data.target) body['target'] = data.target;
815
+ if (data.targetAlias) body['target_alias'] = data.targetAlias;
816
+ if (data.targetId) body['target_id'] = data.targetId;
817
+ if (data.targetType) body['target_type'] = data.targetType;
818
+ if (data.targetEmail) body['target_email'] = data.targetEmail;
819
+ if (data.targetPhone) body['target_phone'] = data.targetPhone;
820
+ if (data.targetDeviceId) body['target_device_id'] = data.targetDeviceId;
821
+ if (data.parentId) body['parent_id'] = data.parentId;
822
+ if (data.value) body['value'] = data.value;
823
+ if (data.dataSource) body['data_source'] = data.dataSource;
824
+ if (data.dataSourceAlias) body['data_source_alias'] = data.dataSourceAlias;
825
+ if (data.dataSourceId) body['data_source_id'] = data.dataSourceId;
826
+ if (data.dataSourceType) body['data_source_type'] = data.dataSourceType;
827
+ if (data.contextId) body['context_id'] = data.contextId;
828
+ if (data.notificationContent) body['notification_content'] = data.notificationContent;
829
+ if (data.notificationUrl) body['notification_url'] = data.notificationUrl;
830
+ if (data.additionalData) body['additional_data'] = data.additionalData;
831
+ return body;
832
+ }
833
+ function createEntitiesService(transport, _config, sseUrl) {
752
834
  return {
753
835
  async list (params) {
754
836
  const queryParams = {};
@@ -768,28 +850,13 @@ function createEntitiesService(transport, _config) {
768
850
  },
769
851
  async register (uniqueId, data) {
770
852
  const response = await transport.post(`/entities/${uniqueId}/register`, {
771
- entity: {
772
- code: data == null ? void 0 : data.code,
773
- name: data == null ? void 0 : data.name,
774
- description: data == null ? void 0 : data.description,
775
- system_prompt: data == null ? void 0 : data.systemPrompt,
776
- model: data == null ? void 0 : data.model,
777
- payload: data == null ? void 0 : data.payload
778
- }
853
+ entity: data ? buildEntityBody(data) : {}
779
854
  });
780
855
  return decodeOne(response, entityMapper);
781
856
  },
782
857
  async update (uniqueId, data) {
783
858
  const response = await transport.put(`/entities/${uniqueId}`, {
784
- entity: {
785
- name: data.name,
786
- description: data.description,
787
- system_prompt: data.systemPrompt,
788
- model: data.model,
789
- enabled: data.enabled,
790
- status: data.status,
791
- payload: data.payload
792
- }
859
+ entity: buildEntityBody(data)
793
860
  });
794
861
  return decodeOne(response, entityMapper);
795
862
  },
@@ -797,121 +864,92 @@ function createEntitiesService(transport, _config) {
797
864
  await transport.delete(`/entities/${uniqueId}`);
798
865
  },
799
866
  async addPrompt (uniqueId, promptUniqueId) {
800
- await transport.post(`/entities/${uniqueId}/prompts`, {
801
- prompt_unique_id: promptUniqueId
867
+ await transport.post(`/entities/${uniqueId}/add_prompt`, {
868
+ prompt: {
869
+ unique_id: promptUniqueId
870
+ }
802
871
  });
803
872
  },
804
- async getContext (uniqueId, contextUniqueId) {
805
- const response = await transport.get(`/entities/${uniqueId}/contexts/${contextUniqueId}`);
806
- return {
807
- id: response.id,
808
- uniqueId: response.unique_id,
809
- entityUniqueId: response.entity_unique_id,
810
- messages: (response.messages || []).map((m)=>({
811
- role: m.role,
812
- content: m.content,
813
- timestamp: new Date(m.timestamp),
814
- payload: m.payload
815
- })),
816
- payload: response.payload,
817
- createdAt: new Date(response.created_at),
818
- updatedAt: new Date(response.updated_at)
819
- };
820
- },
821
873
  async createContext (uniqueId, data) {
822
- const response = await transport.post(`/entities/${uniqueId}/contexts`, {
823
- system_prompt: data == null ? void 0 : data.systemPrompt,
824
- payload: data == null ? void 0 : data.payload
874
+ return transport.post(`/entities/${uniqueId}/create_context`, {
875
+ context: data ? buildContextBody(data) : {}
825
876
  });
826
- return {
827
- id: response.id,
828
- uniqueId: response.unique_id,
829
- entityUniqueId: response.entity_unique_id,
830
- messages: [],
831
- payload: response.payload,
832
- createdAt: new Date(response.created_at),
833
- updatedAt: new Date(response.updated_at)
834
- };
835
- },
836
- async getConversation (uniqueId, contextUniqueId) {
837
- const response = await transport.get(`/entities/${uniqueId}/conversations/${contextUniqueId}`);
838
- return {
839
- id: response.id,
840
- uniqueId: response.unique_id,
841
- entityUniqueId: response.entity_unique_id,
842
- messages: (response.messages || []).map((m)=>({
843
- role: m.role,
844
- content: m.content,
845
- timestamp: new Date(m.timestamp),
846
- payload: m.payload
847
- })),
848
- payload: response.payload,
849
- createdAt: new Date(response.created_at),
850
- updatedAt: new Date(response.updated_at)
851
- };
852
877
  },
853
878
  async sendMessage (uniqueId, contextUniqueId, data) {
854
- const response = await transport.post(`/entities/${uniqueId}/contexts/${contextUniqueId}/messages`, {
855
- message: data.message,
856
- payload: data.payload
879
+ return transport.post(`/entities/${uniqueId}/contexts/${contextUniqueId}/send_message`, {
880
+ message: buildMessageBody(data)
857
881
  });
858
- return {
859
- message: {
860
- role: response.message.role,
861
- content: response.message.content,
862
- timestamp: new Date(response.message.timestamp),
863
- payload: response.message.payload
864
- },
865
- response: response.response ? {
866
- role: response.response.role,
867
- content: response.response.content,
868
- timestamp: new Date(response.response.timestamp),
869
- payload: response.response.payload
870
- } : undefined,
871
- tokens: response.tokens,
872
- cost: response.cost
873
- };
874
882
  },
875
- async queryFile (uniqueId, fileUniqueId, data) {
876
- const response = await transport.post(`/entities/${uniqueId}/files/${fileUniqueId}/query`, {
877
- query: data.query,
878
- payload: data.payload
879
- });
880
- return {
881
- answer: response.answer,
882
- sources: response.sources,
883
- tokens: response.tokens,
884
- cost: response.cost
885
- };
883
+ async sendMessageStream (uniqueId, contextUniqueId, data) {
884
+ const response = await transport.post(`/entities/${uniqueId}/contexts/${contextUniqueId}/send_message_stream`, {
885
+ message: buildMessageBody(data)
886
+ }, _({
887
+ responseType: 'stream',
888
+ headers: {
889
+ Accept: 'text/event-stream'
890
+ }
891
+ }, sseUrl ? {
892
+ baseUrl: sseUrl
893
+ } : {}));
894
+ if (response.body) {
895
+ return response.body.pipeThrough(new TextDecoderStream());
896
+ }
897
+ throw new Error('Streaming not supported');
886
898
  }
887
899
  };
888
900
  }
889
901
 
890
902
  const clusterMapper = {
891
903
  type: 'cluster',
892
- map: (resource)=>{
893
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10;
894
- return {
904
+ map: (resource)=>({
895
905
  id: resource.id,
896
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
897
- userUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['user_unique_id'],
898
- code: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['code'],
899
- name: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['name'],
900
- description: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['description'],
901
- members: (((_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['members']) || []).map((m)=>({
902
- entityUniqueId: m.entity_unique_id,
903
- role: m.role,
904
- addedAt: parseDate(m.added_at)
905
- })),
906
- enabled: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['enabled'],
907
- status: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['status'],
908
- payload: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['payload'],
909
- createdAt: parseDate((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['created_at']),
910
- updatedAt: parseDate((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['updated_at'])
911
- };
912
- }
906
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
907
+ name: parseString(resource.attributes['name']) || '',
908
+ reference: parseString(resource.attributes['reference']),
909
+ description: parseString(resource.attributes['description']),
910
+ userUniqueId: parseString(resource.attributes['user_unique_id']),
911
+ abstract: parseString(resource.attributes['abstract']),
912
+ keywords: parseString(resource.attributes['keywords']),
913
+ content: parseString(resource.attributes['content']),
914
+ contentUrl: parseString(resource.attributes['content_url']),
915
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
916
+ imageUrl: parseString(resource.attributes['image_url']),
917
+ mediaUrl: parseString(resource.attributes['media_url']),
918
+ source: parseString(resource.attributes['source']),
919
+ sourceId: parseString(resource.attributes['source_id']),
920
+ sourceType: parseString(resource.attributes['source_type']),
921
+ sourceAlias: parseString(resource.attributes['source_alias']),
922
+ tags: parseString(resource.attributes['tags']),
923
+ members: parseString(resource.attributes['members']),
924
+ status: parseString(resource.attributes['status']) || 'active',
925
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
926
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
927
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
928
+ })
913
929
  };
914
930
 
931
+ function buildClusterBody(data) {
932
+ const body = {};
933
+ if (data.name) body['name'] = data.name;
934
+ if (data.reference) body['reference'] = data.reference;
935
+ if (data.description) body['description'] = data.description;
936
+ if (data.userUniqueId) body['user_unique_id'] = data.userUniqueId;
937
+ if (data.abstract) body['abstract'] = data.abstract;
938
+ if (data.keywords) body['keywords'] = data.keywords;
939
+ if (data.content) body['content'] = data.content;
940
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
941
+ if (data.thumbnailUrl) body['thumbnail_url'] = data.thumbnailUrl;
942
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
943
+ if (data.mediaUrl) body['media_url'] = data.mediaUrl;
944
+ if (data.source) body['source'] = data.source;
945
+ if (data.sourceId) body['source_id'] = data.sourceId;
946
+ if (data.sourceType) body['source_type'] = data.sourceType;
947
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
948
+ if (data.tags) body['tags'] = data.tags;
949
+ if (data.members) body['members'] = data.members;
950
+ if (data.status) body['status'] = data.status;
951
+ return body;
952
+ }
915
953
  function createClustersService(transport, _config) {
916
954
  return {
917
955
  async list (userUniqueId, params) {
@@ -932,134 +970,80 @@ function createClustersService(transport, _config) {
932
970
  },
933
971
  async create (userUniqueId, data) {
934
972
  const response = await transport.post(`/users/${userUniqueId}/clusters`, {
935
- cluster: {
936
- code: data.code,
937
- name: data.name,
938
- description: data.description,
939
- payload: data.payload
940
- }
973
+ cluster: buildClusterBody(data)
941
974
  });
942
975
  return decodeOne(response, clusterMapper);
943
976
  },
944
977
  async update (userUniqueId, uniqueId, data) {
945
978
  const response = await transport.put(`/users/${userUniqueId}/clusters/${uniqueId}`, {
946
- cluster: {
947
- name: data.name,
948
- description: data.description,
949
- enabled: data.enabled,
950
- status: data.status,
951
- payload: data.payload
952
- }
979
+ cluster: buildClusterBody(data)
953
980
  });
954
981
  return decodeOne(response, clusterMapper);
955
982
  },
956
983
  async delete (userUniqueId, uniqueId) {
957
984
  await transport.delete(`/users/${userUniqueId}/clusters/${uniqueId}`);
958
985
  },
959
- async addMember (userUniqueId, uniqueId, entityUniqueId) {
960
- await transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/entities/${entityUniqueId}`, {});
961
- },
962
- async removeMember (userUniqueId, uniqueId, entityUniqueId) {
963
- await transport.delete(`/users/${userUniqueId}/clusters/${uniqueId}/entities/${entityUniqueId}`);
964
- },
965
986
  async addPrompt (userUniqueId, uniqueId, promptUniqueId) {
966
- await transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/prompts`, {
967
- prompt_unique_id: promptUniqueId
987
+ const response = await transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/prompts`, {
988
+ prompt: {
989
+ unique_id: promptUniqueId
990
+ }
968
991
  });
969
- },
970
- async getContext (userUniqueId, uniqueId, contextUniqueId) {
971
- const response = await transport.get(`/users/${userUniqueId}/clusters/${uniqueId}/contexts/${contextUniqueId}`);
972
- return {
973
- id: response.id,
974
- uniqueId: response.unique_id,
975
- clusterUniqueId: response.cluster_unique_id,
976
- messages: (response.messages || []).map((m)=>({
977
- role: m.role,
978
- content: m.content,
979
- timestamp: new Date(m.timestamp),
980
- payload: m.payload
981
- })),
982
- payload: response.payload,
983
- createdAt: new Date(response.created_at),
984
- updatedAt: new Date(response.updated_at)
985
- };
992
+ return decodeOne(response, clusterMapper);
986
993
  },
987
994
  async createContext (userUniqueId, uniqueId, data) {
988
- const response = await transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/contexts`, {
989
- system_prompt: data == null ? void 0 : data.systemPrompt,
990
- payload: data == null ? void 0 : data.payload
991
- });
992
- return {
993
- id: response.id,
994
- uniqueId: response.unique_id,
995
- clusterUniqueId: response.cluster_unique_id,
996
- messages: [],
997
- payload: response.payload,
998
- createdAt: new Date(response.created_at),
999
- updatedAt: new Date(response.updated_at)
1000
- };
1001
- },
1002
- async getConversation (userUniqueId, uniqueId, contextUniqueId) {
1003
- const response = await transport.get(`/users/${userUniqueId}/clusters/${uniqueId}/conversations/${contextUniqueId}`);
1004
- return {
1005
- id: response.id,
1006
- uniqueId: response.unique_id,
1007
- clusterUniqueId: response.cluster_unique_id,
1008
- messages: (response.messages || []).map((m)=>({
1009
- role: m.role,
1010
- content: m.content,
1011
- timestamp: new Date(m.timestamp),
1012
- payload: m.payload
1013
- })),
1014
- payload: response.payload,
1015
- createdAt: new Date(response.created_at),
1016
- updatedAt: new Date(response.updated_at)
1017
- };
995
+ return transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/contexts`, data ? {
996
+ context: buildContextBody(data)
997
+ } : {});
1018
998
  },
1019
999
  async sendMessage (userUniqueId, uniqueId, contextUniqueId, data) {
1020
- const response = await transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/contexts/${contextUniqueId}/messages`, {
1021
- message: data.message,
1022
- payload: data.payload
1000
+ return transport.post(`/users/${userUniqueId}/clusters/${uniqueId}/contexts/${contextUniqueId}/messages`, {
1001
+ message: buildMessageBody(data)
1023
1002
  });
1024
- return {
1025
- message: {
1026
- role: response.message.role,
1027
- content: response.message.content,
1028
- timestamp: new Date(response.message.timestamp),
1029
- payload: response.message.payload
1030
- },
1031
- response: response.response ? {
1032
- role: response.response.role,
1033
- content: response.response.content,
1034
- timestamp: new Date(response.response.timestamp),
1035
- payload: response.response.payload
1036
- } : undefined,
1037
- tokens: response.tokens,
1038
- cost: response.cost
1039
- };
1040
1003
  }
1041
1004
  };
1042
1005
  }
1043
1006
 
1044
1007
  const jarvisUserMapper = {
1045
1008
  type: 'user',
1046
- map: (resource)=>{
1047
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8;
1048
- return {
1009
+ map: (resource)=>({
1049
1010
  id: resource.id,
1050
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
1051
- email: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['email'],
1052
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
1053
- username: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['username'],
1054
- avatarUrl: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['avatar_url'],
1055
- status: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['status'],
1056
- payload: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['payload'],
1057
- createdAt: parseDate((_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['created_at']),
1058
- updatedAt: parseDate((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['updated_at'])
1059
- };
1060
- }
1011
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1012
+ name: parseString(resource.attributes['name']),
1013
+ firstName: parseString(resource.attributes['first_name']),
1014
+ lastName: parseString(resource.attributes['last_name']),
1015
+ email: parseString(resource.attributes['email']),
1016
+ phone: parseString(resource.attributes['phone']),
1017
+ avatarUrl: parseString(resource.attributes['avatar_url']),
1018
+ roleName: parseString(resource.attributes['role_name']),
1019
+ roleUniqueId: parseString(resource.attributes['role_unique_id']),
1020
+ timeZone: parseString(resource.attributes['time_zone']),
1021
+ preferredLanguage: parseString(resource.attributes['preferred_language']),
1022
+ maxFileSize: parseOptionalNumber(resource.attributes['max_file_size']),
1023
+ maxStorage: parseOptionalNumber(resource.attributes['max_storage']),
1024
+ status: parseString(resource.attributes['status']) || 'active',
1025
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
1026
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1027
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1028
+ })
1061
1029
  };
1062
1030
 
1031
+ function buildUserBody(data) {
1032
+ const body = {};
1033
+ if (data.name) body['name'] = data.name;
1034
+ if (data.firstName) body['first_name'] = data.firstName;
1035
+ if (data.lastName) body['last_name'] = data.lastName;
1036
+ if (data.email) body['email'] = data.email;
1037
+ if (data.phone) body['phone'] = data.phone;
1038
+ if (data.avatarUrl) body['avatar_url'] = data.avatarUrl;
1039
+ if (data.roleName) body['role_name'] = data.roleName;
1040
+ if (data.roleUniqueId) body['role_unique_id'] = data.roleUniqueId;
1041
+ if (data.timeZone) body['time_zone'] = data.timeZone;
1042
+ if (data.preferredLanguage) body['preferred_language'] = data.preferredLanguage;
1043
+ if (data.maxFileSize !== undefined) body['max_file_size'] = data.maxFileSize;
1044
+ if (data.maxStorage !== undefined) body['max_storage'] = data.maxStorage;
1045
+ return body;
1046
+ }
1063
1047
  function createJarvisUsersService(transport, _config) {
1064
1048
  return {
1065
1049
  async list (params) {
@@ -1080,206 +1064,68 @@ function createJarvisUsersService(transport, _config) {
1080
1064
  },
1081
1065
  async register (uniqueId, data) {
1082
1066
  const response = await transport.post(`/identities/${uniqueId}/register`, {
1083
- user: {
1084
- email: data == null ? void 0 : data.email,
1085
- name: data == null ? void 0 : data.name,
1086
- username: data == null ? void 0 : data.username,
1087
- avatar_url: data == null ? void 0 : data.avatarUrl,
1088
- payload: data == null ? void 0 : data.payload
1089
- }
1067
+ user: data ? buildUserBody(data) : {}
1090
1068
  });
1091
1069
  return decodeOne(response, jarvisUserMapper);
1092
1070
  },
1093
1071
  async update (uniqueId, data) {
1094
1072
  const response = await transport.put(`/identities/${uniqueId}`, {
1095
- user: {
1096
- name: data.name,
1097
- username: data.username,
1098
- avatar_url: data.avatarUrl,
1099
- status: data.status,
1100
- payload: data.payload
1101
- }
1073
+ user: buildUserBody(data)
1102
1074
  });
1103
1075
  return decodeOne(response, jarvisUserMapper);
1104
1076
  },
1105
1077
  async addPrompt (uniqueId, promptUniqueId) {
1106
- await transport.post(`/identities/${uniqueId}/prompts`, {
1107
- prompt_unique_id: promptUniqueId
1078
+ await transport.post(`/identities/${uniqueId}/add_prompt`, {
1079
+ prompt: {
1080
+ unique_id: promptUniqueId
1081
+ }
1108
1082
  });
1109
1083
  },
1110
- async getContext (uniqueId, contextUniqueId) {
1111
- const response = await transport.get(`/identities/${uniqueId}/contexts/${contextUniqueId}`);
1112
- return {
1113
- id: response.id,
1114
- uniqueId: response.unique_id,
1115
- userUniqueId: response.user_unique_id,
1116
- messages: (response.messages || []).map((m)=>({
1117
- role: m.role,
1118
- content: m.content,
1119
- timestamp: new Date(m.timestamp),
1120
- payload: m.payload
1121
- })),
1122
- payload: response.payload,
1123
- createdAt: new Date(response.created_at),
1124
- updatedAt: new Date(response.updated_at)
1125
- };
1126
- },
1127
1084
  async createContext (uniqueId, data) {
1128
- const response = await transport.post(`/identities/${uniqueId}/contexts`, {
1129
- system_prompt: data == null ? void 0 : data.systemPrompt,
1130
- payload: data == null ? void 0 : data.payload
1085
+ return transport.post(`/identities/${uniqueId}/create_context`, {
1086
+ context: data ? buildContextBody(data) : {}
1131
1087
  });
1132
- return {
1133
- id: response.id,
1134
- uniqueId: response.unique_id,
1135
- userUniqueId: response.user_unique_id,
1136
- messages: [],
1137
- payload: response.payload,
1138
- createdAt: new Date(response.created_at),
1139
- updatedAt: new Date(response.updated_at)
1140
- };
1141
- },
1142
- async getConversation (uniqueId, contextUniqueId) {
1143
- const response = await transport.get(`/identities/${uniqueId}/conversations/${contextUniqueId}`);
1144
- return {
1145
- id: response.id,
1146
- uniqueId: response.unique_id,
1147
- userUniqueId: response.user_unique_id,
1148
- messages: (response.messages || []).map((m)=>({
1149
- role: m.role,
1150
- content: m.content,
1151
- timestamp: new Date(m.timestamp),
1152
- payload: m.payload
1153
- })),
1154
- payload: response.payload,
1155
- createdAt: new Date(response.created_at),
1156
- updatedAt: new Date(response.updated_at)
1157
- };
1158
1088
  },
1159
1089
  async sendMessage (uniqueId, contextUniqueId, data) {
1160
- const response = await transport.post(`/identities/${uniqueId}/contexts/${contextUniqueId}/messages`, {
1161
- message: data.message,
1162
- payload: data.payload
1090
+ return transport.post(`/identities/${uniqueId}/contexts/${contextUniqueId}/send_message`, {
1091
+ message: buildMessageBody(data)
1163
1092
  });
1164
- return {
1165
- message: {
1166
- role: response.message.role,
1167
- content: response.message.content,
1168
- timestamp: new Date(response.message.timestamp),
1169
- payload: response.message.payload
1170
- },
1171
- response: response.response ? {
1172
- role: response.response.role,
1173
- content: response.response.content,
1174
- timestamp: new Date(response.response.timestamp),
1175
- payload: response.response.payload
1176
- } : undefined,
1177
- tokens: response.tokens,
1178
- cost: response.cost
1179
- };
1180
- },
1181
- async getContentContext (uniqueId, contentIdentityUniqueId, contextUniqueId) {
1182
- const response = await transport.get(`/identities/${uniqueId}/content/${contentIdentityUniqueId}/context/${contextUniqueId}`);
1183
- return {
1184
- id: response.id,
1185
- uniqueId: response.unique_id,
1186
- userUniqueId: response.user_unique_id,
1187
- messages: (response.messages || []).map((m)=>({
1188
- role: m.role,
1189
- content: m.content,
1190
- timestamp: new Date(m.timestamp),
1191
- payload: m.payload
1192
- })),
1193
- payload: response.payload,
1194
- createdAt: new Date(response.created_at),
1195
- updatedAt: new Date(response.updated_at)
1196
- };
1197
- },
1198
- async createContentContext (uniqueId, contentIdentityUniqueId, data) {
1199
- const response = await transport.post(`/identities/${uniqueId}/content/${contentIdentityUniqueId}/context`, {
1200
- system_prompt: data == null ? void 0 : data.systemPrompt,
1201
- payload: data == null ? void 0 : data.payload
1202
- });
1203
- return {
1204
- id: response.id,
1205
- uniqueId: response.unique_id,
1206
- userUniqueId: response.user_unique_id,
1207
- messages: [],
1208
- payload: response.payload,
1209
- createdAt: new Date(response.created_at),
1210
- updatedAt: new Date(response.updated_at)
1211
- };
1212
- },
1213
- async getContentConversation (uniqueId, contentIdentityUniqueId, contextUniqueId) {
1214
- const response = await transport.get(`/identities/${uniqueId}/content/${contentIdentityUniqueId}/conversations/${contextUniqueId}`);
1215
- return {
1216
- id: response.id,
1217
- uniqueId: response.unique_id,
1218
- userUniqueId: response.user_unique_id,
1219
- messages: (response.messages || []).map((m)=>({
1220
- role: m.role,
1221
- content: m.content,
1222
- timestamp: new Date(m.timestamp),
1223
- payload: m.payload
1224
- })),
1225
- payload: response.payload,
1226
- createdAt: new Date(response.created_at),
1227
- updatedAt: new Date(response.updated_at)
1228
- };
1229
- },
1230
- async sendContentMessage (uniqueId, contentIdentityUniqueId, contextUniqueId, data) {
1231
- const response = await transport.post(`/identities/${uniqueId}/content/${contentIdentityUniqueId}/contexts/${contextUniqueId}/messages`, {
1232
- message: data.message,
1233
- payload: data.payload
1234
- });
1235
- return {
1236
- message: {
1237
- role: response.message.role,
1238
- content: response.message.content,
1239
- timestamp: new Date(response.message.timestamp),
1240
- payload: response.message.payload
1241
- },
1242
- response: response.response ? {
1243
- role: response.response.role,
1244
- content: response.response.content,
1245
- timestamp: new Date(response.response.timestamp),
1246
- payload: response.response.payload
1247
- } : undefined,
1248
- tokens: response.tokens,
1249
- cost: response.cost
1250
- };
1251
1093
  }
1252
1094
  };
1253
1095
  }
1254
1096
 
1255
1097
  const workflowParticipantMapper = {
1256
1098
  type: 'workflow_participant',
1257
- map: (resource)=>{
1258
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10;
1259
- return {
1099
+ map: (resource)=>({
1260
1100
  id: resource.id,
1261
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
1262
- workflowUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['workflow_unique_id'],
1263
- entityType: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['entity_type'],
1264
- entityUniqueId: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['entity_unique_id'],
1265
- role: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['role'],
1266
- permissions: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['permissions'],
1267
- enabled: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['enabled'],
1268
- status: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['status'],
1269
- payload: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['payload'],
1270
- createdAt: parseDate((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['created_at']),
1271
- updatedAt: parseDate((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['updated_at'])
1272
- };
1273
- }
1101
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1102
+ workflowUniqueId: parseString(resource.attributes['workflow_unique_id']) || '',
1103
+ role: parseString(resource.attributes['role']),
1104
+ roleName: parseString(resource.attributes['role_name']),
1105
+ participantUniqueId: parseString(resource.attributes['participant_unique_id']),
1106
+ participantName: parseString(resource.attributes['participant_name']),
1107
+ status: parseString(resource.attributes['status']) || 'active',
1108
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
1109
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1110
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1111
+ })
1274
1112
  };
1275
1113
 
1114
+ function buildParticipantBody(data) {
1115
+ const body = {};
1116
+ if (data.role) body['role'] = data.role;
1117
+ if (data.roleName) body['role_name'] = data.roleName;
1118
+ if (data.participantUniqueId) body['participant_unique_id'] = data.participantUniqueId;
1119
+ if (data.participantName) body['participant_name'] = data.participantName;
1120
+ if (data.status) body['status'] = data.status;
1121
+ return body;
1122
+ }
1276
1123
  function createWorkflowParticipantsService(transport, _config) {
1277
1124
  return {
1278
1125
  async list (workflowUniqueId, params) {
1279
1126
  const queryParams = {};
1280
1127
  if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
1281
1128
  if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
1282
- if (params == null ? void 0 : params.entityType) queryParams['entity_type'] = params.entityType;
1283
1129
  if (params == null ? void 0 : params.role) queryParams['role'] = params.role;
1284
1130
  if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
1285
1131
  if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
@@ -1294,25 +1140,13 @@ function createWorkflowParticipantsService(transport, _config) {
1294
1140
  },
1295
1141
  async add (workflowUniqueId, data) {
1296
1142
  const response = await transport.post(`/workflows/${workflowUniqueId}/participants`, {
1297
- participant: {
1298
- entity_type: data.entityType,
1299
- entity_unique_id: data.entityUniqueId,
1300
- role: data.role,
1301
- permissions: data.permissions,
1302
- payload: data.payload
1303
- }
1143
+ workflow_participant: buildParticipantBody(data)
1304
1144
  });
1305
1145
  return decodeOne(response, workflowParticipantMapper);
1306
1146
  },
1307
1147
  async update (workflowUniqueId, uniqueId, data) {
1308
1148
  const response = await transport.put(`/workflows/${workflowUniqueId}/participants/${uniqueId}`, {
1309
- participant: {
1310
- role: data.role,
1311
- permissions: data.permissions,
1312
- enabled: data.enabled,
1313
- status: data.status,
1314
- payload: data.payload
1315
- }
1149
+ workflow_participant: buildParticipantBody(data)
1316
1150
  });
1317
1151
  return decodeOne(response, workflowParticipantMapper);
1318
1152
  },
@@ -1322,30 +1156,29 @@ function createWorkflowParticipantsService(transport, _config) {
1322
1156
  };
1323
1157
  }
1324
1158
 
1325
- const workflowStepMapper = {
1326
- type: 'workflow_step',
1327
- map: (resource)=>{
1328
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13;
1329
- return {
1330
- id: resource.id,
1331
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
1332
- workflowUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['workflow_unique_id'],
1333
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
1334
- description: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['description'],
1335
- stepType: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['step_type'],
1336
- order: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['order'],
1337
- config: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['config'],
1338
- promptUniqueId: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['prompt_unique_id'],
1339
- agentUniqueId: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['agent_unique_id'],
1340
- enabled: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['enabled'],
1341
- status: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['status'],
1342
- payload: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['payload'],
1343
- createdAt: parseDate((_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['created_at']),
1344
- updatedAt: parseDate((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['updated_at'])
1345
- };
1346
- }
1347
- };
1348
-
1159
+ function buildStepBody$1(data) {
1160
+ const body = {};
1161
+ if (data.name) body['name'] = data.name;
1162
+ if (data.description) body['description'] = data.description;
1163
+ if (data.source) body['source'] = data.source;
1164
+ if (data.sourceId) body['source_id'] = data.sourceId;
1165
+ if (data.sourceType) body['source_type'] = data.sourceType;
1166
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
1167
+ if (data.order !== undefined) body['order'] = data.order;
1168
+ if (data.stepUrl) body['step_url'] = data.stepUrl;
1169
+ if (data.stepParams) body['step_params'] = data.stepParams;
1170
+ if (data.agentUniqueId) body['agent_unique_id'] = data.agentUniqueId;
1171
+ if (data.agentName) body['agent_name'] = data.agentName;
1172
+ if (data.promptUniqueId) body['prompt_unique_id'] = data.promptUniqueId;
1173
+ if (data.promptName) body['prompt_name'] = data.promptName;
1174
+ if (data.customPrompt) body['custom_prompt'] = data.customPrompt;
1175
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
1176
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
1177
+ if (data.videoUrl) body['video_url'] = data.videoUrl;
1178
+ if (data.status) body['status'] = data.status;
1179
+ if (data.enabled !== undefined) body['enabled'] = data.enabled;
1180
+ return body;
1181
+ }
1349
1182
  function createWorkflowStepsService(transport, _config) {
1350
1183
  return {
1351
1184
  async get (workflowUniqueId, stepUniqueId) {
@@ -1353,30 +1186,14 @@ function createWorkflowStepsService(transport, _config) {
1353
1186
  return decodeOne(response, workflowStepMapper);
1354
1187
  },
1355
1188
  async add (workflowUniqueId, data) {
1356
- const response = await transport.put(`/workflows/${workflowUniqueId}/steps`, {
1357
- step: {
1358
- name: data.name,
1359
- description: data.description,
1360
- step_type: data.stepType,
1361
- order: data.order,
1362
- config: data.config,
1363
- payload: data.payload
1364
- }
1189
+ const response = await transport.post(`/workflows/${workflowUniqueId}/steps`, {
1190
+ step: buildStepBody$1(data)
1365
1191
  });
1366
1192
  return decodeOne(response, workflowStepMapper);
1367
1193
  },
1368
1194
  async update (workflowUniqueId, stepUniqueId, data) {
1369
1195
  const response = await transport.put(`/workflows/${workflowUniqueId}/steps/${stepUniqueId}`, {
1370
- step: {
1371
- name: data.name,
1372
- description: data.description,
1373
- step_type: data.stepType,
1374
- order: data.order,
1375
- config: data.config,
1376
- enabled: data.enabled,
1377
- status: data.status,
1378
- payload: data.payload
1379
- }
1196
+ step: buildStepBody$1(data)
1380
1197
  });
1381
1198
  return decodeOne(response, workflowStepMapper);
1382
1199
  },
@@ -1385,14 +1202,16 @@ function createWorkflowStepsService(transport, _config) {
1385
1202
  },
1386
1203
  async addPrompt (stepUniqueId, data) {
1387
1204
  await transport.post(`/steps/${stepUniqueId}/prompts`, {
1388
- prompt_unique_id: data.promptUniqueId,
1389
- payload: data.payload
1205
+ prompt: {
1206
+ unique_id: data.uniqueId
1207
+ }
1390
1208
  });
1391
1209
  },
1392
1210
  async addAgent (stepUniqueId, data) {
1393
1211
  await transport.post(`/steps/${stepUniqueId}/agents`, {
1394
- agent_unique_id: data.agentUniqueId,
1395
- payload: data.payload
1212
+ agent: {
1213
+ unique_id: data.uniqueId
1214
+ }
1396
1215
  });
1397
1216
  }
1398
1217
  };
@@ -1401,45 +1220,65 @@ function createWorkflowStepsService(transport, _config) {
1401
1220
  const workflowInstanceMapper = {
1402
1221
  type: 'workflow_instance',
1403
1222
  map: (resource)=>{
1404
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13, _resource_attributes14;
1223
+ var _parseOptionalNumber;
1405
1224
  return {
1406
1225
  id: resource.id,
1407
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
1408
- workflowUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['workflow_unique_id'],
1409
- currentStepUniqueId: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['current_step_unique_id'],
1410
- currentStepOrder: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['current_step_order'],
1411
- input: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['input'],
1412
- output: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['output'],
1413
- logs: (((_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['logs']) || []).map((log)=>({
1414
- stepUniqueId: log.step_unique_id,
1415
- stepName: log.step_name,
1416
- status: log.status,
1417
- input: log.input,
1418
- output: log.output,
1419
- startedAt: parseDate(log.started_at),
1420
- completedAt: log.completed_at ? parseDate(log.completed_at) : undefined,
1421
- error: log.error
1422
- })),
1423
- status: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['status'],
1424
- startedAt: ((_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['started_at']) ? parseDate((_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['started_at']) : undefined,
1425
- completedAt: ((_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['completed_at']) ? parseDate((_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['completed_at']) : undefined,
1426
- payload: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['payload'],
1427
- createdAt: parseDate((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['created_at']),
1428
- updatedAt: parseDate((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['updated_at'])
1226
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1227
+ workflowUniqueId: parseString(resource.attributes['workflow_unique_id']) || '',
1228
+ currentStepUniqueId: parseString(resource.attributes['current_step_unique_id']),
1229
+ currentStepOrder: (_parseOptionalNumber = parseOptionalNumber(resource.attributes['current_step_order'])) != null ? _parseOptionalNumber : 0,
1230
+ input: resource.attributes['input'],
1231
+ output: resource.attributes['output'],
1232
+ logs: parseLogs(resource.attributes['logs']),
1233
+ status: parseString(resource.attributes['status']) || 'pending',
1234
+ startedAt: resource.attributes['started_at'] ? parseDate(resource.attributes['started_at']) : undefined,
1235
+ completedAt: resource.attributes['completed_at'] ? parseDate(resource.attributes['completed_at']) : undefined,
1236
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1237
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1429
1238
  };
1430
1239
  }
1431
1240
  };
1241
+ function parseLogs(value) {
1242
+ if (!Array.isArray(value)) return undefined;
1243
+ return value.map((log)=>({
1244
+ stepUniqueId: log.step_unique_id || '',
1245
+ stepName: log.step_name || '',
1246
+ status: log.status || '',
1247
+ input: log.input,
1248
+ output: log.output,
1249
+ startedAt: parseDate(log.started_at) || new Date(),
1250
+ completedAt: log.completed_at ? parseDate(log.completed_at) : undefined,
1251
+ error: log.error
1252
+ }));
1253
+ }
1432
1254
 
1255
+ function buildStepBody(data) {
1256
+ const body = {};
1257
+ if (data.stepUniqueId) body['step_unique_id'] = data.stepUniqueId;
1258
+ if (data.stepParams) body['step_params'] = data.stepParams;
1259
+ if (data.stepStatus) body['step_status'] = data.stepStatus;
1260
+ if (data.source) body['source'] = data.source;
1261
+ if (data.sourceId) body['source_id'] = data.sourceId;
1262
+ if (data.sourceType) body['source_type'] = data.sourceType;
1263
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
1264
+ if (data.redirectUrl) body['redirect_url'] = data.redirectUrl;
1265
+ return body;
1266
+ }
1433
1267
  function createWorkflowInstancesService(transport, _config) {
1434
1268
  return {
1435
1269
  async start (workflowUniqueId, data) {
1436
- const response = await transport.post(`/workflows/${workflowUniqueId}/start`, {
1437
- input: data == null ? void 0 : data.input,
1438
- payload: data == null ? void 0 : data.payload
1439
- });
1440
- return {
1441
- instance: decodeOne(response, workflowInstanceMapper)
1270
+ const body = {};
1271
+ if (data == null ? void 0 : data.userUniqueId) body['user'] = {
1272
+ user_unique_id: data.userUniqueId
1442
1273
  };
1274
+ const dataBody = {};
1275
+ if (data == null ? void 0 : data.source) dataBody['source'] = data.source;
1276
+ if (data == null ? void 0 : data.sourceId) dataBody['source_id'] = data.sourceId;
1277
+ if (data == null ? void 0 : data.sourceType) dataBody['source_type'] = data.sourceType;
1278
+ if (data == null ? void 0 : data.sourceAlias) dataBody['source_alias'] = data.sourceAlias;
1279
+ if (Object.keys(dataBody).length > 0) body['data'] = dataBody;
1280
+ const response = await transport.post(`/workflows/${workflowUniqueId}/start`, body);
1281
+ return decodeOne(response, workflowInstanceMapper);
1443
1282
  },
1444
1283
  async get (workflowUniqueId, instanceUniqueId) {
1445
1284
  const response = await transport.get(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}`);
@@ -1465,22 +1304,34 @@ function createWorkflowInstancesService(transport, _config) {
1465
1304
  };
1466
1305
  },
1467
1306
  async step (workflowUniqueId, instanceUniqueId, data) {
1468
- const response = await transport.put(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}`, {
1469
- input: data == null ? void 0 : data.input,
1470
- payload: data == null ? void 0 : data.payload
1471
- });
1307
+ const response = await transport.put(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}/step`, data ? {
1308
+ step: buildStepBody(data)
1309
+ } : {});
1472
1310
  return decodeOne(response, workflowInstanceMapper);
1473
1311
  },
1474
1312
  async logStep (workflowUniqueId, instanceUniqueId, data) {
1475
- const response = await transport.put(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}/log`, {
1476
- step_unique_id: data.stepUniqueId,
1477
- status: data.status,
1478
- output: data.output,
1479
- error: data.error,
1480
- payload: data.payload
1313
+ const response = await transport.put(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}/log_step`, {
1314
+ step: buildStepBody(data)
1481
1315
  });
1482
1316
  return decodeOne(response, workflowInstanceMapper);
1483
1317
  },
1318
+ async executeStep (workflowUniqueId, instanceUniqueId, data) {
1319
+ const response = await transport.post(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}/execute_step`, (data == null ? void 0 : data.placeholders) ? {
1320
+ execute: {
1321
+ placeholders: data.placeholders
1322
+ }
1323
+ } : {});
1324
+ return decodeOne(response, workflowInstanceMapper);
1325
+ },
1326
+ async executeNextStep (workflowUniqueId, instanceUniqueId, data) {
1327
+ const body = {};
1328
+ if (data == null ? void 0 : data.transitionUniqueId) body['transition_unique_id'] = data.transitionUniqueId;
1329
+ if (data == null ? void 0 : data.placeholders) body['placeholders'] = data.placeholders;
1330
+ const response = await transport.post(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}/execute_next_step`, Object.keys(body).length > 0 ? {
1331
+ execute_next: body
1332
+ } : {});
1333
+ return decodeOne(response, workflowInstanceMapper);
1334
+ },
1484
1335
  async suspend (workflowUniqueId, instanceUniqueId) {
1485
1336
  const response = await transport.put(`/workflows/${workflowUniqueId}/instances/${instanceUniqueId}/suspend`, {});
1486
1337
  return decodeOne(response, workflowInstanceMapper);
@@ -1492,211 +1343,137 @@ function createWorkflowInstancesService(transport, _config) {
1492
1343
  };
1493
1344
  }
1494
1345
 
1495
- function createAgentRuntimeService(transport, _config) {
1346
+ function buildRuntimeMessageBody(data) {
1347
+ const body = {};
1348
+ if (data.role) body['role'] = data.role;
1349
+ if (data.content) body['content'] = data.content;
1350
+ if (data.fileIds) body['file_ids'] = data.fileIds;
1351
+ if (data.metadata) body['metadata'] = data.metadata;
1352
+ if (data.source) body['source'] = data.source;
1353
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
1354
+ if (data.sourceId) body['source_id'] = data.sourceId;
1355
+ if (data.sourceType) body['source_type'] = data.sourceType;
1356
+ if (data.sourceEmail) body['source_email'] = data.sourceEmail;
1357
+ if (data.sourcePhone) body['source_phone'] = data.sourcePhone;
1358
+ if (data.target) body['target'] = data.target;
1359
+ if (data.targetAlias) body['target_alias'] = data.targetAlias;
1360
+ if (data.targetId) body['target_id'] = data.targetId;
1361
+ if (data.targetType) body['target_type'] = data.targetType;
1362
+ if (data.targetEmail) body['target_email'] = data.targetEmail;
1363
+ if (data.targetPhone) body['target_phone'] = data.targetPhone;
1364
+ if (data.targetDeviceId) body['target_device_id'] = data.targetDeviceId;
1365
+ if (data.parentId) body['parent_id'] = data.parentId;
1366
+ if (data.value) body['value'] = data.value;
1367
+ if (data.dataSource) body['data_source'] = data.dataSource;
1368
+ if (data.dataSourceAlias) body['data_source_alias'] = data.dataSourceAlias;
1369
+ if (data.dataSourceId) body['data_source_id'] = data.dataSourceId;
1370
+ if (data.dataSourceType) body['data_source_type'] = data.dataSourceType;
1371
+ if (data.contextId) body['context_id'] = data.contextId;
1372
+ if (data.notificationContent) body['notification_content'] = data.notificationContent;
1373
+ if (data.notificationUrl) body['notification_url'] = data.notificationUrl;
1374
+ if (data.additionalData) body['additional_data'] = data.additionalData;
1375
+ return body;
1376
+ }
1377
+ function parseAgentThread(response) {
1378
+ return {
1379
+ id: response.id,
1380
+ threadId: response.thread_id,
1381
+ agentUniqueId: response.agent_unique_id,
1382
+ contextUniqueId: response.context_unique_id,
1383
+ status: response.status,
1384
+ metadata: response.metadata,
1385
+ createdAt: new Date(response.created_at),
1386
+ updatedAt: new Date(response.updated_at)
1387
+ };
1388
+ }
1389
+ function parseAgentMessage(m) {
1390
+ return {
1391
+ id: m.id,
1392
+ threadId: m.thread_id,
1393
+ role: m.role,
1394
+ content: (m.content || []).map((c)=>({
1395
+ type: c.type,
1396
+ text: c.text,
1397
+ imageFile: c.image_file,
1398
+ imageUrl: c.image_url
1399
+ })),
1400
+ metadata: m.metadata,
1401
+ createdAt: new Date(m.created_at)
1402
+ };
1403
+ }
1404
+ function createAgentRuntimeService(transport, _config, sseUrl) {
1496
1405
  return {
1497
1406
  async getContext (agentUniqueId, contextUniqueId) {
1498
- var _response_thread, _response_thread1, _response_thread2, _response_thread3, _response_thread4, _response_thread5, _response_thread6, _response_thread7;
1499
1407
  const response = await transport.get(`/agents/${agentUniqueId}/context/${contextUniqueId}`);
1500
1408
  return {
1501
- thread: {
1502
- id: (_response_thread = response.thread) == null ? void 0 : _response_thread.id,
1503
- threadId: (_response_thread1 = response.thread) == null ? void 0 : _response_thread1.thread_id,
1504
- agentUniqueId: (_response_thread2 = response.thread) == null ? void 0 : _response_thread2.agent_unique_id,
1505
- contextUniqueId: (_response_thread3 = response.thread) == null ? void 0 : _response_thread3.context_unique_id,
1506
- status: (_response_thread4 = response.thread) == null ? void 0 : _response_thread4.status,
1507
- metadata: (_response_thread5 = response.thread) == null ? void 0 : _response_thread5.metadata,
1508
- createdAt: new Date((_response_thread6 = response.thread) == null ? void 0 : _response_thread6.created_at),
1509
- updatedAt: new Date((_response_thread7 = response.thread) == null ? void 0 : _response_thread7.updated_at)
1510
- },
1409
+ thread: parseAgentThread(response.thread || response),
1511
1410
  conversation: response.conversation ? {
1512
1411
  uniqueId: response.conversation.unique_id,
1513
- messages: (response.conversation.messages || []).map((m)=>({
1514
- id: m.id,
1515
- threadId: m.thread_id,
1516
- role: m.role,
1517
- content: (m.content || []).map((c)=>({
1518
- type: c.type,
1519
- text: c.text,
1520
- imageFile: c.image_file,
1521
- imageUrl: c.image_url
1522
- })),
1523
- metadata: m.metadata,
1524
- createdAt: new Date(m.created_at)
1525
- }))
1412
+ messages: (response.conversation.messages || []).map(parseAgentMessage)
1526
1413
  } : undefined
1527
1414
  };
1528
1415
  },
1529
1416
  async createContext (agentUniqueId, data) {
1530
- var _response_thread, _response_thread1, _response_thread2, _response_thread3, _response_thread4, _response_thread5, _response_thread6, _response_thread7;
1531
- const response = await transport.post(`/agents/${agentUniqueId}/context`, {
1532
- metadata: data == null ? void 0 : data.metadata
1533
- });
1417
+ const response = await transport.post(`/agents/${agentUniqueId}/context`, data ? {
1418
+ context: buildContextBody(data)
1419
+ } : {});
1534
1420
  return {
1535
- thread: {
1536
- id: (_response_thread = response.thread) == null ? void 0 : _response_thread.id,
1537
- threadId: (_response_thread1 = response.thread) == null ? void 0 : _response_thread1.thread_id,
1538
- agentUniqueId: (_response_thread2 = response.thread) == null ? void 0 : _response_thread2.agent_unique_id,
1539
- contextUniqueId: (_response_thread3 = response.thread) == null ? void 0 : _response_thread3.context_unique_id,
1540
- status: (_response_thread4 = response.thread) == null ? void 0 : _response_thread4.status,
1541
- metadata: (_response_thread5 = response.thread) == null ? void 0 : _response_thread5.metadata,
1542
- createdAt: new Date((_response_thread6 = response.thread) == null ? void 0 : _response_thread6.created_at),
1543
- updatedAt: new Date((_response_thread7 = response.thread) == null ? void 0 : _response_thread7.updated_at)
1544
- }
1421
+ thread: parseAgentThread(response.thread || response)
1545
1422
  };
1546
1423
  },
1547
1424
  async getConversation (agentUniqueId, contextUniqueId) {
1548
1425
  const response = await transport.get(`/agents/${agentUniqueId}/conversations/${contextUniqueId}`);
1549
1426
  return {
1550
- messages: (response.messages || []).map((m)=>({
1551
- id: m.id,
1552
- threadId: m.thread_id,
1553
- role: m.role,
1554
- content: (m.content || []).map((c)=>({
1555
- type: c.type,
1556
- text: c.text,
1557
- imageFile: c.image_file,
1558
- imageUrl: c.image_url
1559
- })),
1560
- metadata: m.metadata,
1561
- createdAt: new Date(m.created_at)
1562
- }))
1427
+ messages: (response.messages || []).map(parseAgentMessage)
1563
1428
  };
1564
1429
  },
1565
1430
  async getThread (agentUniqueId, threadId) {
1566
1431
  const response = await transport.get(`/agents/${agentUniqueId}/threads/${threadId}`);
1567
- return {
1568
- id: response.id,
1569
- threadId: response.thread_id,
1570
- agentUniqueId: response.agent_unique_id,
1571
- contextUniqueId: response.context_unique_id,
1572
- status: response.status,
1573
- metadata: response.metadata,
1574
- createdAt: new Date(response.created_at),
1575
- updatedAt: new Date(response.updated_at)
1576
- };
1432
+ return parseAgentThread(response);
1577
1433
  },
1578
1434
  async createThread (agentUniqueId, data) {
1579
- const response = await transport.post(`/agents/${agentUniqueId}/thread`, {
1580
- metadata: data == null ? void 0 : data.metadata
1581
- });
1582
- return {
1583
- id: response.id,
1584
- threadId: response.thread_id,
1585
- agentUniqueId: response.agent_unique_id,
1586
- contextUniqueId: response.context_unique_id,
1587
- status: response.status,
1588
- metadata: response.metadata,
1589
- createdAt: new Date(response.created_at),
1590
- updatedAt: new Date(response.updated_at)
1591
- };
1435
+ const body = {};
1436
+ if (data == null ? void 0 : data.metadata) body['metadata'] = data.metadata;
1437
+ if (data == null ? void 0 : data.fileIds) body['file_ids'] = data.fileIds;
1438
+ const response = await transport.post(`/agents/${agentUniqueId}/thread`, body);
1439
+ return parseAgentThread(response);
1592
1440
  },
1593
1441
  async sendMessage (agentUniqueId, threadId, data) {
1594
- const response = await transport.post(`/agents/${agentUniqueId}/threads/${threadId}/messages`, {
1595
- message: data.message,
1596
- metadata: data.metadata
1597
- });
1598
- return {
1599
- message: {
1600
- id: response.id,
1601
- threadId: response.thread_id,
1602
- role: response.role,
1603
- content: (response.content || []).map((c)=>({
1604
- type: c.type,
1605
- text: c.text,
1606
- imageFile: c.image_file,
1607
- imageUrl: c.image_url
1608
- })),
1609
- metadata: response.metadata,
1610
- createdAt: new Date(response.created_at)
1611
- }
1442
+ const requestBody = {
1443
+ message: buildRuntimeMessageBody(data)
1612
1444
  };
1445
+ if (data.promptUniqueId) {
1446
+ requestBody['prompt'] = {
1447
+ unique_id: data.promptUniqueId
1448
+ };
1449
+ }
1450
+ return transport.post(`/agents/${agentUniqueId}/threads/${threadId}/messages`, requestBody);
1613
1451
  },
1614
1452
  async sendMessageStream (agentUniqueId, threadId, data) {
1615
- const response = await transport.post(`/agents/${agentUniqueId}/threads/${threadId}/messages/stream`, {
1616
- message: data.message,
1617
- metadata: data.metadata
1618
- }, {
1619
- responseType: 'stream'
1620
- });
1453
+ const requestBody = {
1454
+ message: buildRuntimeMessageBody(data)
1455
+ };
1456
+ if (data.promptUniqueId) {
1457
+ requestBody['prompt'] = {
1458
+ unique_id: data.promptUniqueId
1459
+ };
1460
+ }
1461
+ const response = await transport.post(`/agents/${agentUniqueId}/threads/${threadId}/messages/stream`, requestBody, _({
1462
+ responseType: 'stream',
1463
+ headers: {
1464
+ Accept: 'text/event-stream'
1465
+ }
1466
+ }, sseUrl ? {
1467
+ baseUrl: sseUrl
1468
+ } : {}));
1621
1469
  if (response.body) {
1622
1470
  return response.body.pipeThrough(new TextDecoderStream());
1623
1471
  }
1624
1472
  throw new Error('Streaming not supported');
1625
1473
  },
1626
- async runThread (agentUniqueId, threadId, data) {
1627
- const response = await transport.post(`/agents/${agentUniqueId}/threads/${threadId}/runs`, {
1628
- instructions: data == null ? void 0 : data.instructions,
1629
- additional_instructions: data == null ? void 0 : data.additionalInstructions,
1630
- tools: data == null ? void 0 : data.tools,
1631
- metadata: data == null ? void 0 : data.metadata
1632
- });
1633
- return {
1634
- run: {
1635
- id: response.id,
1636
- runId: response.run_id,
1637
- threadId: response.thread_id,
1638
- agentUniqueId: response.agent_unique_id,
1639
- status: response.status,
1640
- model: response.model,
1641
- instructions: response.instructions,
1642
- tools: response.tools,
1643
- startedAt: response.started_at ? new Date(response.started_at) : undefined,
1644
- completedAt: response.completed_at ? new Date(response.completed_at) : undefined,
1645
- failedAt: response.failed_at ? new Date(response.failed_at) : undefined,
1646
- cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
1647
- expiresAt: response.expires_at ? new Date(response.expires_at) : undefined,
1648
- lastError: response.last_error,
1649
- usage: response.usage ? {
1650
- promptTokens: response.usage.prompt_tokens,
1651
- completionTokens: response.usage.completion_tokens,
1652
- totalTokens: response.usage.total_tokens
1653
- } : undefined,
1654
- metadata: response.metadata,
1655
- createdAt: new Date(response.created_at)
1656
- }
1657
- };
1658
- },
1659
- async getRun (agentUniqueId, threadId, runId) {
1660
- const response = await transport.get(`/agents/${agentUniqueId}/threads/${threadId}/runs/${runId}`);
1661
- return {
1662
- id: response.id,
1663
- runId: response.run_id,
1664
- threadId: response.thread_id,
1665
- agentUniqueId: response.agent_unique_id,
1666
- status: response.status,
1667
- model: response.model,
1668
- instructions: response.instructions,
1669
- tools: response.tools,
1670
- startedAt: response.started_at ? new Date(response.started_at) : undefined,
1671
- completedAt: response.completed_at ? new Date(response.completed_at) : undefined,
1672
- failedAt: response.failed_at ? new Date(response.failed_at) : undefined,
1673
- cancelledAt: response.cancelled_at ? new Date(response.cancelled_at) : undefined,
1674
- expiresAt: response.expires_at ? new Date(response.expires_at) : undefined,
1675
- lastError: response.last_error,
1676
- usage: response.usage ? {
1677
- promptTokens: response.usage.prompt_tokens,
1678
- completionTokens: response.usage.completion_tokens,
1679
- totalTokens: response.usage.total_tokens
1680
- } : undefined,
1681
- metadata: response.metadata,
1682
- createdAt: new Date(response.created_at)
1683
- };
1684
- },
1685
1474
  async getMessages (agentUniqueId, threadId) {
1686
1475
  const response = await transport.get(`/agents/${agentUniqueId}/threads/${threadId}/messages`);
1687
- return (response.messages || response || []).map((m)=>({
1688
- id: m.id,
1689
- threadId: m.thread_id,
1690
- role: m.role,
1691
- content: (m.content || []).map((c)=>({
1692
- type: c.type,
1693
- text: c.text,
1694
- imageFile: c.image_file,
1695
- imageUrl: c.image_url
1696
- })),
1697
- metadata: m.metadata,
1698
- createdAt: new Date(m.created_at)
1699
- }));
1476
+ return (response.messages || response || []).map(parseAgentMessage);
1700
1477
  },
1701
1478
  async listExecutions (agentUniqueId, params) {
1702
1479
  var _response_meta, _response_meta1, _response_meta2, _response_meta3;
@@ -1758,28 +1535,59 @@ function createAgentRuntimeService(transport, _config) {
1758
1535
 
1759
1536
  const mailTemplateMapper = {
1760
1537
  type: 'mail_template',
1761
- map: (resource)=>{
1762
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13;
1763
- return {
1538
+ map: (resource)=>({
1764
1539
  id: resource.id,
1765
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
1766
- code: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['code'],
1767
- name: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['name'],
1768
- subject: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['subject'],
1769
- fromEmail: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['from_email'],
1770
- fromName: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['from_name'],
1771
- htmlContent: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['html_content'],
1772
- textContent: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['text_content'],
1773
- mandrillSlug: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['mandrill_slug'],
1774
- enabled: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['enabled'],
1775
- status: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['status'],
1776
- payload: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['payload'],
1777
- createdAt: parseDate((_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['created_at']),
1778
- updatedAt: parseDate((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['updated_at'])
1779
- };
1780
- }
1540
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1541
+ eventName: parseString(resource.attributes['event_name']),
1542
+ name: parseString(resource.attributes['name']) || '',
1543
+ source: parseString(resource.attributes['source']),
1544
+ sourceAlias: parseString(resource.attributes['source_alias']),
1545
+ sourceId: parseString(resource.attributes['source_id']),
1546
+ sourceType: parseString(resource.attributes['source_type']),
1547
+ templateName: parseString(resource.attributes['template_name']),
1548
+ templateHtml: parseString(resource.attributes['template_html']),
1549
+ templateText: parseString(resource.attributes['template_text']),
1550
+ fromDomain: parseString(resource.attributes['from_domain']),
1551
+ fromAddress: parseString(resource.attributes['from_address']),
1552
+ fromName: parseString(resource.attributes['from_name']),
1553
+ fromSubject: parseString(resource.attributes['from_subject']),
1554
+ preferredLanguage: parseString(resource.attributes['preferred_language']),
1555
+ provider: parseString(resource.attributes['provider']),
1556
+ status: parseString(resource.attributes['status']) || 'active',
1557
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
1558
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1559
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1560
+ })
1781
1561
  };
1782
1562
 
1563
+ function buildMailTemplateBody(data) {
1564
+ const body = {};
1565
+ if (data.eventName) body['event_name'] = data.eventName;
1566
+ if (data.name) body['name'] = data.name;
1567
+ if (data.source) body['source'] = data.source;
1568
+ if (data.sourceAlias) body['source_alias'] = data.sourceAlias;
1569
+ if (data.sourceId) body['source_id'] = data.sourceId;
1570
+ if (data.sourceType) body['source_type'] = data.sourceType;
1571
+ if (data.templateName) body['template_name'] = data.templateName;
1572
+ if (data.templateHtml) body['template_html'] = data.templateHtml;
1573
+ if (data.templateText) body['template_text'] = data.templateText;
1574
+ if (data.fromDomain) body['from_domain'] = data.fromDomain;
1575
+ if (data.fromAddress) body['from_address'] = data.fromAddress;
1576
+ if (data.fromName) body['from_name'] = data.fromName;
1577
+ if (data.fromSubject) body['from_subject'] = data.fromSubject;
1578
+ if (data.preferredLanguage) body['preferred_language'] = data.preferredLanguage;
1579
+ if (data.provider) body['provider'] = data.provider;
1580
+ return body;
1581
+ }
1582
+ function buildMandrillBody(data) {
1583
+ const body = {};
1584
+ if (data.fromEmail) body['from_email'] = data.fromEmail;
1585
+ if (data.fromName) body['from_name'] = data.fromName;
1586
+ if (data.fromSubject) body['from_subject'] = data.fromSubject;
1587
+ if (data.templateHtml) body['template_html'] = data.templateHtml;
1588
+ if (data.templateText) body['template_text'] = data.templateText;
1589
+ return body;
1590
+ }
1783
1591
  function createMailTemplatesService(transport, _config) {
1784
1592
  return {
1785
1593
  async list (params) {
@@ -1800,49 +1608,26 @@ function createMailTemplatesService(transport, _config) {
1800
1608
  },
1801
1609
  async create (data) {
1802
1610
  const response = await transport.post('/mailtemplates', {
1803
- mail_template: {
1804
- code: data.code,
1805
- name: data.name,
1806
- subject: data.subject,
1807
- from_email: data.fromEmail,
1808
- from_name: data.fromName,
1809
- html_content: data.htmlContent,
1810
- text_content: data.textContent,
1811
- payload: data.payload
1812
- }
1611
+ mail_template: buildMailTemplateBody(data)
1813
1612
  });
1814
1613
  return decodeOne(response, mailTemplateMapper);
1815
1614
  },
1816
1615
  async update (uniqueId, data) {
1817
1616
  const response = await transport.put(`/mailtemplates/${uniqueId}`, {
1818
- mail_template: {
1819
- name: data.name,
1820
- subject: data.subject,
1821
- from_email: data.fromEmail,
1822
- from_name: data.fromName,
1823
- html_content: data.htmlContent,
1824
- text_content: data.textContent,
1825
- enabled: data.enabled,
1826
- status: data.status,
1827
- payload: data.payload
1828
- }
1617
+ mail_template: buildMailTemplateBody(data)
1829
1618
  });
1830
1619
  return decodeOne(response, mailTemplateMapper);
1831
1620
  },
1832
1621
  async createMandrillTemplate (uniqueId, data) {
1833
- const response = await transport.post(`/mailtemplates/${uniqueId}/mandrill`, {
1834
- slug: data == null ? void 0 : data.slug,
1835
- labels: data == null ? void 0 : data.labels,
1836
- payload: data == null ? void 0 : data.payload
1837
- });
1622
+ const response = await transport.post(`/mailtemplates/${uniqueId}/mandrill`, data ? {
1623
+ mandrill: buildMandrillBody(data)
1624
+ } : {});
1838
1625
  return decodeOne(response, mailTemplateMapper);
1839
1626
  },
1840
1627
  async updateMandrillTemplate (uniqueId, data) {
1841
- const response = await transport.put(`/mailtemplates/${uniqueId}/mandrill`, {
1842
- slug: data == null ? void 0 : data.slug,
1843
- labels: data == null ? void 0 : data.labels,
1844
- payload: data == null ? void 0 : data.payload
1845
- });
1628
+ const response = await transport.put(`/mailtemplates/${uniqueId}/mandrill`, data ? {
1629
+ mandrill: buildMandrillBody(data)
1630
+ } : {});
1846
1631
  return decodeOne(response, mailTemplateMapper);
1847
1632
  },
1848
1633
  async publishMandrill (uniqueId) {
@@ -1850,19 +1635,7 @@ function createMailTemplatesService(transport, _config) {
1850
1635
  return decodeOne(response, mailTemplateMapper);
1851
1636
  },
1852
1637
  async getMandrillStats (uniqueId) {
1853
- const response = await transport.get(`/mailtemplates/${uniqueId}/mandrill/stats`);
1854
- return {
1855
- slug: response.slug,
1856
- sentCount: response.sent_count,
1857
- openCount: response.open_count,
1858
- clickCount: response.click_count,
1859
- hardBounceCount: response.hard_bounce_count,
1860
- softBounceCount: response.soft_bounce_count,
1861
- rejectCount: response.reject_count,
1862
- spamCount: response.spam_count,
1863
- unsubCount: response.unsub_count,
1864
- lastSentAt: response.last_sent_at ? new Date(response.last_sent_at) : undefined
1865
- };
1638
+ return transport.get(`/mailtemplates/${uniqueId}/mandrill/stats`);
1866
1639
  }
1867
1640
  };
1868
1641
  }
@@ -1990,54 +1763,74 @@ function createMarvinChatService(transport, _config) {
1990
1763
 
1991
1764
  const promptCommentMapper = {
1992
1765
  type: 'comment',
1993
- map: (resource)=>{
1994
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13, _resource_attributes14;
1995
- return {
1766
+ map: (resource)=>({
1996
1767
  id: resource.id,
1997
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
1998
- promptUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['prompt_unique_id'],
1999
- parentUniqueId: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['parent_unique_id'],
2000
- userUniqueId: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['user_unique_id'],
2001
- content: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['content'],
2002
- likesCount: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['likes_count'],
2003
- repliesCount: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['replies_count'],
2004
- isLiked: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['is_liked'],
2005
- isFollowed: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['is_followed'],
2006
- isSaved: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['is_saved'],
2007
- enabled: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['enabled'],
2008
- status: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['status'],
2009
- payload: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['payload'],
2010
- createdAt: parseDate((_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['created_at']),
2011
- updatedAt: parseDate((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['updated_at'])
2012
- };
2013
- }
1768
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1769
+ promptUniqueId: parseString(resource.attributes['prompt_unique_id']) || '',
1770
+ parentUniqueId: parseString(resource.attributes['parent_unique_id']),
1771
+ content: parseString(resource.attributes['content']) || '',
1772
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
1773
+ imageUrl: parseString(resource.attributes['image_url']),
1774
+ contentUrl: parseString(resource.attributes['content_url']),
1775
+ mediaUrl: parseString(resource.attributes['media_url']),
1776
+ userUniqueId: parseString(resource.attributes['user_unique_id']),
1777
+ userName: parseString(resource.attributes['user_name']),
1778
+ userAlias: parseString(resource.attributes['user_alias']),
1779
+ userAvatarUrl: parseString(resource.attributes['user_avatar_url']),
1780
+ aiGenerated: resource.attributes['ai_generated'] != null ? parseBoolean(resource.attributes['ai_generated']) : undefined,
1781
+ aiModel: parseString(resource.attributes['ai_model']),
1782
+ likesCount: parseOptionalNumber(resource.attributes['likes_count']),
1783
+ repliesCount: parseOptionalNumber(resource.attributes['replies_count']),
1784
+ status: parseString(resource.attributes['status']) || 'active',
1785
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
1786
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1787
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1788
+ })
2014
1789
  };
2015
1790
  const executionCommentMapper = {
2016
1791
  type: 'execution_comment',
2017
- map: (resource)=>{
2018
- var _resource_attributes, _resource_attributes1, _resource_attributes2, _resource_attributes3, _resource_attributes4, _resource_attributes5, _resource_attributes6, _resource_attributes7, _resource_attributes8, _resource_attributes9, _resource_attributes10, _resource_attributes11, _resource_attributes12, _resource_attributes13, _resource_attributes14, _resource_attributes15;
2019
- return {
1792
+ map: (resource)=>({
2020
1793
  id: resource.id,
2021
- uniqueId: (_resource_attributes = resource.attributes) == null ? void 0 : _resource_attributes['unique_id'],
2022
- promptUniqueId: (_resource_attributes1 = resource.attributes) == null ? void 0 : _resource_attributes1['prompt_unique_id'],
2023
- executionUniqueId: (_resource_attributes2 = resource.attributes) == null ? void 0 : _resource_attributes2['execution_unique_id'],
2024
- parentUniqueId: (_resource_attributes3 = resource.attributes) == null ? void 0 : _resource_attributes3['parent_unique_id'],
2025
- userUniqueId: (_resource_attributes4 = resource.attributes) == null ? void 0 : _resource_attributes4['user_unique_id'],
2026
- content: (_resource_attributes5 = resource.attributes) == null ? void 0 : _resource_attributes5['content'],
2027
- likesCount: (_resource_attributes6 = resource.attributes) == null ? void 0 : _resource_attributes6['likes_count'],
2028
- repliesCount: (_resource_attributes7 = resource.attributes) == null ? void 0 : _resource_attributes7['replies_count'],
2029
- isLiked: (_resource_attributes8 = resource.attributes) == null ? void 0 : _resource_attributes8['is_liked'],
2030
- isFollowed: (_resource_attributes9 = resource.attributes) == null ? void 0 : _resource_attributes9['is_followed'],
2031
- isSaved: (_resource_attributes10 = resource.attributes) == null ? void 0 : _resource_attributes10['is_saved'],
2032
- enabled: (_resource_attributes11 = resource.attributes) == null ? void 0 : _resource_attributes11['enabled'],
2033
- status: (_resource_attributes12 = resource.attributes) == null ? void 0 : _resource_attributes12['status'],
2034
- payload: (_resource_attributes13 = resource.attributes) == null ? void 0 : _resource_attributes13['payload'],
2035
- createdAt: parseDate((_resource_attributes14 = resource.attributes) == null ? void 0 : _resource_attributes14['created_at']),
2036
- updatedAt: parseDate((_resource_attributes15 = resource.attributes) == null ? void 0 : _resource_attributes15['updated_at'])
2037
- };
2038
- }
1794
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1795
+ promptUniqueId: parseString(resource.attributes['prompt_unique_id']) || '',
1796
+ executionUniqueId: parseString(resource.attributes['execution_unique_id']) || '',
1797
+ parentUniqueId: parseString(resource.attributes['parent_unique_id']),
1798
+ content: parseString(resource.attributes['content']) || '',
1799
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
1800
+ imageUrl: parseString(resource.attributes['image_url']),
1801
+ contentUrl: parseString(resource.attributes['content_url']),
1802
+ mediaUrl: parseString(resource.attributes['media_url']),
1803
+ userUniqueId: parseString(resource.attributes['user_unique_id']),
1804
+ userName: parseString(resource.attributes['user_name']),
1805
+ userAlias: parseString(resource.attributes['user_alias']),
1806
+ userAvatarUrl: parseString(resource.attributes['user_avatar_url']),
1807
+ aiGenerated: resource.attributes['ai_generated'] != null ? parseBoolean(resource.attributes['ai_generated']) : undefined,
1808
+ aiModel: parseString(resource.attributes['ai_model']),
1809
+ likesCount: parseOptionalNumber(resource.attributes['likes_count']),
1810
+ repliesCount: parseOptionalNumber(resource.attributes['replies_count']),
1811
+ status: parseString(resource.attributes['status']) || 'active',
1812
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
1813
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1814
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1815
+ })
2039
1816
  };
2040
1817
 
1818
+ function buildCommentBody$1(data) {
1819
+ const body = {};
1820
+ if (data.content) body['content'] = data.content;
1821
+ if (data.thumbnailUrl) body['thumbnail_url'] = data.thumbnailUrl;
1822
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
1823
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
1824
+ if (data.mediaUrl) body['media_url'] = data.mediaUrl;
1825
+ if (data.userUniqueId) body['user_unique_id'] = data.userUniqueId;
1826
+ if (data.userName) body['user_name'] = data.userName;
1827
+ if (data.userAlias) body['user_alias'] = data.userAlias;
1828
+ if (data.userAvatarUrl) body['user_avatar_url'] = data.userAvatarUrl;
1829
+ if (data.status) body['status'] = data.status;
1830
+ if (data.aiGenerated !== undefined) body['ai_generated'] = data.aiGenerated;
1831
+ if (data.aiModel) body['ai_model'] = data.aiModel;
1832
+ return body;
1833
+ }
2041
1834
  function createPromptCommentsService(transport, _config) {
2042
1835
  return {
2043
1836
  async list (promptUniqueId, params) {
@@ -2059,22 +1852,13 @@ function createPromptCommentsService(transport, _config) {
2059
1852
  },
2060
1853
  async create (promptUniqueId, data) {
2061
1854
  const response = await transport.post(`/prompts/${promptUniqueId}/comments`, {
2062
- comment: {
2063
- content: data.content,
2064
- user_unique_id: data.userUniqueId,
2065
- payload: data.payload
2066
- }
1855
+ comment: buildCommentBody$1(data)
2067
1856
  });
2068
1857
  return decodeOne(response, promptCommentMapper);
2069
1858
  },
2070
1859
  async update (promptUniqueId, uniqueId, data) {
2071
1860
  const response = await transport.put(`/prompts/${promptUniqueId}/comments/${uniqueId}`, {
2072
- comment: {
2073
- content: data.content,
2074
- enabled: data.enabled,
2075
- status: data.status,
2076
- payload: data.payload
2077
- }
1861
+ comment: buildCommentBody$1(data)
2078
1862
  });
2079
1863
  return decodeOne(response, promptCommentMapper);
2080
1864
  },
@@ -2089,11 +1873,7 @@ function createPromptCommentsService(transport, _config) {
2089
1873
  },
2090
1874
  async reply (promptUniqueId, uniqueId, data) {
2091
1875
  const response = await transport.post(`/prompts/${promptUniqueId}/comments/${uniqueId}/reply`, {
2092
- comment: {
2093
- content: data.content,
2094
- user_unique_id: data.userUniqueId,
2095
- payload: data.payload
2096
- }
1876
+ comment: buildCommentBody$1(data)
2097
1877
  });
2098
1878
  return decodeOne(response, promptCommentMapper);
2099
1879
  },
@@ -2112,6 +1892,22 @@ function createPromptCommentsService(transport, _config) {
2112
1892
  };
2113
1893
  }
2114
1894
 
1895
+ function buildCommentBody(data) {
1896
+ const body = {};
1897
+ if (data.content) body['content'] = data.content;
1898
+ if (data.thumbnailUrl) body['thumbnail_url'] = data.thumbnailUrl;
1899
+ if (data.imageUrl) body['image_url'] = data.imageUrl;
1900
+ if (data.contentUrl) body['content_url'] = data.contentUrl;
1901
+ if (data.mediaUrl) body['media_url'] = data.mediaUrl;
1902
+ if (data.userUniqueId) body['user_unique_id'] = data.userUniqueId;
1903
+ if (data.userName) body['user_name'] = data.userName;
1904
+ if (data.userAlias) body['user_alias'] = data.userAlias;
1905
+ if (data.userAvatarUrl) body['user_avatar_url'] = data.userAvatarUrl;
1906
+ if (data.status) body['status'] = data.status;
1907
+ if (data.aiGenerated !== undefined) body['ai_generated'] = data.aiGenerated;
1908
+ if (data.aiModel) body['ai_model'] = data.aiModel;
1909
+ return body;
1910
+ }
2115
1911
  function createExecutionCommentsService(transport, _config) {
2116
1912
  return {
2117
1913
  async list (promptUniqueId, executionUniqueId, params) {
@@ -2133,22 +1929,13 @@ function createExecutionCommentsService(transport, _config) {
2133
1929
  },
2134
1930
  async create (promptUniqueId, executionUniqueId, data) {
2135
1931
  const response = await transport.post(`/prompts/${promptUniqueId}/executions/${executionUniqueId}/comments`, {
2136
- comment: {
2137
- content: data.content,
2138
- user_unique_id: data.userUniqueId,
2139
- payload: data.payload
2140
- }
1932
+ comment: buildCommentBody(data)
2141
1933
  });
2142
1934
  return decodeOne(response, executionCommentMapper);
2143
1935
  },
2144
1936
  async update (promptUniqueId, executionUniqueId, uniqueId, data) {
2145
1937
  const response = await transport.put(`/prompts/${promptUniqueId}/executions/${executionUniqueId}/comments/${uniqueId}`, {
2146
- comment: {
2147
- content: data.content,
2148
- enabled: data.enabled,
2149
- status: data.status,
2150
- payload: data.payload
2151
- }
1938
+ comment: buildCommentBody(data)
2152
1939
  });
2153
1940
  return decodeOne(response, executionCommentMapper);
2154
1941
  },
@@ -2163,11 +1950,7 @@ function createExecutionCommentsService(transport, _config) {
2163
1950
  },
2164
1951
  async reply (promptUniqueId, executionUniqueId, uniqueId, data) {
2165
1952
  const response = await transport.post(`/prompts/${promptUniqueId}/executions/${executionUniqueId}/comments/${uniqueId}/reply`, {
2166
- comment: {
2167
- content: data.content,
2168
- user_unique_id: data.userUniqueId,
2169
- payload: data.payload
2170
- }
1953
+ comment: buildCommentBody(data)
2171
1954
  });
2172
1955
  return decodeOne(response, executionCommentMapper);
2173
1956
  },
@@ -2186,15 +1969,346 @@ function createExecutionCommentsService(transport, _config) {
2186
1969
  };
2187
1970
  }
2188
1971
 
2189
- /**
2190
- * Create the Jarvis block.
2191
- *
2192
- * @example
2193
- * ```typescript
2194
- * const block = createJarvisBlock(transport, { appId: 'xxx' });
2195
- * const agents = await block.agents.list({ page: 1 });
2196
- * ```
2197
- */ function createJarvisBlock(transport, config) {
1972
+ const toolMapper = {
1973
+ type: 'tool',
1974
+ map: (resource)=>({
1975
+ id: resource.id,
1976
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
1977
+ name: parseString(resource.attributes['name']) || '',
1978
+ description: parseString(resource.attributes['description']),
1979
+ toolType: parseString(resource.attributes['tool_type']),
1980
+ apiMethod: parseString(resource.attributes['api_method']),
1981
+ apiUrl: parseString(resource.attributes['api_url']),
1982
+ requiresAuth: resource.attributes['requires_auth'] != null ? parseBoolean(resource.attributes['requires_auth']) : undefined,
1983
+ responseMapping: parseString(resource.attributes['response_mapping']),
1984
+ parameters: resource.attributes['parameters'],
1985
+ apiHeaders: resource.attributes['api_headers'],
1986
+ status: parseString(resource.attributes['status']) || 'active',
1987
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
1988
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
1989
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
1990
+ })
1991
+ };
1992
+
1993
+ function buildToolBody(data) {
1994
+ const body = {};
1995
+ if (data.name) body['name'] = data.name;
1996
+ if (data.description) body['description'] = data.description;
1997
+ if (data.toolType) body['tool_type'] = data.toolType;
1998
+ if (data.apiMethod) body['api_method'] = data.apiMethod;
1999
+ if (data.apiUrl) body['api_url'] = data.apiUrl;
2000
+ if (data.requiresAuth !== undefined) body['requires_auth'] = data.requiresAuth;
2001
+ if (data.responseMapping) body['response_mapping'] = data.responseMapping;
2002
+ if (data.parameters) body['parameters'] = data.parameters;
2003
+ if (data.apiHeaders) body['api_headers'] = data.apiHeaders;
2004
+ if (data.status) body['status'] = data.status;
2005
+ if (data.enabled !== undefined) body['enabled'] = data.enabled;
2006
+ return body;
2007
+ }
2008
+ function createToolsService(transport, _config) {
2009
+ return {
2010
+ async list (params) {
2011
+ const queryParams = {};
2012
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
2013
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
2014
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
2015
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
2016
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
2017
+ const response = await transport.get('/tools', {
2018
+ params: queryParams
2019
+ });
2020
+ return decodePageResult(response, toolMapper);
2021
+ },
2022
+ async get (uniqueId) {
2023
+ const response = await transport.get(`/tools/${uniqueId}`);
2024
+ return decodeOne(response, toolMapper);
2025
+ },
2026
+ async create (data) {
2027
+ const response = await transport.post('/tools', {
2028
+ tool: buildToolBody(data)
2029
+ });
2030
+ return decodeOne(response, toolMapper);
2031
+ },
2032
+ async update (uniqueId, data) {
2033
+ const response = await transport.put(`/tools/${uniqueId}`, {
2034
+ tool: buildToolBody(data)
2035
+ });
2036
+ return decodeOne(response, toolMapper);
2037
+ },
2038
+ async delete (uniqueId) {
2039
+ await transport.delete(`/tools/${uniqueId}`);
2040
+ }
2041
+ };
2042
+ }
2043
+
2044
+ const agentToolMapper = {
2045
+ type: 'agent_tool',
2046
+ map: (resource)=>({
2047
+ id: resource.id,
2048
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
2049
+ agentUniqueId: parseString(resource.attributes['agent_unique_id']) || '',
2050
+ name: parseString(resource.attributes['name']) || '',
2051
+ description: parseString(resource.attributes['description']),
2052
+ toolType: parseString(resource.attributes['tool_type']),
2053
+ apiMethod: parseString(resource.attributes['api_method']),
2054
+ apiUrl: parseString(resource.attributes['api_url']),
2055
+ requiresAuth: resource.attributes['requires_auth'] != null ? parseBoolean(resource.attributes['requires_auth']) : undefined,
2056
+ responseMapping: parseString(resource.attributes['response_mapping']),
2057
+ parameters: resource.attributes['parameters'],
2058
+ apiHeaders: resource.attributes['api_headers'],
2059
+ status: parseString(resource.attributes['status']) || 'active',
2060
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
2061
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
2062
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
2063
+ })
2064
+ };
2065
+
2066
+ function buildAgentToolBody(data) {
2067
+ const body = {};
2068
+ if (data.name) body['name'] = data.name;
2069
+ if (data.description) body['description'] = data.description;
2070
+ if (data.toolType) body['tool_type'] = data.toolType;
2071
+ if (data.apiMethod) body['api_method'] = data.apiMethod;
2072
+ if (data.apiUrl) body['api_url'] = data.apiUrl;
2073
+ if (data.requiresAuth !== undefined) body['requires_auth'] = data.requiresAuth;
2074
+ if (data.responseMapping) body['response_mapping'] = data.responseMapping;
2075
+ if (data.parameters) body['parameters'] = data.parameters;
2076
+ if (data.apiHeaders) body['api_headers'] = data.apiHeaders;
2077
+ if (data.status) body['status'] = data.status;
2078
+ if (data.enabled !== undefined) body['enabled'] = data.enabled;
2079
+ return body;
2080
+ }
2081
+ function createAgentToolsService(transport, _config) {
2082
+ return {
2083
+ async list (agentUniqueId, params) {
2084
+ const queryParams = {};
2085
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
2086
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
2087
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
2088
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
2089
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
2090
+ const response = await transport.get(`/agents/${agentUniqueId}/tools`, {
2091
+ params: queryParams
2092
+ });
2093
+ return decodePageResult(response, agentToolMapper);
2094
+ },
2095
+ async get (agentUniqueId, uniqueId) {
2096
+ const response = await transport.get(`/agents/${agentUniqueId}/tools/${uniqueId}`);
2097
+ return decodeOne(response, agentToolMapper);
2098
+ },
2099
+ async create (agentUniqueId, data) {
2100
+ const response = await transport.post(`/agents/${agentUniqueId}/tools`, {
2101
+ agent_tool: buildAgentToolBody(data)
2102
+ });
2103
+ return decodeOne(response, agentToolMapper);
2104
+ },
2105
+ async update (agentUniqueId, uniqueId, data) {
2106
+ const response = await transport.put(`/agents/${agentUniqueId}/tools/${uniqueId}`, {
2107
+ agent_tool: buildAgentToolBody(data)
2108
+ });
2109
+ return decodeOne(response, agentToolMapper);
2110
+ },
2111
+ async delete (agentUniqueId, uniqueId) {
2112
+ await transport.delete(`/agents/${agentUniqueId}/tools/${uniqueId}`);
2113
+ }
2114
+ };
2115
+ }
2116
+
2117
+ const agentToolAssignmentMapper = {
2118
+ type: 'agent_tool_assignment',
2119
+ map: (resource)=>({
2120
+ id: resource.id,
2121
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
2122
+ agentUniqueId: parseString(resource.attributes['agent_unique_id']) || '',
2123
+ toolUniqueId: parseString(resource.attributes['tool_unique_id']) || '',
2124
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
2125
+ priority: parseOptionalNumber(resource.attributes['priority']),
2126
+ status: parseString(resource.attributes['status']) || 'active',
2127
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
2128
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
2129
+ })
2130
+ };
2131
+
2132
+ function createAgentToolAssignmentsService(transport, _config) {
2133
+ return {
2134
+ async list (agentUniqueId, params) {
2135
+ const queryParams = {};
2136
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
2137
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
2138
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
2139
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
2140
+ const response = await transport.get(`/agents/${agentUniqueId}/tool_assignments`, {
2141
+ params: queryParams
2142
+ });
2143
+ return decodePageResult(response, agentToolAssignmentMapper);
2144
+ },
2145
+ async get (agentUniqueId, uniqueId) {
2146
+ const response = await transport.get(`/agents/${agentUniqueId}/tool_assignments/${uniqueId}`);
2147
+ return decodeOne(response, agentToolAssignmentMapper);
2148
+ },
2149
+ async create (agentUniqueId, data) {
2150
+ const body = {};
2151
+ if (data.toolUniqueId) body['tool_unique_id'] = data.toolUniqueId;
2152
+ if (data.enabled !== undefined) body['enabled'] = data.enabled;
2153
+ if (data.priority !== undefined) body['priority'] = data.priority;
2154
+ const response = await transport.post(`/agents/${agentUniqueId}/tool_assignments`, {
2155
+ assignment: body
2156
+ });
2157
+ return decodeOne(response, agentToolAssignmentMapper);
2158
+ },
2159
+ async update (agentUniqueId, uniqueId, data) {
2160
+ const body = {};
2161
+ if (data.enabled !== undefined) body['enabled'] = data.enabled;
2162
+ if (data.priority !== undefined) body['priority'] = data.priority;
2163
+ const response = await transport.put(`/agents/${agentUniqueId}/tool_assignments/${uniqueId}`, {
2164
+ assignment: body
2165
+ });
2166
+ return decodeOne(response, agentToolAssignmentMapper);
2167
+ },
2168
+ async delete (agentUniqueId, uniqueId) {
2169
+ await transport.delete(`/agents/${agentUniqueId}/tool_assignments/${uniqueId}`);
2170
+ }
2171
+ };
2172
+ }
2173
+
2174
+ const conditionMapper = {
2175
+ type: 'condition',
2176
+ map: (resource)=>({
2177
+ id: resource.id,
2178
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
2179
+ name: parseString(resource.attributes['name']) || '',
2180
+ description: parseString(resource.attributes['description']),
2181
+ expressionType: parseString(resource.attributes['expression_type']),
2182
+ promptUniqueId: parseString(resource.attributes['prompt_unique_id']),
2183
+ llmModel: parseString(resource.attributes['llm_model']),
2184
+ llmTemperature: parseOptionalNumber(resource.attributes['llm_temperature']),
2185
+ cacheable: resource.attributes['cacheable'] != null ? parseBoolean(resource.attributes['cacheable']) : undefined,
2186
+ cacheTtlSeconds: parseOptionalNumber(resource.attributes['cache_ttl_seconds']),
2187
+ expression: resource.attributes['expression'],
2188
+ status: parseString(resource.attributes['status']) || 'active',
2189
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
2190
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
2191
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
2192
+ })
2193
+ };
2194
+
2195
+ function buildConditionBody(data) {
2196
+ const body = {};
2197
+ if (data.name) body['name'] = data.name;
2198
+ if (data.description) body['description'] = data.description;
2199
+ if (data.expressionType) body['expression_type'] = data.expressionType;
2200
+ if (data.promptUniqueId) body['prompt_unique_id'] = data.promptUniqueId;
2201
+ if (data.llmModel) body['llm_model'] = data.llmModel;
2202
+ if (data.llmTemperature !== undefined) body['llm_temperature'] = data.llmTemperature;
2203
+ if (data.cacheable !== undefined) body['cacheable'] = data.cacheable;
2204
+ if (data.cacheTtlSeconds !== undefined) body['cache_ttl_seconds'] = data.cacheTtlSeconds;
2205
+ if (data.expression) body['expression'] = data.expression;
2206
+ return body;
2207
+ }
2208
+ function createConditionsService(transport, _config) {
2209
+ return {
2210
+ async list (params) {
2211
+ const queryParams = {};
2212
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
2213
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
2214
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
2215
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
2216
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
2217
+ const response = await transport.get('/conditions', {
2218
+ params: queryParams
2219
+ });
2220
+ return decodePageResult(response, conditionMapper);
2221
+ },
2222
+ async get (uniqueId) {
2223
+ const response = await transport.get(`/conditions/${uniqueId}`);
2224
+ return decodeOne(response, conditionMapper);
2225
+ },
2226
+ async create (data) {
2227
+ const response = await transport.post('/conditions', {
2228
+ condition: buildConditionBody(data)
2229
+ });
2230
+ return decodeOne(response, conditionMapper);
2231
+ },
2232
+ async update (uniqueId, data) {
2233
+ const response = await transport.put(`/conditions/${uniqueId}`, {
2234
+ condition: buildConditionBody(data)
2235
+ });
2236
+ return decodeOne(response, conditionMapper);
2237
+ },
2238
+ async delete (uniqueId) {
2239
+ await transport.delete(`/conditions/${uniqueId}`);
2240
+ }
2241
+ };
2242
+ }
2243
+
2244
+ const stepTransitionMapper = {
2245
+ type: 'step_transition',
2246
+ map: (resource)=>({
2247
+ id: resource.id,
2248
+ uniqueId: parseString(resource.attributes['unique_id']) || '',
2249
+ name: parseString(resource.attributes['name']) || '',
2250
+ description: parseString(resource.attributes['description']),
2251
+ transitionType: parseString(resource.attributes['transition_type']),
2252
+ priority: parseOptionalNumber(resource.attributes['priority']),
2253
+ isDefault: resource.attributes['is_default'] != null ? parseBoolean(resource.attributes['is_default']) : undefined,
2254
+ allowsBackward: resource.attributes['allows_backward'] != null ? parseBoolean(resource.attributes['allows_backward']) : undefined,
2255
+ maxIterations: parseOptionalNumber(resource.attributes['max_iterations']),
2256
+ onLoop: parseString(resource.attributes['on_loop']),
2257
+ status: parseString(resource.attributes['status']) || 'active',
2258
+ enabled: resource.attributes['enabled'] != null ? parseBoolean(resource.attributes['enabled']) : undefined,
2259
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
2260
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date()
2261
+ })
2262
+ };
2263
+
2264
+ function buildStepTransitionBody(data) {
2265
+ const body = {};
2266
+ if (data.name) body['name'] = data.name;
2267
+ if (data.description) body['description'] = data.description;
2268
+ if (data.transitionType) body['transition_type'] = data.transitionType;
2269
+ if (data.priority !== undefined) body['priority'] = data.priority;
2270
+ if (data.isDefault !== undefined) body['is_default'] = data.isDefault;
2271
+ if (data.allowsBackward !== undefined) body['allows_backward'] = data.allowsBackward;
2272
+ if (data.maxIterations !== undefined) body['max_iterations'] = data.maxIterations;
2273
+ if (data.onLoop) body['on_loop'] = data.onLoop;
2274
+ return body;
2275
+ }
2276
+ function createStepTransitionsService(transport, _config) {
2277
+ return {
2278
+ async list (stepUniqueId, params) {
2279
+ const queryParams = {};
2280
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
2281
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
2282
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
2283
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
2284
+ const response = await transport.get(`/steps/${stepUniqueId}/transitions`, {
2285
+ params: queryParams
2286
+ });
2287
+ return decodePageResult(response, stepTransitionMapper);
2288
+ },
2289
+ async get (stepUniqueId, uniqueId) {
2290
+ const response = await transport.get(`/steps/${stepUniqueId}/transitions/${uniqueId}`);
2291
+ return decodeOne(response, stepTransitionMapper);
2292
+ },
2293
+ async create (stepUniqueId, data) {
2294
+ const response = await transport.post(`/steps/${stepUniqueId}/transitions`, {
2295
+ step_transition: buildStepTransitionBody(data)
2296
+ });
2297
+ return decodeOne(response, stepTransitionMapper);
2298
+ },
2299
+ async update (stepUniqueId, uniqueId, data) {
2300
+ const response = await transport.put(`/steps/${stepUniqueId}/transitions/${uniqueId}`, {
2301
+ step_transition: buildStepTransitionBody(data)
2302
+ });
2303
+ return decodeOne(response, stepTransitionMapper);
2304
+ },
2305
+ async delete (stepUniqueId, uniqueId) {
2306
+ await transport.delete(`/steps/${stepUniqueId}/transitions/${uniqueId}`);
2307
+ }
2308
+ };
2309
+ }
2310
+
2311
+ function createJarvisBlock(transport, config) {
2198
2312
  return {
2199
2313
  agents: createAgentsService(transport),
2200
2314
  prompts: createPromptsService(transport),
@@ -2202,17 +2316,22 @@ function createExecutionCommentsService(transport, _config) {
2202
2316
  executions: createExecutionsService(transport),
2203
2317
  conversations: createConversationsService(transport),
2204
2318
  aiModels: createAIModelsService(transport),
2205
- entities: createEntitiesService(transport),
2319
+ entities: createEntitiesService(transport, config, config.sseUrl),
2206
2320
  clusters: createClustersService(transport),
2207
2321
  users: createJarvisUsersService(transport),
2208
2322
  workflowParticipants: createWorkflowParticipantsService(transport),
2209
2323
  workflowSteps: createWorkflowStepsService(transport),
2210
2324
  workflowInstances: createWorkflowInstancesService(transport),
2211
- agentRuntime: createAgentRuntimeService(transport),
2325
+ agentRuntime: createAgentRuntimeService(transport, config, config.sseUrl),
2212
2326
  mailTemplates: createMailTemplatesService(transport),
2213
2327
  marvinChat: createMarvinChatService(transport),
2214
2328
  promptComments: createPromptCommentsService(transport),
2215
2329
  executionComments: createExecutionCommentsService(transport),
2330
+ tools: createToolsService(transport),
2331
+ agentTools: createAgentToolsService(transport),
2332
+ agentToolAssignments: createAgentToolAssignmentsService(transport),
2333
+ conditions: createConditionsService(transport),
2334
+ stepTransitions: createStepTransitionsService(transport),
2216
2335
  health: ()=>transport.get('/health')
2217
2336
  };
2218
2337
  }