@contractspec/example.agent-console 3.2.0 → 3.3.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.
- package/.turbo/turbo-build.log +27 -27
- package/CHANGELOG.md +15 -0
- package/dist/agent.feature.js +9 -1
- package/dist/browser/agent.feature.js +9 -1
- package/dist/browser/handlers/agent.handlers.js +17 -0
- package/dist/browser/handlers/index.js +17 -0
- package/dist/browser/index.js +50 -6
- package/dist/browser/ui/AgentDashboard.js +24 -5
- package/dist/browser/ui/hooks/index.js +24 -5
- package/dist/browser/ui/hooks/useAgentMutations.js +24 -5
- package/dist/browser/ui/index.js +24 -5
- package/dist/handlers/agent.handlers.d.ts +8 -0
- package/dist/handlers/agent.handlers.js +17 -0
- package/dist/handlers/index.js +17 -0
- package/dist/index.js +50 -6
- package/dist/node/agent.feature.js +9 -1
- package/dist/node/handlers/agent.handlers.js +17 -0
- package/dist/node/handlers/index.js +17 -0
- package/dist/node/index.js +50 -6
- package/dist/node/ui/AgentDashboard.js +24 -5
- package/dist/node/ui/hooks/index.js +24 -5
- package/dist/node/ui/hooks/useAgentMutations.js +24 -5
- package/dist/node/ui/index.js +24 -5
- package/dist/ui/AgentDashboard.js +24 -5
- package/dist/ui/hooks/index.js +24 -5
- package/dist/ui/hooks/useAgentMutations.d.ts +4 -3
- package/dist/ui/hooks/useAgentMutations.js +24 -5
- package/dist/ui/index.js +24 -5
- package/package.json +8 -8
- package/src/agent.feature.ts +11 -0
- package/src/handlers/agent.handlers.ts +34 -0
- package/src/ui/hooks/useAgentMutations.ts +34 -10
package/dist/index.js
CHANGED
|
@@ -112,7 +112,15 @@ var AgentConsoleFeature = defineFeature({
|
|
|
112
112
|
{ key: "jobs", version: "1.0.0" }
|
|
113
113
|
],
|
|
114
114
|
provides: [{ key: "agent", version: "1.0.0" }]
|
|
115
|
-
}
|
|
115
|
+
},
|
|
116
|
+
telemetry: [{ key: "agent-console.telemetry", version: "1.0.0" }],
|
|
117
|
+
jobs: [{ key: "agent-console.job.run-execution", version: "1.0.0" }],
|
|
118
|
+
docs: [
|
|
119
|
+
"docs.examples.agent-console.goal",
|
|
120
|
+
"docs.examples.agent-console.usage",
|
|
121
|
+
"docs.examples.agent-console.reference",
|
|
122
|
+
"docs.examples.agent-console.constraints"
|
|
123
|
+
]
|
|
116
124
|
});
|
|
117
125
|
|
|
118
126
|
// src/agent/agent.entity.ts
|
|
@@ -1702,11 +1710,28 @@ function createAgentHandlers(db) {
|
|
|
1702
1710
|
totalCostUsd: data?.totalCost ?? 0
|
|
1703
1711
|
};
|
|
1704
1712
|
}
|
|
1713
|
+
async function executeAgent(input) {
|
|
1714
|
+
const agent = await getAgent(input.agentId);
|
|
1715
|
+
if (!agent)
|
|
1716
|
+
throw new Error("AGENT_NOT_FOUND");
|
|
1717
|
+
if (agent.status !== "ACTIVE")
|
|
1718
|
+
throw new Error("AGENT_NOT_ACTIVE");
|
|
1719
|
+
const id = generateId("run");
|
|
1720
|
+
const now = new Date().toISOString();
|
|
1721
|
+
const pid = input.context?.projectId ?? agent.projectId;
|
|
1722
|
+
await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
1723
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
|
|
1724
|
+
const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
|
|
1725
|
+
if (!rows[0])
|
|
1726
|
+
throw new Error("Failed to retrieve created run");
|
|
1727
|
+
return rowToRun(rows[0], rows[0].agentName);
|
|
1728
|
+
}
|
|
1705
1729
|
return {
|
|
1706
1730
|
listAgents,
|
|
1707
1731
|
getAgent,
|
|
1708
1732
|
createAgent,
|
|
1709
1733
|
updateAgent,
|
|
1734
|
+
executeAgent,
|
|
1710
1735
|
listTools,
|
|
1711
1736
|
listRuns,
|
|
1712
1737
|
getRunMetrics
|
|
@@ -4249,6 +4274,11 @@ function useAgentMutations(options = {}) {
|
|
|
4249
4274
|
error: null,
|
|
4250
4275
|
data: null
|
|
4251
4276
|
});
|
|
4277
|
+
const [executeState, setExecuteState] = useState4({
|
|
4278
|
+
loading: false,
|
|
4279
|
+
error: null,
|
|
4280
|
+
data: null
|
|
4281
|
+
});
|
|
4252
4282
|
const createAgent = useCallback4(async (input) => {
|
|
4253
4283
|
setCreateState({ loading: true, error: null, data: null });
|
|
4254
4284
|
try {
|
|
@@ -4290,10 +4320,23 @@ function useAgentMutations(options = {}) {
|
|
|
4290
4320
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
4291
4321
|
}, [updateAgent]);
|
|
4292
4322
|
const executeAgent = useCallback4(async (input) => {
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4323
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
4324
|
+
try {
|
|
4325
|
+
const result = await agent.executeAgent({
|
|
4326
|
+
agentId: input.agentId,
|
|
4327
|
+
message: input.message,
|
|
4328
|
+
context: { projectId, organizationId: "demo-org" }
|
|
4329
|
+
});
|
|
4330
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
4331
|
+
options.onSuccess?.();
|
|
4332
|
+
return result;
|
|
4333
|
+
} catch (err) {
|
|
4334
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
4335
|
+
setExecuteState({ loading: false, error, data: null });
|
|
4336
|
+
options.onError?.(error);
|
|
4337
|
+
return null;
|
|
4338
|
+
}
|
|
4339
|
+
}, [agent, projectId, options]);
|
|
4297
4340
|
return {
|
|
4298
4341
|
createAgent,
|
|
4299
4342
|
updateAgent,
|
|
@@ -4303,7 +4346,8 @@ function useAgentMutations(options = {}) {
|
|
|
4303
4346
|
executeAgent,
|
|
4304
4347
|
createState,
|
|
4305
4348
|
updateState,
|
|
4306
|
-
|
|
4349
|
+
executeState,
|
|
4350
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
4307
4351
|
};
|
|
4308
4352
|
}
|
|
4309
4353
|
|
|
@@ -111,7 +111,15 @@ var AgentConsoleFeature = defineFeature({
|
|
|
111
111
|
{ key: "jobs", version: "1.0.0" }
|
|
112
112
|
],
|
|
113
113
|
provides: [{ key: "agent", version: "1.0.0" }]
|
|
114
|
-
}
|
|
114
|
+
},
|
|
115
|
+
telemetry: [{ key: "agent-console.telemetry", version: "1.0.0" }],
|
|
116
|
+
jobs: [{ key: "agent-console.job.run-execution", version: "1.0.0" }],
|
|
117
|
+
docs: [
|
|
118
|
+
"docs.examples.agent-console.goal",
|
|
119
|
+
"docs.examples.agent-console.usage",
|
|
120
|
+
"docs.examples.agent-console.reference",
|
|
121
|
+
"docs.examples.agent-console.constraints"
|
|
122
|
+
]
|
|
115
123
|
});
|
|
116
124
|
export {
|
|
117
125
|
AgentConsoleFeature
|
|
@@ -237,11 +237,28 @@ function createAgentHandlers(db) {
|
|
|
237
237
|
totalCostUsd: data?.totalCost ?? 0
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
|
+
async function executeAgent(input) {
|
|
241
|
+
const agent = await getAgent(input.agentId);
|
|
242
|
+
if (!agent)
|
|
243
|
+
throw new Error("AGENT_NOT_FOUND");
|
|
244
|
+
if (agent.status !== "ACTIVE")
|
|
245
|
+
throw new Error("AGENT_NOT_ACTIVE");
|
|
246
|
+
const id = generateId("run");
|
|
247
|
+
const now = new Date().toISOString();
|
|
248
|
+
const pid = input.context?.projectId ?? agent.projectId;
|
|
249
|
+
await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
250
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
|
|
251
|
+
const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
|
|
252
|
+
if (!rows[0])
|
|
253
|
+
throw new Error("Failed to retrieve created run");
|
|
254
|
+
return rowToRun(rows[0], rows[0].agentName);
|
|
255
|
+
}
|
|
240
256
|
return {
|
|
241
257
|
listAgents,
|
|
242
258
|
getAgent,
|
|
243
259
|
createAgent,
|
|
244
260
|
updateAgent,
|
|
261
|
+
executeAgent,
|
|
245
262
|
listTools,
|
|
246
263
|
listRuns,
|
|
247
264
|
getRunMetrics
|
|
@@ -533,11 +533,28 @@ function createAgentHandlers(db) {
|
|
|
533
533
|
totalCostUsd: data?.totalCost ?? 0
|
|
534
534
|
};
|
|
535
535
|
}
|
|
536
|
+
async function executeAgent(input) {
|
|
537
|
+
const agent = await getAgent(input.agentId);
|
|
538
|
+
if (!agent)
|
|
539
|
+
throw new Error("AGENT_NOT_FOUND");
|
|
540
|
+
if (agent.status !== "ACTIVE")
|
|
541
|
+
throw new Error("AGENT_NOT_ACTIVE");
|
|
542
|
+
const id = generateId("run");
|
|
543
|
+
const now = new Date().toISOString();
|
|
544
|
+
const pid = input.context?.projectId ?? agent.projectId;
|
|
545
|
+
await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
546
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
|
|
547
|
+
const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
|
|
548
|
+
if (!rows[0])
|
|
549
|
+
throw new Error("Failed to retrieve created run");
|
|
550
|
+
return rowToRun(rows[0], rows[0].agentName);
|
|
551
|
+
}
|
|
536
552
|
return {
|
|
537
553
|
listAgents,
|
|
538
554
|
getAgent,
|
|
539
555
|
createAgent,
|
|
540
556
|
updateAgent,
|
|
557
|
+
executeAgent,
|
|
541
558
|
listTools,
|
|
542
559
|
listRuns,
|
|
543
560
|
getRunMetrics
|
package/dist/node/index.js
CHANGED
|
@@ -111,7 +111,15 @@ var AgentConsoleFeature = defineFeature({
|
|
|
111
111
|
{ key: "jobs", version: "1.0.0" }
|
|
112
112
|
],
|
|
113
113
|
provides: [{ key: "agent", version: "1.0.0" }]
|
|
114
|
-
}
|
|
114
|
+
},
|
|
115
|
+
telemetry: [{ key: "agent-console.telemetry", version: "1.0.0" }],
|
|
116
|
+
jobs: [{ key: "agent-console.job.run-execution", version: "1.0.0" }],
|
|
117
|
+
docs: [
|
|
118
|
+
"docs.examples.agent-console.goal",
|
|
119
|
+
"docs.examples.agent-console.usage",
|
|
120
|
+
"docs.examples.agent-console.reference",
|
|
121
|
+
"docs.examples.agent-console.constraints"
|
|
122
|
+
]
|
|
115
123
|
});
|
|
116
124
|
|
|
117
125
|
// src/agent/agent.entity.ts
|
|
@@ -1701,11 +1709,28 @@ function createAgentHandlers(db) {
|
|
|
1701
1709
|
totalCostUsd: data?.totalCost ?? 0
|
|
1702
1710
|
};
|
|
1703
1711
|
}
|
|
1712
|
+
async function executeAgent(input) {
|
|
1713
|
+
const agent = await getAgent(input.agentId);
|
|
1714
|
+
if (!agent)
|
|
1715
|
+
throw new Error("AGENT_NOT_FOUND");
|
|
1716
|
+
if (agent.status !== "ACTIVE")
|
|
1717
|
+
throw new Error("AGENT_NOT_ACTIVE");
|
|
1718
|
+
const id = generateId("run");
|
|
1719
|
+
const now = new Date().toISOString();
|
|
1720
|
+
const pid = input.context?.projectId ?? agent.projectId;
|
|
1721
|
+
await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
1722
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
|
|
1723
|
+
const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
|
|
1724
|
+
if (!rows[0])
|
|
1725
|
+
throw new Error("Failed to retrieve created run");
|
|
1726
|
+
return rowToRun(rows[0], rows[0].agentName);
|
|
1727
|
+
}
|
|
1704
1728
|
return {
|
|
1705
1729
|
listAgents,
|
|
1706
1730
|
getAgent,
|
|
1707
1731
|
createAgent,
|
|
1708
1732
|
updateAgent,
|
|
1733
|
+
executeAgent,
|
|
1709
1734
|
listTools,
|
|
1710
1735
|
listRuns,
|
|
1711
1736
|
getRunMetrics
|
|
@@ -4248,6 +4273,11 @@ function useAgentMutations(options = {}) {
|
|
|
4248
4273
|
error: null,
|
|
4249
4274
|
data: null
|
|
4250
4275
|
});
|
|
4276
|
+
const [executeState, setExecuteState] = useState4({
|
|
4277
|
+
loading: false,
|
|
4278
|
+
error: null,
|
|
4279
|
+
data: null
|
|
4280
|
+
});
|
|
4251
4281
|
const createAgent = useCallback4(async (input) => {
|
|
4252
4282
|
setCreateState({ loading: true, error: null, data: null });
|
|
4253
4283
|
try {
|
|
@@ -4289,10 +4319,23 @@ function useAgentMutations(options = {}) {
|
|
|
4289
4319
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
4290
4320
|
}, [updateAgent]);
|
|
4291
4321
|
const executeAgent = useCallback4(async (input) => {
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4322
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
4323
|
+
try {
|
|
4324
|
+
const result = await agent.executeAgent({
|
|
4325
|
+
agentId: input.agentId,
|
|
4326
|
+
message: input.message,
|
|
4327
|
+
context: { projectId, organizationId: "demo-org" }
|
|
4328
|
+
});
|
|
4329
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
4330
|
+
options.onSuccess?.();
|
|
4331
|
+
return result;
|
|
4332
|
+
} catch (err) {
|
|
4333
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
4334
|
+
setExecuteState({ loading: false, error, data: null });
|
|
4335
|
+
options.onError?.(error);
|
|
4336
|
+
return null;
|
|
4337
|
+
}
|
|
4338
|
+
}, [agent, projectId, options]);
|
|
4296
4339
|
return {
|
|
4297
4340
|
createAgent,
|
|
4298
4341
|
updateAgent,
|
|
@@ -4302,7 +4345,8 @@ function useAgentMutations(options = {}) {
|
|
|
4302
4345
|
executeAgent,
|
|
4303
4346
|
createState,
|
|
4304
4347
|
updateState,
|
|
4305
|
-
|
|
4348
|
+
executeState,
|
|
4349
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
4306
4350
|
};
|
|
4307
4351
|
}
|
|
4308
4352
|
|
|
@@ -519,6 +519,11 @@ function useAgentMutations(options = {}) {
|
|
|
519
519
|
error: null,
|
|
520
520
|
data: null
|
|
521
521
|
});
|
|
522
|
+
const [executeState, setExecuteState] = useState4({
|
|
523
|
+
loading: false,
|
|
524
|
+
error: null,
|
|
525
|
+
data: null
|
|
526
|
+
});
|
|
522
527
|
const createAgent = useCallback4(async (input) => {
|
|
523
528
|
setCreateState({ loading: true, error: null, data: null });
|
|
524
529
|
try {
|
|
@@ -560,10 +565,23 @@ function useAgentMutations(options = {}) {
|
|
|
560
565
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
561
566
|
}, [updateAgent]);
|
|
562
567
|
const executeAgent = useCallback4(async (input) => {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
568
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
569
|
+
try {
|
|
570
|
+
const result = await agent.executeAgent({
|
|
571
|
+
agentId: input.agentId,
|
|
572
|
+
message: input.message,
|
|
573
|
+
context: { projectId, organizationId: "demo-org" }
|
|
574
|
+
});
|
|
575
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
576
|
+
options.onSuccess?.();
|
|
577
|
+
return result;
|
|
578
|
+
} catch (err) {
|
|
579
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
580
|
+
setExecuteState({ loading: false, error, data: null });
|
|
581
|
+
options.onError?.(error);
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
}, [agent, projectId, options]);
|
|
567
585
|
return {
|
|
568
586
|
createAgent,
|
|
569
587
|
updateAgent,
|
|
@@ -573,7 +591,8 @@ function useAgentMutations(options = {}) {
|
|
|
573
591
|
executeAgent,
|
|
574
592
|
createState,
|
|
575
593
|
updateState,
|
|
576
|
-
|
|
594
|
+
executeState,
|
|
595
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
577
596
|
};
|
|
578
597
|
}
|
|
579
598
|
|
|
@@ -203,6 +203,11 @@ function useAgentMutations(options = {}) {
|
|
|
203
203
|
error: null,
|
|
204
204
|
data: null
|
|
205
205
|
});
|
|
206
|
+
const [executeState, setExecuteState] = useState4({
|
|
207
|
+
loading: false,
|
|
208
|
+
error: null,
|
|
209
|
+
data: null
|
|
210
|
+
});
|
|
206
211
|
const createAgent = useCallback4(async (input) => {
|
|
207
212
|
setCreateState({ loading: true, error: null, data: null });
|
|
208
213
|
try {
|
|
@@ -244,10 +249,23 @@ function useAgentMutations(options = {}) {
|
|
|
244
249
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
245
250
|
}, [updateAgent]);
|
|
246
251
|
const executeAgent = useCallback4(async (input) => {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
253
|
+
try {
|
|
254
|
+
const result = await agent.executeAgent({
|
|
255
|
+
agentId: input.agentId,
|
|
256
|
+
message: input.message,
|
|
257
|
+
context: { projectId, organizationId: "demo-org" }
|
|
258
|
+
});
|
|
259
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
260
|
+
options.onSuccess?.();
|
|
261
|
+
return result;
|
|
262
|
+
} catch (err) {
|
|
263
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
264
|
+
setExecuteState({ loading: false, error, data: null });
|
|
265
|
+
options.onError?.(error);
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
}, [agent, projectId, options]);
|
|
251
269
|
return {
|
|
252
270
|
createAgent,
|
|
253
271
|
updateAgent,
|
|
@@ -257,7 +275,8 @@ function useAgentMutations(options = {}) {
|
|
|
257
275
|
executeAgent,
|
|
258
276
|
createState,
|
|
259
277
|
updateState,
|
|
260
|
-
|
|
278
|
+
executeState,
|
|
279
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
261
280
|
};
|
|
262
281
|
}
|
|
263
282
|
|
|
@@ -14,6 +14,11 @@ function useAgentMutations(options = {}) {
|
|
|
14
14
|
error: null,
|
|
15
15
|
data: null
|
|
16
16
|
});
|
|
17
|
+
const [executeState, setExecuteState] = useState({
|
|
18
|
+
loading: false,
|
|
19
|
+
error: null,
|
|
20
|
+
data: null
|
|
21
|
+
});
|
|
17
22
|
const createAgent = useCallback(async (input) => {
|
|
18
23
|
setCreateState({ loading: true, error: null, data: null });
|
|
19
24
|
try {
|
|
@@ -55,10 +60,23 @@ function useAgentMutations(options = {}) {
|
|
|
55
60
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
56
61
|
}, [updateAgent]);
|
|
57
62
|
const executeAgent = useCallback(async (input) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
64
|
+
try {
|
|
65
|
+
const result = await agent.executeAgent({
|
|
66
|
+
agentId: input.agentId,
|
|
67
|
+
message: input.message,
|
|
68
|
+
context: { projectId, organizationId: "demo-org" }
|
|
69
|
+
});
|
|
70
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
71
|
+
options.onSuccess?.();
|
|
72
|
+
return result;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
75
|
+
setExecuteState({ loading: false, error, data: null });
|
|
76
|
+
options.onError?.(error);
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}, [agent, projectId, options]);
|
|
62
80
|
return {
|
|
63
81
|
createAgent,
|
|
64
82
|
updateAgent,
|
|
@@ -68,7 +86,8 @@ function useAgentMutations(options = {}) {
|
|
|
68
86
|
executeAgent,
|
|
69
87
|
createState,
|
|
70
88
|
updateState,
|
|
71
|
-
|
|
89
|
+
executeState,
|
|
90
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
72
91
|
};
|
|
73
92
|
}
|
|
74
93
|
export {
|
package/dist/node/ui/index.js
CHANGED
|
@@ -519,6 +519,11 @@ function useAgentMutations(options = {}) {
|
|
|
519
519
|
error: null,
|
|
520
520
|
data: null
|
|
521
521
|
});
|
|
522
|
+
const [executeState, setExecuteState] = useState4({
|
|
523
|
+
loading: false,
|
|
524
|
+
error: null,
|
|
525
|
+
data: null
|
|
526
|
+
});
|
|
522
527
|
const createAgent = useCallback4(async (input) => {
|
|
523
528
|
setCreateState({ loading: true, error: null, data: null });
|
|
524
529
|
try {
|
|
@@ -560,10 +565,23 @@ function useAgentMutations(options = {}) {
|
|
|
560
565
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
561
566
|
}, [updateAgent]);
|
|
562
567
|
const executeAgent = useCallback4(async (input) => {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
568
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
569
|
+
try {
|
|
570
|
+
const result = await agent.executeAgent({
|
|
571
|
+
agentId: input.agentId,
|
|
572
|
+
message: input.message,
|
|
573
|
+
context: { projectId, organizationId: "demo-org" }
|
|
574
|
+
});
|
|
575
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
576
|
+
options.onSuccess?.();
|
|
577
|
+
return result;
|
|
578
|
+
} catch (err) {
|
|
579
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
580
|
+
setExecuteState({ loading: false, error, data: null });
|
|
581
|
+
options.onError?.(error);
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
}, [agent, projectId, options]);
|
|
567
585
|
return {
|
|
568
586
|
createAgent,
|
|
569
587
|
updateAgent,
|
|
@@ -573,7 +591,8 @@ function useAgentMutations(options = {}) {
|
|
|
573
591
|
executeAgent,
|
|
574
592
|
createState,
|
|
575
593
|
updateState,
|
|
576
|
-
|
|
594
|
+
executeState,
|
|
595
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
577
596
|
};
|
|
578
597
|
}
|
|
579
598
|
|
|
@@ -520,6 +520,11 @@ function useAgentMutations(options = {}) {
|
|
|
520
520
|
error: null,
|
|
521
521
|
data: null
|
|
522
522
|
});
|
|
523
|
+
const [executeState, setExecuteState] = useState4({
|
|
524
|
+
loading: false,
|
|
525
|
+
error: null,
|
|
526
|
+
data: null
|
|
527
|
+
});
|
|
523
528
|
const createAgent = useCallback4(async (input) => {
|
|
524
529
|
setCreateState({ loading: true, error: null, data: null });
|
|
525
530
|
try {
|
|
@@ -561,10 +566,23 @@ function useAgentMutations(options = {}) {
|
|
|
561
566
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
562
567
|
}, [updateAgent]);
|
|
563
568
|
const executeAgent = useCallback4(async (input) => {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
569
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
570
|
+
try {
|
|
571
|
+
const result = await agent.executeAgent({
|
|
572
|
+
agentId: input.agentId,
|
|
573
|
+
message: input.message,
|
|
574
|
+
context: { projectId, organizationId: "demo-org" }
|
|
575
|
+
});
|
|
576
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
577
|
+
options.onSuccess?.();
|
|
578
|
+
return result;
|
|
579
|
+
} catch (err) {
|
|
580
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
581
|
+
setExecuteState({ loading: false, error, data: null });
|
|
582
|
+
options.onError?.(error);
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
}, [agent, projectId, options]);
|
|
568
586
|
return {
|
|
569
587
|
createAgent,
|
|
570
588
|
updateAgent,
|
|
@@ -574,7 +592,8 @@ function useAgentMutations(options = {}) {
|
|
|
574
592
|
executeAgent,
|
|
575
593
|
createState,
|
|
576
594
|
updateState,
|
|
577
|
-
|
|
595
|
+
executeState,
|
|
596
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
578
597
|
};
|
|
579
598
|
}
|
|
580
599
|
|
package/dist/ui/hooks/index.js
CHANGED
|
@@ -204,6 +204,11 @@ function useAgentMutations(options = {}) {
|
|
|
204
204
|
error: null,
|
|
205
205
|
data: null
|
|
206
206
|
});
|
|
207
|
+
const [executeState, setExecuteState] = useState4({
|
|
208
|
+
loading: false,
|
|
209
|
+
error: null,
|
|
210
|
+
data: null
|
|
211
|
+
});
|
|
207
212
|
const createAgent = useCallback4(async (input) => {
|
|
208
213
|
setCreateState({ loading: true, error: null, data: null });
|
|
209
214
|
try {
|
|
@@ -245,10 +250,23 @@ function useAgentMutations(options = {}) {
|
|
|
245
250
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
246
251
|
}, [updateAgent]);
|
|
247
252
|
const executeAgent = useCallback4(async (input) => {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
253
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
254
|
+
try {
|
|
255
|
+
const result = await agent.executeAgent({
|
|
256
|
+
agentId: input.agentId,
|
|
257
|
+
message: input.message,
|
|
258
|
+
context: { projectId, organizationId: "demo-org" }
|
|
259
|
+
});
|
|
260
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
261
|
+
options.onSuccess?.();
|
|
262
|
+
return result;
|
|
263
|
+
} catch (err) {
|
|
264
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
265
|
+
setExecuteState({ loading: false, error, data: null });
|
|
266
|
+
options.onError?.(error);
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}, [agent, projectId, options]);
|
|
252
270
|
return {
|
|
253
271
|
createAgent,
|
|
254
272
|
updateAgent,
|
|
@@ -258,7 +276,8 @@ function useAgentMutations(options = {}) {
|
|
|
258
276
|
executeAgent,
|
|
259
277
|
createState,
|
|
260
278
|
updateState,
|
|
261
|
-
|
|
279
|
+
executeState,
|
|
280
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
262
281
|
};
|
|
263
282
|
}
|
|
264
283
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Agent, CreateAgentInput, UpdateAgentInput } from '../../handlers/agent.handlers';
|
|
1
|
+
import type { Agent, Run, CreateAgentInput, UpdateAgentInput } from '../../handlers/agent.handlers';
|
|
2
2
|
export interface MutationState<T> {
|
|
3
3
|
loading: boolean;
|
|
4
4
|
error: Error | null;
|
|
@@ -17,9 +17,10 @@ export declare function useAgentMutations(options?: UseAgentMutationsOptions): {
|
|
|
17
17
|
executeAgent: (input: {
|
|
18
18
|
agentId: string;
|
|
19
19
|
message: string;
|
|
20
|
-
}) => Promise<null>;
|
|
20
|
+
}) => Promise<Run | null>;
|
|
21
21
|
createState: MutationState<Agent>;
|
|
22
22
|
updateState: MutationState<Agent>;
|
|
23
|
+
executeState: MutationState<Run>;
|
|
23
24
|
isLoading: boolean;
|
|
24
25
|
};
|
|
25
|
-
export type { CreateAgentInput, UpdateAgentInput, Agent };
|
|
26
|
+
export type { CreateAgentInput, UpdateAgentInput, Agent, Run };
|
|
@@ -15,6 +15,11 @@ function useAgentMutations(options = {}) {
|
|
|
15
15
|
error: null,
|
|
16
16
|
data: null
|
|
17
17
|
});
|
|
18
|
+
const [executeState, setExecuteState] = useState({
|
|
19
|
+
loading: false,
|
|
20
|
+
error: null,
|
|
21
|
+
data: null
|
|
22
|
+
});
|
|
18
23
|
const createAgent = useCallback(async (input) => {
|
|
19
24
|
setCreateState({ loading: true, error: null, data: null });
|
|
20
25
|
try {
|
|
@@ -56,10 +61,23 @@ function useAgentMutations(options = {}) {
|
|
|
56
61
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
57
62
|
}, [updateAgent]);
|
|
58
63
|
const executeAgent = useCallback(async (input) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
setExecuteState({ loading: true, error: null, data: null });
|
|
65
|
+
try {
|
|
66
|
+
const result = await agent.executeAgent({
|
|
67
|
+
agentId: input.agentId,
|
|
68
|
+
message: input.message,
|
|
69
|
+
context: { projectId, organizationId: "demo-org" }
|
|
70
|
+
});
|
|
71
|
+
setExecuteState({ loading: false, error: null, data: result });
|
|
72
|
+
options.onSuccess?.();
|
|
73
|
+
return result;
|
|
74
|
+
} catch (err) {
|
|
75
|
+
const error = err instanceof Error ? err : new Error("Failed to execute agent");
|
|
76
|
+
setExecuteState({ loading: false, error, data: null });
|
|
77
|
+
options.onError?.(error);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}, [agent, projectId, options]);
|
|
63
81
|
return {
|
|
64
82
|
createAgent,
|
|
65
83
|
updateAgent,
|
|
@@ -69,7 +87,8 @@ function useAgentMutations(options = {}) {
|
|
|
69
87
|
executeAgent,
|
|
70
88
|
createState,
|
|
71
89
|
updateState,
|
|
72
|
-
|
|
90
|
+
executeState,
|
|
91
|
+
isLoading: createState.loading || updateState.loading || executeState.loading
|
|
73
92
|
};
|
|
74
93
|
}
|
|
75
94
|
export {
|