lua-cli 2.5.8 → 3.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/chat.api.service.d.ts +8 -0
- package/dist/api/chat.api.service.js +50 -0
- package/dist/api/job.api.service.d.ts +219 -0
- package/dist/api/job.api.service.js +216 -0
- package/dist/api/lazy-instances.d.ts +24 -0
- package/dist/api/lazy-instances.js +48 -0
- package/dist/api/postprocessor.api.service.d.ts +158 -0
- package/dist/api/postprocessor.api.service.js +111 -0
- package/dist/api/preprocessor.api.service.d.ts +158 -0
- package/dist/api/preprocessor.api.service.js +111 -0
- package/dist/api/user.data.api.service.d.ts +13 -0
- package/dist/api/user.data.api.service.js +20 -0
- package/dist/api/webhook.api.service.d.ts +151 -0
- package/dist/api/webhook.api.service.js +134 -0
- package/dist/api-exports.d.ts +176 -41
- package/dist/api-exports.js +195 -21
- package/dist/cli/command-definitions.js +85 -8
- package/dist/commands/chat.js +73 -36
- package/dist/commands/compile.js +140 -7
- package/dist/commands/dev.js +23 -2
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.js +4 -0
- package/dist/commands/init.js +53 -7
- package/dist/commands/jobs.d.ts +20 -0
- package/dist/commands/jobs.js +533 -0
- package/dist/commands/logs.js +2 -5
- package/dist/commands/postprocessors.d.ts +8 -0
- package/dist/commands/postprocessors.js +431 -0
- package/dist/commands/preprocessors.d.ts +8 -0
- package/dist/commands/preprocessors.js +431 -0
- package/dist/commands/push.d.ts +3 -2
- package/dist/commands/push.js +1216 -7
- package/dist/commands/test.d.ts +9 -18
- package/dist/commands/test.js +574 -82
- package/dist/commands/webhooks.d.ts +18 -0
- package/dist/commands/webhooks.js +424 -0
- package/dist/common/job.instance.d.ts +80 -0
- package/dist/common/job.instance.js +116 -0
- package/dist/common/user.instance.d.ts +1 -0
- package/dist/common/user.instance.js +9 -0
- package/dist/config/constants.d.ts +4 -3
- package/dist/config/constants.js +10 -8
- package/dist/interfaces/agent.d.ts +2 -1
- package/dist/interfaces/chat.d.ts +52 -1
- package/dist/interfaces/index.d.ts +10 -0
- package/dist/interfaces/index.js +7 -0
- package/dist/interfaces/jobs.d.ts +193 -0
- package/dist/interfaces/jobs.js +5 -0
- package/dist/interfaces/postprocessors.d.ts +35 -0
- package/dist/interfaces/postprocessors.js +4 -0
- package/dist/interfaces/preprocessors.d.ts +35 -0
- package/dist/interfaces/preprocessors.js +4 -0
- package/dist/interfaces/webhooks.d.ts +104 -0
- package/dist/interfaces/webhooks.js +5 -0
- package/dist/services/auth.d.ts +8 -2
- package/dist/services/auth.js +35 -3
- package/dist/types/api-contracts.d.ts +5 -0
- package/dist/types/compile.types.d.ts +49 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/skill.d.ts +521 -0
- package/dist/types/skill.js +471 -0
- package/dist/utils/agent-management.d.ts +25 -0
- package/dist/utils/agent-management.js +67 -0
- package/dist/utils/bundling.d.ts +44 -5
- package/dist/utils/bundling.js +723 -23
- package/dist/utils/compile.d.ts +63 -0
- package/dist/utils/compile.js +712 -36
- package/dist/utils/deployment.d.ts +2 -1
- package/dist/utils/deployment.js +16 -2
- package/dist/utils/dev-api.d.ts +42 -2
- package/dist/utils/dev-api.js +177 -4
- package/dist/utils/dev-server.d.ts +1 -1
- package/dist/utils/dev-server.js +4 -4
- package/dist/utils/dynamic-job-bundler.d.ts +17 -0
- package/dist/utils/dynamic-job-bundler.js +143 -0
- package/dist/utils/init-agent.d.ts +3 -1
- package/dist/utils/init-agent.js +6 -4
- package/dist/utils/init-prompts.d.ts +2 -1
- package/dist/utils/init-prompts.js +14 -9
- package/dist/utils/job-management.d.ts +24 -0
- package/dist/utils/job-management.js +264 -0
- package/dist/utils/postprocessor-management.d.ts +9 -0
- package/dist/utils/postprocessor-management.js +118 -0
- package/dist/utils/pre-bundle-jobs.d.ts +26 -0
- package/dist/utils/pre-bundle-jobs.js +176 -0
- package/dist/utils/preprocessor-management.d.ts +9 -0
- package/dist/utils/preprocessor-management.js +118 -0
- package/dist/utils/sandbox-storage.d.ts +48 -0
- package/dist/utils/sandbox-storage.js +114 -0
- package/dist/utils/sandbox.d.ts +61 -1
- package/dist/utils/sandbox.js +299 -72
- package/dist/utils/tool-detection.d.ts +3 -2
- package/dist/utils/tool-detection.js +18 -4
- package/dist/utils/webhook-management.d.ts +24 -0
- package/dist/utils/webhook-management.js +256 -0
- package/package.json +1 -1
- package/template/README.md +30 -2
- package/template/env.example +5 -0
- package/template/lua.skill.yaml +47 -0
- package/template/package-lock.json +10505 -0
- package/template/package.json +2 -1
- package/template/src/index.ts +103 -2
- package/template/src/jobs/AbandonedBasketProcessorJob.ts +139 -0
- package/template/src/jobs/DailyCleanupJob.ts +100 -0
- package/template/src/jobs/DataMigrationJob.ts +133 -0
- package/template/src/jobs/HealthCheckJob.ts +87 -0
- package/template/src/tools/CreateInlineJob.ts +42 -0
- package/template/src/tools/GameScoreTrackerTool.ts +356 -0
- package/template/src/tools/SmartBasketTool.ts +188 -0
- package/template/src/webhooks/PaymentWebhook.ts +113 -0
- package/template/src/webhooks/UserEventWebhook.ts +77 -0
- package/API_REFERENCE.md +0 -1408
- package/CHANGELOG.md +0 -236
- package/CLI_REFERENCE.md +0 -908
- package/GETTING_STARTED.md +0 -1040
- package/INSTANCE_TYPES.md +0 -1158
- package/README.md +0 -865
- package/TEMPLATE_GUIDE.md +0 -1398
- package/USER_DATA_INSTANCE.md +0 -621
- package/template/TOOL_EXAMPLES.md +0 -655
|
@@ -18,4 +18,12 @@ export default class ChatApi extends HttpClient {
|
|
|
18
18
|
* @throws Error if the agent is not found or the chat request fails
|
|
19
19
|
*/
|
|
20
20
|
sendMessage(agentId: string, chatData: ChatRequest): Promise<ApiResponse<ChatResponse>>;
|
|
21
|
+
/**
|
|
22
|
+
* Streams a message to an agent and receives chunked responses
|
|
23
|
+
* @param agentId - The unique identifier of the agent to chat with
|
|
24
|
+
* @param chatData - The chat request data including message, conversation history, and context
|
|
25
|
+
* @param onChunk - Callback function to handle each text chunk as it arrives
|
|
26
|
+
* @returns Promise resolving when stream completes
|
|
27
|
+
*/
|
|
28
|
+
sendMessageStream(agentId: string, chatData: ChatRequest, onChunk: (text: string) => void): Promise<void>;
|
|
21
29
|
}
|
|
@@ -21,4 +21,54 @@ export default class ChatApi extends HttpClient {
|
|
|
21
21
|
Authorization: `Bearer ${this.apiKey}`,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Streams a message to an agent and receives chunked responses
|
|
26
|
+
* @param agentId - The unique identifier of the agent to chat with
|
|
27
|
+
* @param chatData - The chat request data including message, conversation history, and context
|
|
28
|
+
* @param onChunk - Callback function to handle each text chunk as it arrives
|
|
29
|
+
* @returns Promise resolving when stream completes
|
|
30
|
+
*/
|
|
31
|
+
async sendMessageStream(agentId, chatData, onChunk) {
|
|
32
|
+
const response = await fetch(`${this.baseUrl}/chat/stream/${agentId}?channel=dev`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify(chatData)
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
42
|
+
}
|
|
43
|
+
const reader = response.body?.getReader();
|
|
44
|
+
if (!reader) {
|
|
45
|
+
throw new Error('Response body is not readable');
|
|
46
|
+
}
|
|
47
|
+
const decoder = new TextDecoder();
|
|
48
|
+
let buffer = '';
|
|
49
|
+
while (true) {
|
|
50
|
+
const { done, value } = await reader.read();
|
|
51
|
+
if (done)
|
|
52
|
+
break;
|
|
53
|
+
// Decode the chunk and add to buffer
|
|
54
|
+
buffer += decoder.decode(value, { stream: true });
|
|
55
|
+
// Process complete lines (chunks are separated by newlines)
|
|
56
|
+
const lines = buffer.split('\n');
|
|
57
|
+
buffer = lines.pop() || ''; // Keep incomplete line in buffer
|
|
58
|
+
for (const line of lines) {
|
|
59
|
+
if (!line.trim())
|
|
60
|
+
continue;
|
|
61
|
+
try {
|
|
62
|
+
const chunk = JSON.parse(line);
|
|
63
|
+
// Only process text-delta chunks
|
|
64
|
+
if (chunk.type === 'text-delta' && chunk.textDelta) {
|
|
65
|
+
onChunk(chunk.textDelta);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// Skip invalid JSON lines
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
24
74
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { HttpClient } from "../common/http.client.js";
|
|
2
|
+
import { ApiResponse } from "../interfaces/common.js";
|
|
3
|
+
import { CreateJobDTO, PushJobVersionDTO, UpdateJobVersionDTO } from "../interfaces/jobs.js";
|
|
4
|
+
import { JobInstance } from "../common/job.instance.js";
|
|
5
|
+
/**
|
|
6
|
+
* Job API Response Types
|
|
7
|
+
*/
|
|
8
|
+
export interface JobVersion {
|
|
9
|
+
version: string;
|
|
10
|
+
jobId: string;
|
|
11
|
+
createdAt: string | number;
|
|
12
|
+
isActive?: boolean;
|
|
13
|
+
schedule?: any;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
retry?: {
|
|
16
|
+
maxAttempts: number;
|
|
17
|
+
backoffSeconds?: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface GetJobsResponse {
|
|
21
|
+
jobs: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
context?: string;
|
|
26
|
+
versions: JobVersion[];
|
|
27
|
+
activeVersionId?: string;
|
|
28
|
+
lastRunAt?: string;
|
|
29
|
+
nextRunAt?: string;
|
|
30
|
+
status?: 'active' | 'paused' | 'failed';
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export interface CreateJobResponse {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
agentId: string;
|
|
38
|
+
context?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface JobVersionResponse {
|
|
41
|
+
versionId: string;
|
|
42
|
+
jobId: string;
|
|
43
|
+
version: string;
|
|
44
|
+
createdAt: string;
|
|
45
|
+
schedule: any;
|
|
46
|
+
}
|
|
47
|
+
export interface UpdateJobVersionResponse {
|
|
48
|
+
versionId: string;
|
|
49
|
+
jobId: string;
|
|
50
|
+
version: string;
|
|
51
|
+
updatedAt: string;
|
|
52
|
+
}
|
|
53
|
+
export interface DeleteJobResponse {
|
|
54
|
+
deleted: boolean;
|
|
55
|
+
deactivated?: boolean;
|
|
56
|
+
message: string;
|
|
57
|
+
}
|
|
58
|
+
export interface JobExecutionResponse {
|
|
59
|
+
executionId: string;
|
|
60
|
+
jobId: string;
|
|
61
|
+
startedAt: string;
|
|
62
|
+
completedAt?: string;
|
|
63
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
64
|
+
result?: any;
|
|
65
|
+
error?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Job API Service
|
|
69
|
+
* Handles all job-related API calls
|
|
70
|
+
*/
|
|
71
|
+
export default class JobApi extends HttpClient {
|
|
72
|
+
apiKey: string;
|
|
73
|
+
agentId: string;
|
|
74
|
+
/**
|
|
75
|
+
* Creates an instance of JobApi
|
|
76
|
+
* @param baseUrl - The base URL for the API
|
|
77
|
+
* @param apiKey - The API key for authentication
|
|
78
|
+
* @param agentId - The unique identifier of the agent
|
|
79
|
+
*/
|
|
80
|
+
constructor(baseUrl: string, apiKey: string, agentId: string);
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves all jobs for the agent
|
|
83
|
+
* @returns Promise resolving to an ApiResponse containing an array of jobs with their versions
|
|
84
|
+
* @throws Error if the API request fails or the agent is not found
|
|
85
|
+
*/
|
|
86
|
+
getJobs(): Promise<ApiResponse<GetJobsResponse>>;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves a job by its unique identifier
|
|
89
|
+
* @param jobId - The unique identifier of the job to retrieve
|
|
90
|
+
* @returns Promise resolving to an JobInstance representing the job
|
|
91
|
+
* @throws Error if the job is not found or the request fails
|
|
92
|
+
*/
|
|
93
|
+
getJob(jobId: string): Promise<JobInstance>;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new job for the agent.
|
|
96
|
+
* Optionally creates initial version and activates the job in one call.
|
|
97
|
+
*
|
|
98
|
+
* @param jobData - The job data including name, description, schedule, and optional version
|
|
99
|
+
* @param jobData.version - If provided, creates first version automatically
|
|
100
|
+
* @param jobData.activate - If true, activates the job immediately
|
|
101
|
+
* @returns Promise resolving to an ApiResponse containing the created job details
|
|
102
|
+
* @throws Error if the job creation fails or validation errors occur
|
|
103
|
+
*/
|
|
104
|
+
createJob(jobData: CreateJobDTO): Promise<ApiResponse<CreateJobResponse>>;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new job for the agent and returns a JobInstance.
|
|
107
|
+
* Supports automatic version creation and activation.
|
|
108
|
+
*
|
|
109
|
+
* @param jobData - The job data including name, description, schedule, and optional version
|
|
110
|
+
* @param jobData.version - If provided, creates first version automatically
|
|
111
|
+
* @param jobData.activate - If true, activates the job immediately
|
|
112
|
+
* @returns Promise resolving to a JobInstance containing the created job details
|
|
113
|
+
* @throws Error if the job creation fails or validation errors occur
|
|
114
|
+
*/
|
|
115
|
+
createJobInstance(jobData: CreateJobDTO): Promise<JobInstance>;
|
|
116
|
+
private compressCode;
|
|
117
|
+
/**
|
|
118
|
+
* Pushes a new version of a job to production
|
|
119
|
+
* @param jobId - The unique identifier of the job
|
|
120
|
+
* @param versionData - The version data including code, configuration, and metadata
|
|
121
|
+
* @returns Promise resolving to an ApiResponse containing the created version details
|
|
122
|
+
* @throws Error if the job is not found or the push operation fails
|
|
123
|
+
*/
|
|
124
|
+
pushJob(jobId: string, versionData: PushJobVersionDTO): Promise<ApiResponse<JobVersionResponse>>;
|
|
125
|
+
/**
|
|
126
|
+
* Pushes a new development/sandbox version of a job for testing
|
|
127
|
+
* @param jobId - The unique identifier of the job
|
|
128
|
+
* @param versionData - The version data including code, configuration, and metadata
|
|
129
|
+
* @returns Promise resolving to an ApiResponse containing the development version details
|
|
130
|
+
* @throws Error if the job is not found or the push operation fails
|
|
131
|
+
*/
|
|
132
|
+
pushDevJob(jobId: string, versionData: PushJobVersionDTO): Promise<ApiResponse<JobVersionResponse>>;
|
|
133
|
+
/**
|
|
134
|
+
* Updates an existing development/sandbox version of a job
|
|
135
|
+
* @param jobId - The unique identifier of the job
|
|
136
|
+
* @param sandboxVersionId - The unique identifier of the sandbox version to update
|
|
137
|
+
* @param versionData - The updated version data including code, configuration, and metadata
|
|
138
|
+
* @returns Promise resolving to an ApiResponse containing the updated version details
|
|
139
|
+
* @throws Error if the job or version is not found or the update fails
|
|
140
|
+
*/
|
|
141
|
+
updateDevJob(jobId: string, sandboxVersionId: string, versionData: UpdateJobVersionDTO): Promise<ApiResponse<UpdateJobVersionResponse>>;
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves all versions of a specific job
|
|
144
|
+
* @param jobId - The unique identifier of the job
|
|
145
|
+
* @returns Promise resolving to an ApiResponse containing an array of job versions
|
|
146
|
+
* @throws Error if the job is not found or the request fails
|
|
147
|
+
*/
|
|
148
|
+
getJobVersions(jobId: string): Promise<ApiResponse<{
|
|
149
|
+
versions: JobVersion[];
|
|
150
|
+
activeVersionId?: string;
|
|
151
|
+
}>>;
|
|
152
|
+
/**
|
|
153
|
+
* Publishes a specific version of a job to production
|
|
154
|
+
* @param jobId - The unique identifier of the job
|
|
155
|
+
* @param version - The version identifier to publish
|
|
156
|
+
* @returns Promise resolving to an ApiResponse containing publication confirmation details
|
|
157
|
+
* @throws Error if the job or version is not found or the publish operation fails
|
|
158
|
+
*/
|
|
159
|
+
publishJobVersion(jobId: string, version: string): Promise<ApiResponse<{
|
|
160
|
+
message: string;
|
|
161
|
+
jobId: string;
|
|
162
|
+
activeVersionId: string;
|
|
163
|
+
publishedAt: string;
|
|
164
|
+
}>>;
|
|
165
|
+
/**
|
|
166
|
+
* Deletes a job and all its versions, or deactivates it if it has versions
|
|
167
|
+
* @param jobId - The unique identifier of the job to delete
|
|
168
|
+
* @returns Promise resolving to an ApiResponse with deletion status
|
|
169
|
+
* - If deleted is true: job was successfully deleted
|
|
170
|
+
* - If deleted is false and deactivated is true: job has versions and was deactivated instead
|
|
171
|
+
* @throws Error if the job is not found or the delete operation fails
|
|
172
|
+
*/
|
|
173
|
+
deleteJob(jobId: string): Promise<ApiResponse<DeleteJobResponse>>;
|
|
174
|
+
/**
|
|
175
|
+
* Activates a job (enables it to run on schedule)
|
|
176
|
+
* @param jobId - The unique identifier of the job to activate
|
|
177
|
+
* @returns Promise resolving to an ApiResponse with activation status
|
|
178
|
+
* @throws Error if the job is not found or the operation fails
|
|
179
|
+
*/
|
|
180
|
+
activateJob(jobId: string): Promise<ApiResponse<{
|
|
181
|
+
message: string;
|
|
182
|
+
active: boolean;
|
|
183
|
+
}>>;
|
|
184
|
+
/**
|
|
185
|
+
* Deactivates a job (disables it from running)
|
|
186
|
+
* @param jobId - The unique identifier of the job to deactivate
|
|
187
|
+
* @returns Promise resolving to an ApiResponse with deactivation status
|
|
188
|
+
* @throws Error if the job is not found or the operation fails
|
|
189
|
+
*/
|
|
190
|
+
deactivateJob(jobId: string): Promise<ApiResponse<{
|
|
191
|
+
message: string;
|
|
192
|
+
active: boolean;
|
|
193
|
+
}>>;
|
|
194
|
+
/**
|
|
195
|
+
* Manually triggers a job execution (ignores schedule)
|
|
196
|
+
* @param jobId - The unique identifier of the job to trigger
|
|
197
|
+
* @returns Promise resolving to an ApiResponse with execution details
|
|
198
|
+
* @throws Error if the job is not found or the operation fails
|
|
199
|
+
*/
|
|
200
|
+
triggerJob(jobId: string): Promise<ApiResponse<JobExecutionResponse>>;
|
|
201
|
+
/**
|
|
202
|
+
* Retrieves execution history for a job
|
|
203
|
+
* @param jobId - The unique identifier of the job
|
|
204
|
+
* @param limit - Maximum number of executions to return (default: 50)
|
|
205
|
+
* @returns Promise resolving to an ApiResponse with execution history
|
|
206
|
+
* @throws Error if the job is not found or the request fails
|
|
207
|
+
*/
|
|
208
|
+
getJobExecutions(jobId: string, limit?: number): Promise<ApiResponse<{
|
|
209
|
+
executions: JobExecutionResponse[];
|
|
210
|
+
}>>;
|
|
211
|
+
/**
|
|
212
|
+
* Updates the metadata of a job
|
|
213
|
+
* @param jobId - The unique identifier of the job
|
|
214
|
+
* @param metadata - The metadata object to update or merge with existing metadata
|
|
215
|
+
* @returns Promise resolving to the updated metadata
|
|
216
|
+
* @throws Error if the job is not found or the metadata update fails
|
|
217
|
+
*/
|
|
218
|
+
updateMetadata(jobId: string, metadata: any): Promise<ApiResponse<any>>;
|
|
219
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { HttpClient } from "../common/http.client.js";
|
|
2
|
+
import { JobInstance } from "../common/job.instance.js";
|
|
3
|
+
import { gzipSync } from "zlib";
|
|
4
|
+
/**
|
|
5
|
+
* Job API Service
|
|
6
|
+
* Handles all job-related API calls
|
|
7
|
+
*/
|
|
8
|
+
export default class JobApi extends HttpClient {
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of JobApi
|
|
11
|
+
* @param baseUrl - The base URL for the API
|
|
12
|
+
* @param apiKey - The API key for authentication
|
|
13
|
+
* @param agentId - The unique identifier of the agent
|
|
14
|
+
*/
|
|
15
|
+
constructor(baseUrl, apiKey, agentId) {
|
|
16
|
+
super(baseUrl);
|
|
17
|
+
this.apiKey = apiKey;
|
|
18
|
+
this.agentId = agentId;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves all jobs for the agent
|
|
22
|
+
* @returns Promise resolving to an ApiResponse containing an array of jobs with their versions
|
|
23
|
+
* @throws Error if the API request fails or the agent is not found
|
|
24
|
+
*/
|
|
25
|
+
async getJobs() {
|
|
26
|
+
return this.httpGet(`/developer/jobs/${this.agentId}`, {
|
|
27
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves a job by its unique identifier
|
|
32
|
+
* @param jobId - The unique identifier of the job to retrieve
|
|
33
|
+
* @returns Promise resolving to an JobInstance representing the job
|
|
34
|
+
* @throws Error if the job is not found or the request fails
|
|
35
|
+
*/
|
|
36
|
+
async getJob(jobId) {
|
|
37
|
+
const response = await this.httpGet(`/developer/jobs/${this.agentId}/${jobId}`, {
|
|
38
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
39
|
+
});
|
|
40
|
+
if (response.success && response.data) {
|
|
41
|
+
return new JobInstance(this, response.data);
|
|
42
|
+
}
|
|
43
|
+
throw new Error(response.error?.message || 'Failed to get job');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new job for the agent.
|
|
47
|
+
* Optionally creates initial version and activates the job in one call.
|
|
48
|
+
*
|
|
49
|
+
* @param jobData - The job data including name, description, schedule, and optional version
|
|
50
|
+
* @param jobData.version - If provided, creates first version automatically
|
|
51
|
+
* @param jobData.activate - If true, activates the job immediately
|
|
52
|
+
* @returns Promise resolving to an ApiResponse containing the created job details
|
|
53
|
+
* @throws Error if the job creation fails or validation errors occur
|
|
54
|
+
*/
|
|
55
|
+
async createJob(jobData) {
|
|
56
|
+
return this.httpPost(`/developer/jobs/${this.agentId}`, jobData, {
|
|
57
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new job for the agent and returns a JobInstance.
|
|
62
|
+
* Supports automatic version creation and activation.
|
|
63
|
+
*
|
|
64
|
+
* @param jobData - The job data including name, description, schedule, and optional version
|
|
65
|
+
* @param jobData.version - If provided, creates first version automatically
|
|
66
|
+
* @param jobData.activate - If true, activates the job immediately
|
|
67
|
+
* @returns Promise resolving to a JobInstance containing the created job details
|
|
68
|
+
* @throws Error if the job creation fails or validation errors occur
|
|
69
|
+
*/
|
|
70
|
+
async createJobInstance(jobData) {
|
|
71
|
+
if (jobData.version?.executeFunction && jobData.version?.executeFunction.length > 0) {
|
|
72
|
+
jobData.version.code = this.compressCode(jobData.version.executeFunction);
|
|
73
|
+
}
|
|
74
|
+
const response = await this.httpPost(`/developer/jobs/${this.agentId}`, jobData, {
|
|
75
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
76
|
+
});
|
|
77
|
+
if (response.success && response.data) {
|
|
78
|
+
return new JobInstance(this, response.data);
|
|
79
|
+
}
|
|
80
|
+
throw new Error(response.error?.message || 'Failed to create job');
|
|
81
|
+
}
|
|
82
|
+
compressCode(code) {
|
|
83
|
+
const compressed = gzipSync(code);
|
|
84
|
+
return compressed.toString('base64');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Pushes a new version of a job to production
|
|
88
|
+
* @param jobId - The unique identifier of the job
|
|
89
|
+
* @param versionData - The version data including code, configuration, and metadata
|
|
90
|
+
* @returns Promise resolving to an ApiResponse containing the created version details
|
|
91
|
+
* @throws Error if the job is not found or the push operation fails
|
|
92
|
+
*/
|
|
93
|
+
async pushJob(jobId, versionData) {
|
|
94
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/version`, versionData, {
|
|
95
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Pushes a new development/sandbox version of a job for testing
|
|
100
|
+
* @param jobId - The unique identifier of the job
|
|
101
|
+
* @param versionData - The version data including code, configuration, and metadata
|
|
102
|
+
* @returns Promise resolving to an ApiResponse containing the development version details
|
|
103
|
+
* @throws Error if the job is not found or the push operation fails
|
|
104
|
+
*/
|
|
105
|
+
async pushDevJob(jobId, versionData) {
|
|
106
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/version/sandbox`, versionData, {
|
|
107
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Updates an existing development/sandbox version of a job
|
|
112
|
+
* @param jobId - The unique identifier of the job
|
|
113
|
+
* @param sandboxVersionId - The unique identifier of the sandbox version to update
|
|
114
|
+
* @param versionData - The updated version data including code, configuration, and metadata
|
|
115
|
+
* @returns Promise resolving to an ApiResponse containing the updated version details
|
|
116
|
+
* @throws Error if the job or version is not found or the update fails
|
|
117
|
+
*/
|
|
118
|
+
async updateDevJob(jobId, sandboxVersionId, versionData) {
|
|
119
|
+
return this.httpPut(`/developer/jobs/${this.agentId}/${jobId}/version/sandbox/${sandboxVersionId}`, versionData, {
|
|
120
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves all versions of a specific job
|
|
125
|
+
* @param jobId - The unique identifier of the job
|
|
126
|
+
* @returns Promise resolving to an ApiResponse containing an array of job versions
|
|
127
|
+
* @throws Error if the job is not found or the request fails
|
|
128
|
+
*/
|
|
129
|
+
async getJobVersions(jobId) {
|
|
130
|
+
return this.httpGet(`/developer/jobs/${this.agentId}/${jobId}/versions`, {
|
|
131
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Publishes a specific version of a job to production
|
|
136
|
+
* @param jobId - The unique identifier of the job
|
|
137
|
+
* @param version - The version identifier to publish
|
|
138
|
+
* @returns Promise resolving to an ApiResponse containing publication confirmation details
|
|
139
|
+
* @throws Error if the job or version is not found or the publish operation fails
|
|
140
|
+
*/
|
|
141
|
+
async publishJobVersion(jobId, version) {
|
|
142
|
+
return this.httpPut(`/developer/jobs/${this.agentId}/${jobId}/${version}/publish`, undefined, {
|
|
143
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Deletes a job and all its versions, or deactivates it if it has versions
|
|
148
|
+
* @param jobId - The unique identifier of the job to delete
|
|
149
|
+
* @returns Promise resolving to an ApiResponse with deletion status
|
|
150
|
+
* - If deleted is true: job was successfully deleted
|
|
151
|
+
* - If deleted is false and deactivated is true: job has versions and was deactivated instead
|
|
152
|
+
* @throws Error if the job is not found or the delete operation fails
|
|
153
|
+
*/
|
|
154
|
+
async deleteJob(jobId) {
|
|
155
|
+
return this.httpDelete(`/developer/jobs/${this.agentId}/${jobId}`, {
|
|
156
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Activates a job (enables it to run on schedule)
|
|
161
|
+
* @param jobId - The unique identifier of the job to activate
|
|
162
|
+
* @returns Promise resolving to an ApiResponse with activation status
|
|
163
|
+
* @throws Error if the job is not found or the operation fails
|
|
164
|
+
*/
|
|
165
|
+
async activateJob(jobId) {
|
|
166
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/activate`, {}, {
|
|
167
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Deactivates a job (disables it from running)
|
|
172
|
+
* @param jobId - The unique identifier of the job to deactivate
|
|
173
|
+
* @returns Promise resolving to an ApiResponse with deactivation status
|
|
174
|
+
* @throws Error if the job is not found or the operation fails
|
|
175
|
+
*/
|
|
176
|
+
async deactivateJob(jobId) {
|
|
177
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/deactivate`, {}, {
|
|
178
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Manually triggers a job execution (ignores schedule)
|
|
183
|
+
* @param jobId - The unique identifier of the job to trigger
|
|
184
|
+
* @returns Promise resolving to an ApiResponse with execution details
|
|
185
|
+
* @throws Error if the job is not found or the operation fails
|
|
186
|
+
*/
|
|
187
|
+
async triggerJob(jobId) {
|
|
188
|
+
return this.httpPost(`/developer/jobs/${this.agentId}/${jobId}/trigger`, {}, {
|
|
189
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves execution history for a job
|
|
194
|
+
* @param jobId - The unique identifier of the job
|
|
195
|
+
* @param limit - Maximum number of executions to return (default: 50)
|
|
196
|
+
* @returns Promise resolving to an ApiResponse with execution history
|
|
197
|
+
* @throws Error if the job is not found or the request fails
|
|
198
|
+
*/
|
|
199
|
+
async getJobExecutions(jobId, limit = 50) {
|
|
200
|
+
return this.httpGet(`/developer/jobs/${this.agentId}/${jobId}/executions?limit=${limit}`, {
|
|
201
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Updates the metadata of a job
|
|
206
|
+
* @param jobId - The unique identifier of the job
|
|
207
|
+
* @param metadata - The metadata object to update or merge with existing metadata
|
|
208
|
+
* @returns Promise resolving to the updated metadata
|
|
209
|
+
* @throws Error if the job is not found or the metadata update fails
|
|
210
|
+
*/
|
|
211
|
+
async updateMetadata(jobId, metadata) {
|
|
212
|
+
return this.httpPut(`/developer/jobs/${this.agentId}/${jobId}/metadata`, metadata, {
|
|
213
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -7,6 +7,9 @@ import BasketApiService from "./basket.api.service.js";
|
|
|
7
7
|
import OrderApiService from "./order.api.service.js";
|
|
8
8
|
import UserDataApiService from "./user.data.api.service.js";
|
|
9
9
|
import CustomDataApiService from "./custom.data.api.service.js";
|
|
10
|
+
import WebhookApi from "./webhook.api.service.js";
|
|
11
|
+
import JobApi from "./job.api.service.js";
|
|
12
|
+
import ChatApi from "./chat.api.service.js";
|
|
10
13
|
/**
|
|
11
14
|
* Gets or creates User Data API instance.
|
|
12
15
|
* Instance is created once and reused for subsequent calls.
|
|
@@ -42,6 +45,27 @@ export declare function getBasketsInstance(): Promise<BasketApiService>;
|
|
|
42
45
|
* @returns OrderApiService instance
|
|
43
46
|
*/
|
|
44
47
|
export declare function getOrderInstance(): Promise<OrderApiService>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets or creates Webhook API instance.
|
|
50
|
+
* Instance is created once and reused for subsequent calls.
|
|
51
|
+
*
|
|
52
|
+
* @returns WebhookApi instance
|
|
53
|
+
*/
|
|
54
|
+
export declare function getWebhookInstance(): Promise<WebhookApi>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets or creates Job API instance.
|
|
57
|
+
* Instance is created once and reused for subsequent calls.
|
|
58
|
+
*
|
|
59
|
+
* @returns JobApi instance
|
|
60
|
+
*/
|
|
61
|
+
export declare function getJobInstance(): Promise<JobApi>;
|
|
62
|
+
/**
|
|
63
|
+
* Gets or creates Chat API instance.
|
|
64
|
+
* Instance is created once and reused for subsequent calls.
|
|
65
|
+
*
|
|
66
|
+
* @returns ChatApi instance
|
|
67
|
+
*/
|
|
68
|
+
export declare function getChatInstance(): Promise<ChatApi>;
|
|
45
69
|
/**
|
|
46
70
|
* Clears all cached API instances.
|
|
47
71
|
* Useful for testing or when credentials change.
|
|
@@ -9,6 +9,9 @@ import BasketApiService from "./basket.api.service.js";
|
|
|
9
9
|
import OrderApiService from "./order.api.service.js";
|
|
10
10
|
import UserDataApiService from "./user.data.api.service.js";
|
|
11
11
|
import CustomDataApiService from "./custom.data.api.service.js";
|
|
12
|
+
import WebhookApi from "./webhook.api.service.js";
|
|
13
|
+
import JobApi from "./job.api.service.js";
|
|
14
|
+
import ChatApi from "./chat.api.service.js";
|
|
12
15
|
/**
|
|
13
16
|
* Singleton instances (lazy-loaded)
|
|
14
17
|
*/
|
|
@@ -17,6 +20,9 @@ let _dataInstance = null;
|
|
|
17
20
|
let _productsInstance = null;
|
|
18
21
|
let _basketsInstance = null;
|
|
19
22
|
let _orderInstance = null;
|
|
23
|
+
let _webhookInstance = null;
|
|
24
|
+
let _jobInstance = null;
|
|
25
|
+
let _chatInstance = null;
|
|
20
26
|
/**
|
|
21
27
|
* Gets or creates User Data API instance.
|
|
22
28
|
* Instance is created once and reused for subsequent calls.
|
|
@@ -82,6 +88,45 @@ export async function getOrderInstance() {
|
|
|
82
88
|
}
|
|
83
89
|
return _orderInstance;
|
|
84
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets or creates Webhook API instance.
|
|
93
|
+
* Instance is created once and reused for subsequent calls.
|
|
94
|
+
*
|
|
95
|
+
* @returns WebhookApi instance
|
|
96
|
+
*/
|
|
97
|
+
export async function getWebhookInstance() {
|
|
98
|
+
if (!_webhookInstance) {
|
|
99
|
+
const creds = await getCredentials();
|
|
100
|
+
_webhookInstance = new WebhookApi(BASE_URLS.API, creds.apiKey, creds.agentId);
|
|
101
|
+
}
|
|
102
|
+
return _webhookInstance;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Gets or creates Job API instance.
|
|
106
|
+
* Instance is created once and reused for subsequent calls.
|
|
107
|
+
*
|
|
108
|
+
* @returns JobApi instance
|
|
109
|
+
*/
|
|
110
|
+
export async function getJobInstance() {
|
|
111
|
+
if (!_jobInstance) {
|
|
112
|
+
const creds = await getCredentials();
|
|
113
|
+
_jobInstance = new JobApi(BASE_URLS.API, creds.apiKey, creds.agentId);
|
|
114
|
+
}
|
|
115
|
+
return _jobInstance;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets or creates Chat API instance.
|
|
119
|
+
* Instance is created once and reused for subsequent calls.
|
|
120
|
+
*
|
|
121
|
+
* @returns ChatApi instance
|
|
122
|
+
*/
|
|
123
|
+
export async function getChatInstance() {
|
|
124
|
+
if (!_chatInstance) {
|
|
125
|
+
const creds = await getCredentials();
|
|
126
|
+
_chatInstance = new ChatApi(BASE_URLS.API, creds.apiKey);
|
|
127
|
+
}
|
|
128
|
+
return _chatInstance;
|
|
129
|
+
}
|
|
85
130
|
/**
|
|
86
131
|
* Clears all cached API instances.
|
|
87
132
|
* Useful for testing or when credentials change.
|
|
@@ -92,4 +137,7 @@ export function clearAllInstances() {
|
|
|
92
137
|
_productsInstance = null;
|
|
93
138
|
_basketsInstance = null;
|
|
94
139
|
_orderInstance = null;
|
|
140
|
+
_webhookInstance = null;
|
|
141
|
+
_jobInstance = null;
|
|
142
|
+
_chatInstance = null;
|
|
95
143
|
}
|