@cuylabs/agent-runtime-dapr 0.10.0 → 0.12.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/dist/{chunk-YS2CWYBQ.js → chunk-2TBZCBXE.js} +20 -23
- package/dist/{chunk-YQQTUE6B.js → chunk-6BLY7B7U.js} +41 -31
- package/dist/{chunk-MJKJT3ZO.js → chunk-EJBODJQR.js} +395 -278
- package/dist/{chunk-MQJ4LZOX.js → chunk-HQLQRXU5.js} +6 -3
- package/dist/{chunk-5CJIC4YB.js → chunk-VKPTE4J6.js} +28 -10
- package/dist/dispatch/index.d.ts +2 -2
- package/dist/dispatch/index.js +2 -2
- package/dist/execution/index.js +2 -2
- package/dist/host/index.d.ts +2 -2
- package/dist/host/index.js +5 -5
- package/dist/{index-BmM58WZa.d.ts → index-BY0FipV1.d.ts} +3 -5
- package/dist/{index-BEOwKSPI.d.ts → index-UtePd9on.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/{invoker-B1jvz9DG.d.ts → invoker-B6ikdYaz.d.ts} +2 -4
- package/dist/team/index.js +5 -5
- package/dist/workflow/index.js +2 -2
- package/package.json +4 -4
|
@@ -5,23 +5,23 @@ import {
|
|
|
5
5
|
createWorkflowDispatchTarget,
|
|
6
6
|
invokeRemoteAgentRun,
|
|
7
7
|
readWorkflowCompletion
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-6BLY7B7U.js";
|
|
9
9
|
import {
|
|
10
10
|
DaprExecutionStore,
|
|
11
11
|
createDaprExecutionObserver,
|
|
12
12
|
createDaprLoggingObserver,
|
|
13
13
|
createWorkflowObserverBridge
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-VKPTE4J6.js";
|
|
15
15
|
import {
|
|
16
16
|
DaprWorkflowClient,
|
|
17
17
|
createDaprAgentTurnWorkflowKit,
|
|
18
18
|
isTerminalDaprWorkflowStatus
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-2TBZCBXE.js";
|
|
20
20
|
import {
|
|
21
21
|
DaprSidecarClient,
|
|
22
22
|
__export,
|
|
23
23
|
isDaprConflictError
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-HQLQRXU5.js";
|
|
25
25
|
|
|
26
26
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
27
27
|
var external_exports = {};
|
|
@@ -4082,11 +4082,10 @@ function formatRemoteResult(name, appId, response, sessionId) {
|
|
|
4082
4082
|
};
|
|
4083
4083
|
}
|
|
4084
4084
|
async function executeDirect(invoker, appId, name, message, sessionId) {
|
|
4085
|
-
const response = await invokeRemoteAgentRun(
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
);
|
|
4085
|
+
const response = await invokeRemoteAgentRun(invoker, appId, {
|
|
4086
|
+
message,
|
|
4087
|
+
...sessionId ? { sessionId } : {}
|
|
4088
|
+
});
|
|
4090
4089
|
return formatRemoteResult(name, appId, response, sessionId);
|
|
4091
4090
|
}
|
|
4092
4091
|
async function startRemoteWorkflow(invoker, appId, message, sessionId) {
|
|
@@ -4139,12 +4138,7 @@ async function fetchExecutionResult(invoker, appId, agentId, sessionId) {
|
|
|
4139
4138
|
return result.data;
|
|
4140
4139
|
}
|
|
4141
4140
|
async function executeWorkflow(invoker, appId, name, message, pollIntervalMs, timeoutMs, sessionId) {
|
|
4142
|
-
const started = await startRemoteWorkflow(
|
|
4143
|
-
invoker,
|
|
4144
|
-
appId,
|
|
4145
|
-
message,
|
|
4146
|
-
sessionId
|
|
4147
|
-
);
|
|
4141
|
+
const started = await startRemoteWorkflow(invoker, appId, message, sessionId);
|
|
4148
4142
|
const agentId = started.agentId ?? name;
|
|
4149
4143
|
const finalState = await pollWorkflowCompletion(
|
|
4150
4144
|
invoker,
|
|
@@ -4499,7 +4493,9 @@ function createDaprWorkflowApprovalRuntime(options) {
|
|
|
4499
4493
|
if (!strict) {
|
|
4500
4494
|
return void 0;
|
|
4501
4495
|
}
|
|
4502
|
-
throw new Error(
|
|
4496
|
+
throw new Error(
|
|
4497
|
+
`Approval request does not belong to agent: ${requestId}`
|
|
4498
|
+
);
|
|
4503
4499
|
}
|
|
4504
4500
|
if (record.status !== "pending") {
|
|
4505
4501
|
if (!strict) {
|
|
@@ -4703,7 +4699,9 @@ function createDaprWorkflowHumanInputRuntime(options) {
|
|
|
4703
4699
|
}
|
|
4704
4700
|
let parsed;
|
|
4705
4701
|
try {
|
|
4706
|
-
parsed = initialized.parameters.parse(
|
|
4702
|
+
parsed = initialized.parameters.parse(
|
|
4703
|
+
input.toolCall.args
|
|
4704
|
+
);
|
|
4707
4705
|
} catch (error) {
|
|
4708
4706
|
return {
|
|
4709
4707
|
action: "deny",
|
|
@@ -4763,26 +4761,28 @@ function createDaprWorkflowHumanInputRuntime(options) {
|
|
|
4763
4761
|
response: structuredClone(response)
|
|
4764
4762
|
};
|
|
4765
4763
|
try {
|
|
4766
|
-
await client.saveState(
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
{
|
|
4770
|
-
...current.etag ? { etag: current.etag, concurrency: "first-write" } : {}
|
|
4771
|
-
}
|
|
4772
|
-
);
|
|
4764
|
+
await client.saveState(requestKey(requestId), toStoredRecord2(next), {
|
|
4765
|
+
...current.etag ? { etag: current.etag, concurrency: "first-write" } : {}
|
|
4766
|
+
});
|
|
4773
4767
|
} catch (error) {
|
|
4774
4768
|
if (!isDaprConflictError(error)) {
|
|
4775
4769
|
throw error;
|
|
4776
4770
|
}
|
|
4777
4771
|
const latest = await getRequest(requestId);
|
|
4778
4772
|
if (!latest) {
|
|
4779
|
-
throw new Error(
|
|
4773
|
+
throw new Error(
|
|
4774
|
+
`Human input request not found after conflict: ${requestId}`
|
|
4775
|
+
);
|
|
4780
4776
|
}
|
|
4781
4777
|
return latest;
|
|
4782
4778
|
}
|
|
4783
|
-
await workflowClient.raiseWorkflowEvent(
|
|
4784
|
-
|
|
4785
|
-
|
|
4779
|
+
await workflowClient.raiseWorkflowEvent(
|
|
4780
|
+
next.workflowInstanceId,
|
|
4781
|
+
`human-input:${requestId}`,
|
|
4782
|
+
{
|
|
4783
|
+
eventData: response
|
|
4784
|
+
}
|
|
4785
|
+
);
|
|
4786
4786
|
await publishEvent(next.sessionId, {
|
|
4787
4787
|
type: "human-input-resolved",
|
|
4788
4788
|
id: requestId,
|
|
@@ -4881,7 +4881,13 @@ function createDaprWorkflowSteerRuntime(options) {
|
|
|
4881
4881
|
};
|
|
4882
4882
|
}
|
|
4883
4883
|
return {
|
|
4884
|
-
ids: [
|
|
4884
|
+
ids: [
|
|
4885
|
+
...new Set(
|
|
4886
|
+
entry.value.filter(
|
|
4887
|
+
(item) => typeof item === "string"
|
|
4888
|
+
)
|
|
4889
|
+
)
|
|
4890
|
+
],
|
|
4885
4891
|
etag: entry.etag,
|
|
4886
4892
|
exists: true
|
|
4887
4893
|
};
|
|
@@ -4942,7 +4948,11 @@ function createDaprWorkflowSteerRuntime(options) {
|
|
|
4942
4948
|
}
|
|
4943
4949
|
}
|
|
4944
4950
|
if (presentIds.length !== (current.ids ?? []).length) {
|
|
4945
|
-
await writeWorkflowIndex(
|
|
4951
|
+
await writeWorkflowIndex(
|
|
4952
|
+
workflowInstanceId,
|
|
4953
|
+
presentIds,
|
|
4954
|
+
current.etag
|
|
4955
|
+
).catch(() => {
|
|
4946
4956
|
});
|
|
4947
4957
|
}
|
|
4948
4958
|
return records;
|
|
@@ -5102,14 +5112,10 @@ function createDaprWorkflowFollowUpRuntime(options) {
|
|
|
5102
5112
|
};
|
|
5103
5113
|
}
|
|
5104
5114
|
async function saveRecord(record, etag) {
|
|
5105
|
-
await client.saveState(
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
...etag ? { etag } : {},
|
|
5110
|
-
concurrency: "first-write"
|
|
5111
|
-
}
|
|
5112
|
-
);
|
|
5115
|
+
await client.saveState(requestKey(record.id), toStoredRecord4(record), {
|
|
5116
|
+
...etag ? { etag } : {},
|
|
5117
|
+
concurrency: "first-write"
|
|
5118
|
+
});
|
|
5113
5119
|
}
|
|
5114
5120
|
async function readIndex(key) {
|
|
5115
5121
|
const entry = await client.getStateEntry(key);
|
|
@@ -5124,7 +5130,13 @@ function createDaprWorkflowFollowUpRuntime(options) {
|
|
|
5124
5130
|
};
|
|
5125
5131
|
}
|
|
5126
5132
|
return {
|
|
5127
|
-
ids: [
|
|
5133
|
+
ids: [
|
|
5134
|
+
...new Set(
|
|
5135
|
+
entry.value.filter(
|
|
5136
|
+
(item) => typeof item === "string"
|
|
5137
|
+
)
|
|
5138
|
+
)
|
|
5139
|
+
],
|
|
5128
5140
|
etag: entry.etag,
|
|
5129
5141
|
exists: true
|
|
5130
5142
|
};
|
|
@@ -5248,7 +5260,9 @@ function createDaprWorkflowFollowUpRuntime(options) {
|
|
|
5248
5260
|
await saveRecord(next, etag);
|
|
5249
5261
|
} catch (error) {
|
|
5250
5262
|
if (isDaprConflictError(error)) {
|
|
5251
|
-
throw new Error(
|
|
5263
|
+
throw new Error(
|
|
5264
|
+
`Follow-up request changed concurrently: ${requestId}`
|
|
5265
|
+
);
|
|
5252
5266
|
}
|
|
5253
5267
|
throw error;
|
|
5254
5268
|
}
|
|
@@ -5286,6 +5300,7 @@ function createDaprWorkflowFollowUpRuntime(options) {
|
|
|
5286
5300
|
|
|
5287
5301
|
// src/host/workflow/workflow-host.ts
|
|
5288
5302
|
import { randomUUID } from "crypto";
|
|
5303
|
+
import process2 from "process";
|
|
5289
5304
|
import {
|
|
5290
5305
|
MiddlewareRunner,
|
|
5291
5306
|
SessionManager,
|
|
@@ -5310,9 +5325,18 @@ function normalizeStatus(value, fallback) {
|
|
|
5310
5325
|
return normalized;
|
|
5311
5326
|
}
|
|
5312
5327
|
function createDaprHttpJobHandler(options) {
|
|
5313
|
-
const handledStatus = normalizeStatus(
|
|
5314
|
-
|
|
5315
|
-
|
|
5328
|
+
const handledStatus = normalizeStatus(
|
|
5329
|
+
options.handledStatus,
|
|
5330
|
+
DEFAULT_HANDLED_STATUS
|
|
5331
|
+
);
|
|
5332
|
+
const unhandledStatus = normalizeStatus(
|
|
5333
|
+
options.unhandledStatus,
|
|
5334
|
+
DEFAULT_UNHANDLED_STATUS
|
|
5335
|
+
);
|
|
5336
|
+
const errorStatus = normalizeStatus(
|
|
5337
|
+
options.errorStatus,
|
|
5338
|
+
DEFAULT_ERROR_STATUS
|
|
5339
|
+
);
|
|
5316
5340
|
return async (jobName) => {
|
|
5317
5341
|
const normalizedJobName = String(jobName).trim();
|
|
5318
5342
|
if (!normalizedJobName) {
|
|
@@ -5356,7 +5380,9 @@ function normalizeDaprCronExpression(expr) {
|
|
|
5356
5380
|
if (parts.length === 6) {
|
|
5357
5381
|
return parts.join(" ");
|
|
5358
5382
|
}
|
|
5359
|
-
throw new Error(
|
|
5383
|
+
throw new Error(
|
|
5384
|
+
`Dapr cron schedules must have 5 or 6 fields. Received: ${expr}`
|
|
5385
|
+
);
|
|
5360
5386
|
}
|
|
5361
5387
|
var DaprJobsApi = class {
|
|
5362
5388
|
client;
|
|
@@ -5389,16 +5415,24 @@ var DaprJobsApi = class {
|
|
|
5389
5415
|
}
|
|
5390
5416
|
const payload = this.toSchedulePayload(job);
|
|
5391
5417
|
const name = this.toDaprJobName(job.id);
|
|
5392
|
-
await this.client.requestJson(
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5418
|
+
await this.client.requestJson(
|
|
5419
|
+
`/v1.0-alpha1/jobs/${encodeURIComponent(name)}`,
|
|
5420
|
+
{
|
|
5421
|
+
method: "POST",
|
|
5422
|
+
body: JSON.stringify(payload)
|
|
5423
|
+
},
|
|
5424
|
+
[200, 201, 204]
|
|
5425
|
+
);
|
|
5396
5426
|
}
|
|
5397
5427
|
async deleteJob(jobId) {
|
|
5398
5428
|
const name = this.toDaprJobName(jobId);
|
|
5399
|
-
await this.client.requestJson(
|
|
5400
|
-
|
|
5401
|
-
|
|
5429
|
+
await this.client.requestJson(
|
|
5430
|
+
`/v1.0-alpha1/jobs/${encodeURIComponent(name)}`,
|
|
5431
|
+
{
|
|
5432
|
+
method: "DELETE"
|
|
5433
|
+
},
|
|
5434
|
+
[200, 204, 404]
|
|
5435
|
+
);
|
|
5402
5436
|
}
|
|
5403
5437
|
toSchedulePayload(job) {
|
|
5404
5438
|
const payload = {
|
|
@@ -5423,9 +5457,13 @@ var DaprJobsApi = class {
|
|
|
5423
5457
|
return payload;
|
|
5424
5458
|
}
|
|
5425
5459
|
if (job.schedule.kind !== "cron") {
|
|
5426
|
-
throw new Error(
|
|
5460
|
+
throw new Error(
|
|
5461
|
+
`Unsupported schedule kind: ${String(job.schedule.kind)}`
|
|
5462
|
+
);
|
|
5427
5463
|
}
|
|
5428
|
-
if (job.schedule.timezone && !["UTC", "ETC/UTC", "Z"].includes(
|
|
5464
|
+
if (job.schedule.timezone && !["UTC", "ETC/UTC", "Z"].includes(
|
|
5465
|
+
job.schedule.timezone.trim().toUpperCase()
|
|
5466
|
+
)) {
|
|
5429
5467
|
throw new Error(
|
|
5430
5468
|
`Dapr jobs API does not expose timezone selection for cron schedules (received: ${job.schedule.timezone})`
|
|
5431
5469
|
);
|
|
@@ -5459,7 +5497,10 @@ var DaprRuntimeDriver = class {
|
|
|
5459
5497
|
started = false;
|
|
5460
5498
|
constructor(options) {
|
|
5461
5499
|
this.client = new DaprSidecarClient(options);
|
|
5462
|
-
this.keyPrefix = ensureNonEmpty5(
|
|
5500
|
+
this.keyPrefix = ensureNonEmpty5(
|
|
5501
|
+
options.keyPrefix ?? DEFAULT_KEY_PREFIX5,
|
|
5502
|
+
"keyPrefix"
|
|
5503
|
+
);
|
|
5463
5504
|
this.jobsApi = new DaprJobsApi({
|
|
5464
5505
|
client: this.client,
|
|
5465
5506
|
jobNamePrefix: ensureNonEmpty5(
|
|
@@ -5552,7 +5593,9 @@ var DaprRuntimeDriver = class {
|
|
|
5552
5593
|
return `${this.keyPrefix}jobs/${jobId}`;
|
|
5553
5594
|
}
|
|
5554
5595
|
async readJob(jobId) {
|
|
5555
|
-
const value = await this.client.getState(
|
|
5596
|
+
const value = await this.client.getState(
|
|
5597
|
+
this.stateKeyForJob(jobId)
|
|
5598
|
+
);
|
|
5556
5599
|
if (!value || typeof value !== "object") {
|
|
5557
5600
|
return void 0;
|
|
5558
5601
|
}
|
|
@@ -5641,7 +5684,10 @@ var DaprOrchestratorRunStore = class {
|
|
|
5641
5684
|
keyPrefix;
|
|
5642
5685
|
constructor(options) {
|
|
5643
5686
|
this.client = new DaprSidecarClient(options);
|
|
5644
|
-
this.keyPrefix = ensureNonEmpty6(
|
|
5687
|
+
this.keyPrefix = ensureNonEmpty6(
|
|
5688
|
+
options.keyPrefix ?? DEFAULT_KEY_PREFIX6,
|
|
5689
|
+
"keyPrefix"
|
|
5690
|
+
);
|
|
5645
5691
|
}
|
|
5646
5692
|
async start() {
|
|
5647
5693
|
await this.client.verifySidecar();
|
|
@@ -5716,7 +5762,9 @@ var DaprOrchestratorRunStore = class {
|
|
|
5716
5762
|
return `${this.keyPrefix}runs/${runId}`;
|
|
5717
5763
|
}
|
|
5718
5764
|
async readRun(runId) {
|
|
5719
|
-
const value = await this.client.getState(
|
|
5765
|
+
const value = await this.client.getState(
|
|
5766
|
+
this.stateKeyForRun(runId)
|
|
5767
|
+
);
|
|
5720
5768
|
if (!value || typeof value !== "object") {
|
|
5721
5769
|
return void 0;
|
|
5722
5770
|
}
|
|
@@ -5882,10 +5930,7 @@ function installDaprSubAgents(options) {
|
|
|
5882
5930
|
}
|
|
5883
5931
|
|
|
5884
5932
|
// src/subagents/host-graph.ts
|
|
5885
|
-
import {
|
|
5886
|
-
DEFAULT_SUBAGENT_DEPTH as DEFAULT_SUBAGENT_DEPTH2,
|
|
5887
|
-
SUBAGENT_TOOL_IDS
|
|
5888
|
-
} from "@cuylabs/agent-core";
|
|
5933
|
+
import { DEFAULT_SUBAGENT_DEPTH as DEFAULT_SUBAGENT_DEPTH2, SUBAGENT_TOOL_IDS } from "@cuylabs/agent-core";
|
|
5889
5934
|
|
|
5890
5935
|
// src/host/hosted-agent.ts
|
|
5891
5936
|
function createDaprHostedAgentBundle(options) {
|
|
@@ -6209,7 +6254,9 @@ function flattenHostedSubagentEntries(entries) {
|
|
|
6209
6254
|
}
|
|
6210
6255
|
function toWorkflowHostMap(entries) {
|
|
6211
6256
|
return new Map(
|
|
6212
|
-
entries.map(
|
|
6257
|
+
entries.map(
|
|
6258
|
+
(entry) => [entry.role.name, entry.bundle.workflowHost]
|
|
6259
|
+
)
|
|
6213
6260
|
);
|
|
6214
6261
|
}
|
|
6215
6262
|
function resolvedSubagentConfig(config, currentDepth, maxDepth) {
|
|
@@ -6255,7 +6302,11 @@ function wireDaprHostedSubagentGraph(options) {
|
|
|
6255
6302
|
...children.length > 0 && (options.config.mode ?? "child-workflow") === "child-workflow" ? createDaprSubAgentWorkflowSupport({
|
|
6256
6303
|
workflowName: `${id}:turn`,
|
|
6257
6304
|
agentId: id,
|
|
6258
|
-
config: resolvedSubagentConfig(
|
|
6305
|
+
config: resolvedSubagentConfig(
|
|
6306
|
+
options.config,
|
|
6307
|
+
childDepth,
|
|
6308
|
+
maxDepth
|
|
6309
|
+
),
|
|
6259
6310
|
roles: options.config.roles,
|
|
6260
6311
|
workflowHosts: toWorkflowHostMap(children),
|
|
6261
6312
|
stateStoreName: options.runtime.stateStoreName,
|
|
@@ -6342,7 +6393,9 @@ var DaprTaskBoardStore = class {
|
|
|
6342
6393
|
if (ids.length === 0) return [];
|
|
6343
6394
|
const members = [];
|
|
6344
6395
|
for (const id of ids) {
|
|
6345
|
-
const entry = await this.client.getStateEntry(
|
|
6396
|
+
const entry = await this.client.getStateEntry(
|
|
6397
|
+
this.memberKey(id)
|
|
6398
|
+
);
|
|
6346
6399
|
if (entry.value) {
|
|
6347
6400
|
this.memberEtags.set(id, entry.etag);
|
|
6348
6401
|
members.push(entry.value);
|
|
@@ -6351,7 +6404,9 @@ var DaprTaskBoardStore = class {
|
|
|
6351
6404
|
return members;
|
|
6352
6405
|
}
|
|
6353
6406
|
async getMember(memberId) {
|
|
6354
|
-
const entry = await this.client.getStateEntry(
|
|
6407
|
+
const entry = await this.client.getStateEntry(
|
|
6408
|
+
this.memberKey(memberId)
|
|
6409
|
+
);
|
|
6355
6410
|
this.memberEtags.set(memberId, entry.etag);
|
|
6356
6411
|
return entry.value;
|
|
6357
6412
|
}
|
|
@@ -6365,7 +6420,10 @@ var DaprTaskBoardStore = class {
|
|
|
6365
6420
|
} catch (error) {
|
|
6366
6421
|
this.memberEtags.delete(member.id);
|
|
6367
6422
|
if (isDaprConflictError(error)) {
|
|
6368
|
-
throw new TaskConflictError(
|
|
6423
|
+
throw new TaskConflictError(
|
|
6424
|
+
`Concurrent member update conflict: ${member.id}`,
|
|
6425
|
+
member.id
|
|
6426
|
+
);
|
|
6369
6427
|
}
|
|
6370
6428
|
throw error;
|
|
6371
6429
|
}
|
|
@@ -6398,7 +6456,9 @@ var DaprTaskBoardStore = class {
|
|
|
6398
6456
|
return tasks;
|
|
6399
6457
|
}
|
|
6400
6458
|
async getTask(taskId) {
|
|
6401
|
-
const entry = await this.client.getStateEntry(
|
|
6459
|
+
const entry = await this.client.getStateEntry(
|
|
6460
|
+
this.taskKey(taskId)
|
|
6461
|
+
);
|
|
6402
6462
|
this.taskEtags.set(taskId, entry.etag);
|
|
6403
6463
|
return entry.value;
|
|
6404
6464
|
}
|
|
@@ -6412,7 +6472,10 @@ var DaprTaskBoardStore = class {
|
|
|
6412
6472
|
} catch (error) {
|
|
6413
6473
|
this.taskEtags.delete(task.id);
|
|
6414
6474
|
if (isDaprConflictError(error)) {
|
|
6415
|
-
throw new TaskConflictError(
|
|
6475
|
+
throw new TaskConflictError(
|
|
6476
|
+
`Concurrent task update conflict: ${task.id}`,
|
|
6477
|
+
task.id
|
|
6478
|
+
);
|
|
6416
6479
|
}
|
|
6417
6480
|
throw error;
|
|
6418
6481
|
}
|
|
@@ -6424,7 +6487,9 @@ var DaprTaskBoardStore = class {
|
|
|
6424
6487
|
if (this.memberEtags.has(memberId)) {
|
|
6425
6488
|
return this.memberEtags.get(memberId);
|
|
6426
6489
|
}
|
|
6427
|
-
const entry = await this.client.getStateEntry(
|
|
6490
|
+
const entry = await this.client.getStateEntry(
|
|
6491
|
+
this.memberKey(memberId)
|
|
6492
|
+
);
|
|
6428
6493
|
this.memberEtags.set(memberId, entry.etag);
|
|
6429
6494
|
return entry.etag;
|
|
6430
6495
|
}
|
|
@@ -6432,7 +6497,9 @@ var DaprTaskBoardStore = class {
|
|
|
6432
6497
|
if (this.taskEtags.has(taskId)) {
|
|
6433
6498
|
return this.taskEtags.get(taskId);
|
|
6434
6499
|
}
|
|
6435
|
-
const entry = await this.client.getStateEntry(
|
|
6500
|
+
const entry = await this.client.getStateEntry(
|
|
6501
|
+
this.taskKey(taskId)
|
|
6502
|
+
);
|
|
6436
6503
|
this.taskEtags.set(taskId, entry.etag);
|
|
6437
6504
|
return entry.etag;
|
|
6438
6505
|
}
|
|
@@ -6441,11 +6508,7 @@ var DaprTaskBoardStore = class {
|
|
|
6441
6508
|
const entry = await this.client.getStateEntry(key);
|
|
6442
6509
|
if (!Array.isArray(entry.value)) return [];
|
|
6443
6510
|
return [
|
|
6444
|
-
...new Set(
|
|
6445
|
-
entry.value.filter(
|
|
6446
|
-
(v) => typeof v === "string"
|
|
6447
|
-
)
|
|
6448
|
-
)
|
|
6511
|
+
...new Set(entry.value.filter((v) => typeof v === "string"))
|
|
6449
6512
|
];
|
|
6450
6513
|
}
|
|
6451
6514
|
async addToIndex(key, id) {
|
|
@@ -6459,9 +6522,7 @@ var DaprTaskBoardStore = class {
|
|
|
6459
6522
|
const current = await this.client.getStateEntry(key);
|
|
6460
6523
|
const ids = Array.isArray(current.value) ? [
|
|
6461
6524
|
...new Set(
|
|
6462
|
-
current.value.filter(
|
|
6463
|
-
(v) => typeof v === "string"
|
|
6464
|
-
)
|
|
6525
|
+
current.value.filter((v) => typeof v === "string")
|
|
6465
6526
|
)
|
|
6466
6527
|
] : [];
|
|
6467
6528
|
const next = updater(ids);
|
|
@@ -6512,14 +6573,10 @@ var DaprMailboxStore = class {
|
|
|
6512
6573
|
if (ids.length === 0) return [];
|
|
6513
6574
|
let messages = [];
|
|
6514
6575
|
for (const id of ids) {
|
|
6515
|
-
const msg = await this.client.getState(
|
|
6516
|
-
this.messageKey(id)
|
|
6517
|
-
);
|
|
6576
|
+
const msg = await this.client.getState(this.messageKey(id));
|
|
6518
6577
|
if (msg) messages.push(msg);
|
|
6519
6578
|
}
|
|
6520
|
-
messages.sort(
|
|
6521
|
-
(a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt)
|
|
6522
|
-
);
|
|
6579
|
+
messages.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
|
|
6523
6580
|
if (filter?.teamId) {
|
|
6524
6581
|
messages = messages.filter((m) => m.teamId === filter.teamId);
|
|
6525
6582
|
}
|
|
@@ -6548,11 +6605,7 @@ var DaprMailboxStore = class {
|
|
|
6548
6605
|
);
|
|
6549
6606
|
if (!Array.isArray(entry.value)) return [];
|
|
6550
6607
|
return [
|
|
6551
|
-
...new Set(
|
|
6552
|
-
entry.value.filter(
|
|
6553
|
-
(v) => typeof v === "string"
|
|
6554
|
-
)
|
|
6555
|
-
)
|
|
6608
|
+
...new Set(entry.value.filter((v) => typeof v === "string"))
|
|
6556
6609
|
];
|
|
6557
6610
|
}
|
|
6558
6611
|
async addToIndex(id) {
|
|
@@ -6568,9 +6621,7 @@ var DaprMailboxStore = class {
|
|
|
6568
6621
|
);
|
|
6569
6622
|
const ids = Array.isArray(current.value) ? [
|
|
6570
6623
|
...new Set(
|
|
6571
|
-
current.value.filter(
|
|
6572
|
-
(v) => typeof v === "string"
|
|
6573
|
-
)
|
|
6624
|
+
current.value.filter((v) => typeof v === "string")
|
|
6574
6625
|
)
|
|
6575
6626
|
] : [];
|
|
6576
6627
|
const next = updater(ids);
|
|
@@ -6673,7 +6724,10 @@ function createCoordinatorWorkflowDefinition(options) {
|
|
|
6673
6724
|
},
|
|
6674
6725
|
launch.runId
|
|
6675
6726
|
);
|
|
6676
|
-
activeChildren.set(launch.taskId, {
|
|
6727
|
+
activeChildren.set(launch.taskId, {
|
|
6728
|
+
handle: childHandle,
|
|
6729
|
+
meta: launch
|
|
6730
|
+
});
|
|
6677
6731
|
}
|
|
6678
6732
|
}
|
|
6679
6733
|
const round = {
|
|
@@ -6691,7 +6745,7 @@ function createCoordinatorWorkflowDefinition(options) {
|
|
|
6691
6745
|
response: reasonResult.response,
|
|
6692
6746
|
usage: reasonResult.usage
|
|
6693
6747
|
};
|
|
6694
|
-
|
|
6748
|
+
const notifications = [...applied.notifications];
|
|
6695
6749
|
let reports = [];
|
|
6696
6750
|
if (notifications.length === 0) {
|
|
6697
6751
|
const reportBatch = yield ctx.callActivity(
|
|
@@ -6712,9 +6766,13 @@ function createCoordinatorWorkflowDefinition(options) {
|
|
|
6712
6766
|
const reportEvent = ctx.waitForExternalEvent(
|
|
6713
6767
|
"worker-report"
|
|
6714
6768
|
);
|
|
6715
|
-
const timeout = ctx.createTimer(
|
|
6769
|
+
const timeout = ctx.createTimer(
|
|
6770
|
+
new Date(Date.now() + input.waitTimeoutMs)
|
|
6771
|
+
);
|
|
6716
6772
|
const waitingOn = [
|
|
6717
|
-
...[...activeChildren.values()].map(
|
|
6773
|
+
...[...activeChildren.values()].map(
|
|
6774
|
+
(entry) => entry.handle
|
|
6775
|
+
),
|
|
6718
6776
|
reportEvent,
|
|
6719
6777
|
timeout
|
|
6720
6778
|
];
|
|
@@ -6782,7 +6840,10 @@ function createCoordinatorWorkflowDefinition(options) {
|
|
|
6782
6840
|
},
|
|
6783
6841
|
launch.runId
|
|
6784
6842
|
);
|
|
6785
|
-
activeChildren.set(launch.taskId, {
|
|
6843
|
+
activeChildren.set(launch.taskId, {
|
|
6844
|
+
handle: childHandle,
|
|
6845
|
+
meta: launch
|
|
6846
|
+
});
|
|
6786
6847
|
}
|
|
6787
6848
|
}
|
|
6788
6849
|
const reportBatch = yield ctx.callActivity(
|
|
@@ -6803,10 +6864,9 @@ function createCoordinatorWorkflowDefinition(options) {
|
|
|
6803
6864
|
error: notification.error
|
|
6804
6865
|
}));
|
|
6805
6866
|
rounds.push(round);
|
|
6806
|
-
const terminalAfterEvent = trackedTaskIds.size === 0 ? true : yield ctx.callActivity(
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
);
|
|
6867
|
+
const terminalAfterEvent = trackedTaskIds.size === 0 ? true : yield ctx.callActivity(activityNames.checkTrackedTasksTerminal, {
|
|
6868
|
+
taskIds: [...trackedTaskIds]
|
|
6869
|
+
});
|
|
6810
6870
|
const transition = evaluateCoordinatorRoundTransition({
|
|
6811
6871
|
reasonAssignmentsCount: reasonResult.assignments.length,
|
|
6812
6872
|
activeTaskCount: activeChildren.size,
|
|
@@ -6818,7 +6878,11 @@ function createCoordinatorWorkflowDefinition(options) {
|
|
|
6818
6878
|
blockedMessage: "No runnable tasks remain. Review blocked work, abort stale tasks, or provide the final response."
|
|
6819
6879
|
});
|
|
6820
6880
|
if (transition.kind === "done") {
|
|
6821
|
-
return {
|
|
6881
|
+
return {
|
|
6882
|
+
response: transition.finalResponse,
|
|
6883
|
+
rounds,
|
|
6884
|
+
usage: totalUsage
|
|
6885
|
+
};
|
|
6822
6886
|
}
|
|
6823
6887
|
message = transition.nextMessage;
|
|
6824
6888
|
}
|
|
@@ -6862,9 +6926,7 @@ function createRecordingTools(members, actions, assignments, messages, aborts, n
|
|
|
6862
6926
|
prompt: external_exports.string().describe(
|
|
6863
6927
|
"Self-contained task prompt with all context the teammate needs"
|
|
6864
6928
|
),
|
|
6865
|
-
dependsOn: external_exports.array(external_exports.string()).optional().describe(
|
|
6866
|
-
"Task IDs this task must wait for before starting."
|
|
6867
|
-
)
|
|
6929
|
+
dependsOn: external_exports.array(external_exports.string()).optional().describe("Task IDs this task must wait for before starting.")
|
|
6868
6930
|
}),
|
|
6869
6931
|
execute: async (params) => {
|
|
6870
6932
|
const taskId = nextTaskId();
|
|
@@ -6934,11 +6996,7 @@ function createRecordingTools(members, actions, assignments, messages, aborts, n
|
|
|
6934
6996
|
return [assignTask, sendMessage, abortTask];
|
|
6935
6997
|
}
|
|
6936
6998
|
function createCoordinatorReasonActivity(options) {
|
|
6937
|
-
const {
|
|
6938
|
-
lead,
|
|
6939
|
-
coordinator,
|
|
6940
|
-
onCoordinatorEvent
|
|
6941
|
-
} = options;
|
|
6999
|
+
const { lead, coordinator, onCoordinatorEvent } = options;
|
|
6942
7000
|
let taskCounter = 0;
|
|
6943
7001
|
return async (_ctx, input) => {
|
|
6944
7002
|
const actions = [];
|
|
@@ -7025,7 +7083,9 @@ function createApplyCoordinatorActionsActivity(options) {
|
|
|
7025
7083
|
const aliasMap = /* @__PURE__ */ new Map();
|
|
7026
7084
|
for (const action of input.actions) {
|
|
7027
7085
|
if (action.kind === "assign") {
|
|
7028
|
-
const dependsOn = action.dependsOn?.map(
|
|
7086
|
+
const dependsOn = action.dependsOn?.map(
|
|
7087
|
+
(depId) => aliasMap.get(depId) ?? depId
|
|
7088
|
+
);
|
|
7029
7089
|
const task = await coordinator.queue({
|
|
7030
7090
|
memberId: action.memberId,
|
|
7031
7091
|
title: action.title,
|
|
@@ -7084,7 +7144,10 @@ function createCommitExternalTaskActivity(options) {
|
|
|
7084
7144
|
outcome = await coordinator.failExternalTask(input.taskId, input.error);
|
|
7085
7145
|
} else {
|
|
7086
7146
|
const taskResult = input.turnState ? extractTaskResult(input.turnState) ?? { response: "" } : { response: "" };
|
|
7087
|
-
outcome = await coordinator.completeExternalTask(
|
|
7147
|
+
outcome = await coordinator.completeExternalTask(
|
|
7148
|
+
input.taskId,
|
|
7149
|
+
taskResult
|
|
7150
|
+
);
|
|
7088
7151
|
}
|
|
7089
7152
|
if (!outcome) {
|
|
7090
7153
|
return { notifications: [] };
|
|
@@ -7188,11 +7251,11 @@ async function readJsonBody(request) {
|
|
|
7188
7251
|
throw new Error("Request body too large");
|
|
7189
7252
|
}
|
|
7190
7253
|
}
|
|
7191
|
-
const
|
|
7192
|
-
if (
|
|
7254
|
+
const text2 = await request.text();
|
|
7255
|
+
if (text2.length > MAX_BODY_SIZE) {
|
|
7193
7256
|
throw new Error("Request body too large");
|
|
7194
7257
|
}
|
|
7195
|
-
return
|
|
7258
|
+
return text2 ? JSON.parse(text2) : {};
|
|
7196
7259
|
}
|
|
7197
7260
|
function toSafeError(error) {
|
|
7198
7261
|
if (error instanceof Error) {
|
|
@@ -7241,16 +7304,11 @@ async function routeTeamRequest(request, segments, url, coordinator, eventBus, l
|
|
|
7241
7304
|
}
|
|
7242
7305
|
const wantsSSE = request.headers.get("accept")?.includes("text/event-stream");
|
|
7243
7306
|
if (wantsSSE && eventBus) {
|
|
7244
|
-
return startCoordinatorLoopWithSSE(
|
|
7245
|
-
|
|
7246
|
-
body.
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
...loopOptions,
|
|
7250
|
-
...body.maxRounds !== void 0 ? { maxRounds: body.maxRounds } : {},
|
|
7251
|
-
...body.waitTimeoutMs !== void 0 ? { waitTimeoutMs: body.waitTimeoutMs } : {}
|
|
7252
|
-
}
|
|
7253
|
-
);
|
|
7307
|
+
return startCoordinatorLoopWithSSE(coordinator, body.prompt, eventBus, {
|
|
7308
|
+
...loopOptions,
|
|
7309
|
+
...body.maxRounds !== void 0 ? { maxRounds: body.maxRounds } : {},
|
|
7310
|
+
...body.waitTimeoutMs !== void 0 ? { waitTimeoutMs: body.waitTimeoutMs } : {}
|
|
7311
|
+
});
|
|
7254
7312
|
}
|
|
7255
7313
|
const result = await coordinator.run(body.prompt, {
|
|
7256
7314
|
...loopOptions,
|
|
@@ -7294,10 +7352,7 @@ async function routeTeamRequest(request, segments, url, coordinator, eventBus, l
|
|
|
7294
7352
|
if (!body.roleName || typeof body.roleName !== "string") {
|
|
7295
7353
|
return errorResponse("roleName is required", 400);
|
|
7296
7354
|
}
|
|
7297
|
-
const member = await coordinator.register(
|
|
7298
|
-
body.roleName,
|
|
7299
|
-
body.memberId
|
|
7300
|
-
);
|
|
7355
|
+
const member = await coordinator.register(body.roleName, body.memberId);
|
|
7301
7356
|
return json(member, 201);
|
|
7302
7357
|
}
|
|
7303
7358
|
if (sub === "register-all" && segments.length === 2) {
|
|
@@ -7414,19 +7469,16 @@ async function routeTeamRequest(request, segments, url, coordinator, eventBus, l
|
|
|
7414
7469
|
return void 0;
|
|
7415
7470
|
}
|
|
7416
7471
|
function startCoordinatorLoopWithSSE(coordinator, prompt, eventBus, options) {
|
|
7417
|
-
const channel = `team:${coordinator.teamId}:run`;
|
|
7418
7472
|
const encoder = new TextEncoder();
|
|
7419
7473
|
const stream = new ReadableStream({
|
|
7420
7474
|
start(controller) {
|
|
7421
7475
|
const emit = (type, data) => {
|
|
7422
7476
|
try {
|
|
7423
7477
|
controller.enqueue(
|
|
7424
|
-
encoder.encode(
|
|
7425
|
-
`event: ${type}
|
|
7478
|
+
encoder.encode(`event: ${type}
|
|
7426
7479
|
data: ${JSON.stringify(data)}
|
|
7427
7480
|
|
|
7428
|
-
`
|
|
7429
|
-
)
|
|
7481
|
+
`)
|
|
7430
7482
|
);
|
|
7431
7483
|
} catch {
|
|
7432
7484
|
}
|
|
@@ -7467,10 +7519,10 @@ data: ${JSON.stringify(data)}
|
|
|
7467
7519
|
}
|
|
7468
7520
|
|
|
7469
7521
|
// src/team/team-runner.ts
|
|
7470
|
-
import { createServer } from "http";
|
|
7471
7522
|
import {
|
|
7472
|
-
|
|
7473
|
-
} from "
|
|
7523
|
+
createServer
|
|
7524
|
+
} from "http";
|
|
7525
|
+
import { createDispatchExternalTaskControl } from "@cuylabs/agent-core";
|
|
7474
7526
|
import {
|
|
7475
7527
|
createTeamCoordinator,
|
|
7476
7528
|
TaskBoard
|
|
@@ -7506,7 +7558,10 @@ function toHeaders(req) {
|
|
|
7506
7558
|
function streamToReadable(req) {
|
|
7507
7559
|
return new ReadableStream({
|
|
7508
7560
|
start(controller) {
|
|
7509
|
-
req.on(
|
|
7561
|
+
req.on(
|
|
7562
|
+
"data",
|
|
7563
|
+
(chunk) => controller.enqueue(new Uint8Array(chunk))
|
|
7564
|
+
);
|
|
7510
7565
|
req.on("end", () => controller.close());
|
|
7511
7566
|
req.on("error", (err) => controller.error(err));
|
|
7512
7567
|
}
|
|
@@ -7731,7 +7786,10 @@ function createDaprTeamRunner(options) {
|
|
|
7731
7786
|
}
|
|
7732
7787
|
async function waitForDurableRun(instanceId, waitOptions) {
|
|
7733
7788
|
const client2 = requireWorkflowClient();
|
|
7734
|
-
const state = await client2.waitForWorkflowCompletion(
|
|
7789
|
+
const state = await client2.waitForWorkflowCompletion(
|
|
7790
|
+
instanceId,
|
|
7791
|
+
waitOptions
|
|
7792
|
+
);
|
|
7735
7793
|
if (!state) {
|
|
7736
7794
|
return void 0;
|
|
7737
7795
|
}
|
|
@@ -7750,11 +7808,9 @@ function createDaprTeamRunner(options) {
|
|
|
7750
7808
|
if (!report || !workflowClient || !activeDurableRunInstanceId) {
|
|
7751
7809
|
return;
|
|
7752
7810
|
}
|
|
7753
|
-
await workflowClient.raiseWorkflowEvent(
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
{ eventData: report }
|
|
7757
|
-
).catch(async () => {
|
|
7811
|
+
await workflowClient.raiseWorkflowEvent(activeDurableRunInstanceId, "worker-report", {
|
|
7812
|
+
eventData: report
|
|
7813
|
+
}).catch(async () => {
|
|
7758
7814
|
await syncActiveDurableRun().catch(() => {
|
|
7759
7815
|
});
|
|
7760
7816
|
});
|
|
@@ -7787,7 +7843,9 @@ function createDaprTeamRunner(options) {
|
|
|
7787
7843
|
task.id,
|
|
7788
7844
|
task.status === "claimed" ? "Process interrupted before durable task launch completed" : "Durable task lost its workflow runId before recovery"
|
|
7789
7845
|
);
|
|
7790
|
-
log(
|
|
7846
|
+
log(
|
|
7847
|
+
`Recovery: marked durable task "${task.id}" without runId as failed`
|
|
7848
|
+
);
|
|
7791
7849
|
continue;
|
|
7792
7850
|
}
|
|
7793
7851
|
const workflow = await recoveryWorkflowClient?.getWorkflow(task.runId);
|
|
@@ -7796,7 +7854,9 @@ function createDaprTeamRunner(options) {
|
|
|
7796
7854
|
task.id,
|
|
7797
7855
|
`Durable workflow "${task.runId}" was missing during recovery`
|
|
7798
7856
|
);
|
|
7799
|
-
log(
|
|
7857
|
+
log(
|
|
7858
|
+
`Recovery: marked task "${task.id}" as failed (missing workflow ${task.runId})`
|
|
7859
|
+
);
|
|
7800
7860
|
continue;
|
|
7801
7861
|
}
|
|
7802
7862
|
switch (workflow.runtimeStatus) {
|
|
@@ -7812,21 +7872,27 @@ function createDaprTeamRunner(options) {
|
|
|
7812
7872
|
task.id,
|
|
7813
7873
|
`Durable workflow "${task.runId}" was terminated before task completion was committed`
|
|
7814
7874
|
);
|
|
7815
|
-
log(
|
|
7875
|
+
log(
|
|
7876
|
+
`Recovery: marked task "${task.id}" as aborted from terminated workflow`
|
|
7877
|
+
);
|
|
7816
7878
|
break;
|
|
7817
7879
|
case "COMPLETED":
|
|
7818
7880
|
await recoveryBoard.failTask(
|
|
7819
7881
|
task.id,
|
|
7820
7882
|
`Durable workflow "${task.runId}" completed before the task-board commit was persisted`
|
|
7821
7883
|
);
|
|
7822
|
-
log(
|
|
7884
|
+
log(
|
|
7885
|
+
`Recovery: marked task "${task.id}" as failed (completed workflow without commit)`
|
|
7886
|
+
);
|
|
7823
7887
|
break;
|
|
7824
7888
|
case "FAILED":
|
|
7825
7889
|
await recoveryBoard.failTask(
|
|
7826
7890
|
task.id,
|
|
7827
7891
|
`Durable workflow "${task.runId}" failed before task completion was committed`
|
|
7828
7892
|
);
|
|
7829
|
-
log(
|
|
7893
|
+
log(
|
|
7894
|
+
`Recovery: marked task "${task.id}" as failed from failed workflow`
|
|
7895
|
+
);
|
|
7830
7896
|
break;
|
|
7831
7897
|
default:
|
|
7832
7898
|
await recoveryBoard.failTask(
|
|
@@ -7855,15 +7921,15 @@ function createDaprTeamRunner(options) {
|
|
|
7855
7921
|
`A durable coordinator run is already active (${activeDurableRunInstanceId})`
|
|
7856
7922
|
);
|
|
7857
7923
|
}
|
|
7858
|
-
const missingHosts = [...coordinator.members.values()].filter(
|
|
7924
|
+
const missingHosts = [...coordinator.members.values()].filter(
|
|
7925
|
+
(memberRuntime) => !agentWorkflowHosts.has(memberRuntime.role.name)
|
|
7926
|
+
).map((memberRuntime) => memberRuntime.member.id);
|
|
7859
7927
|
if (missingHosts.length > 0) {
|
|
7860
7928
|
throw new Error(
|
|
7861
7929
|
`Members were registered after workflow startup without workflow hosts: ${missingHosts.join(", ")}`
|
|
7862
7930
|
);
|
|
7863
7931
|
}
|
|
7864
|
-
const roleNames = [...coordinator.members.values()].map(
|
|
7865
|
-
(m) => m.role.name
|
|
7866
|
-
);
|
|
7932
|
+
const roleNames = [...coordinator.members.values()].map((m) => m.role.name);
|
|
7867
7933
|
const input = {
|
|
7868
7934
|
prompt,
|
|
7869
7935
|
teamId,
|
|
@@ -7873,7 +7939,9 @@ function createDaprTeamRunner(options) {
|
|
|
7873
7939
|
roleNames
|
|
7874
7940
|
};
|
|
7875
7941
|
const instanceId = `${teamId}-coordinator-${Date.now().toString(36)}`;
|
|
7876
|
-
log(
|
|
7942
|
+
log(
|
|
7943
|
+
`Starting coordinator workflow: ${coordinatorWorkflowName} (${instanceId})`
|
|
7944
|
+
);
|
|
7877
7945
|
activeDurableRunInstanceId = instanceId;
|
|
7878
7946
|
try {
|
|
7879
7947
|
const { instanceId: actualInstanceId } = await client2.startWorkflow(
|
|
@@ -7908,9 +7976,7 @@ function createDaprTeamRunner(options) {
|
|
|
7908
7976
|
} else {
|
|
7909
7977
|
await coordinator.registerAll();
|
|
7910
7978
|
}
|
|
7911
|
-
log(
|
|
7912
|
-
`Auto-registered ${coordinator.listRoles().length} member(s)`
|
|
7913
|
-
);
|
|
7979
|
+
log(`Auto-registered ${coordinator.listRoles().length} member(s)`);
|
|
7914
7980
|
}
|
|
7915
7981
|
if (workflowRuntime) {
|
|
7916
7982
|
for (const [, memberRuntime] of coordinator.members) {
|
|
@@ -7930,10 +7996,7 @@ function createDaprTeamRunner(options) {
|
|
|
7930
7996
|
resolveAgentTurnWorkflowName
|
|
7931
7997
|
});
|
|
7932
7998
|
coordinatorWorkflowName = cwDef.workflowName;
|
|
7933
|
-
workflowRuntime.registerWorkflowWithName(
|
|
7934
|
-
cwDef.workflowName,
|
|
7935
|
-
cwDef.workflow
|
|
7936
|
-
);
|
|
7999
|
+
workflowRuntime.registerWorkflowWithName(cwDef.workflowName, cwDef.workflow);
|
|
7937
8000
|
const reasonHandler = createCoordinatorReasonActivity({
|
|
7938
8001
|
lead: options.lead,
|
|
7939
8002
|
coordinator,
|
|
@@ -7980,7 +8043,13 @@ function createDaprTeamRunner(options) {
|
|
|
7980
8043
|
client: workflowClient
|
|
7981
8044
|
})
|
|
7982
8045
|
),
|
|
7983
|
-
createRecord: ({
|
|
8046
|
+
createRecord: ({
|
|
8047
|
+
task,
|
|
8048
|
+
runtime,
|
|
8049
|
+
target,
|
|
8050
|
+
dispatchId,
|
|
8051
|
+
startedAt
|
|
8052
|
+
}) => ({
|
|
7984
8053
|
id: dispatchId,
|
|
7985
8054
|
agentId: runtime.member.id,
|
|
7986
8055
|
targetType: target.name,
|
|
@@ -8009,26 +8078,28 @@ function createDaprTeamRunner(options) {
|
|
|
8009
8078
|
}
|
|
8010
8079
|
const port = serveOptions?.port ?? 3e3;
|
|
8011
8080
|
const host = serveOptions?.host;
|
|
8012
|
-
const server = createServer(
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
response
|
|
8021
|
-
JSON.stringify({ error: "Not found" }),
|
|
8022
|
-
|
|
8023
|
-
|
|
8081
|
+
const server = createServer(
|
|
8082
|
+
async (req, res) => {
|
|
8083
|
+
try {
|
|
8084
|
+
const request = toRequest(req);
|
|
8085
|
+
let response = await teamHandler(request);
|
|
8086
|
+
if (!response) {
|
|
8087
|
+
response = await handleCoreRoute(request, coordinator, started);
|
|
8088
|
+
}
|
|
8089
|
+
if (!response) {
|
|
8090
|
+
response = new Response(JSON.stringify({ error: "Not found" }), {
|
|
8091
|
+
status: 404,
|
|
8092
|
+
headers: { "content-type": "application/json" }
|
|
8093
|
+
});
|
|
8094
|
+
}
|
|
8095
|
+
await writeResponse(response, res);
|
|
8096
|
+
} catch (error) {
|
|
8097
|
+
const message = error instanceof Error ? error.message : "Internal server error";
|
|
8098
|
+
res.writeHead(500, { "content-type": "application/json" });
|
|
8099
|
+
res.end(JSON.stringify({ error: message }));
|
|
8024
8100
|
}
|
|
8025
|
-
await writeResponse(response, res);
|
|
8026
|
-
} catch (error) {
|
|
8027
|
-
const message = error instanceof Error ? error.message : "Internal server error";
|
|
8028
|
-
res.writeHead(500, { "content-type": "application/json" });
|
|
8029
|
-
res.end(JSON.stringify({ error: message }));
|
|
8030
8101
|
}
|
|
8031
|
-
|
|
8102
|
+
);
|
|
8032
8103
|
await new Promise((resolve2, reject) => {
|
|
8033
8104
|
server.once("error", reject);
|
|
8034
8105
|
server.listen(port, host, () => {
|
|
@@ -8183,7 +8254,9 @@ function normalizeWorkflowInstanceId(explicitInstanceId, sessionId) {
|
|
|
8183
8254
|
}
|
|
8184
8255
|
function createSteeringRequest(input) {
|
|
8185
8256
|
if (!input.workflowInstanceId.trim()) {
|
|
8186
|
-
throw new Error(
|
|
8257
|
+
throw new Error(
|
|
8258
|
+
'"workflowInstanceId" is required and must be a non-empty string.'
|
|
8259
|
+
);
|
|
8187
8260
|
}
|
|
8188
8261
|
const sessionId = input.sessionId.trim();
|
|
8189
8262
|
if (!sessionId) {
|
|
@@ -8203,7 +8276,9 @@ function createSteeringRequest(input) {
|
|
|
8203
8276
|
}
|
|
8204
8277
|
function createFollowUpRequest(input) {
|
|
8205
8278
|
if (!input.workflowInstanceId.trim()) {
|
|
8206
|
-
throw new Error(
|
|
8279
|
+
throw new Error(
|
|
8280
|
+
'"workflowInstanceId" is required and must be a non-empty string.'
|
|
8281
|
+
);
|
|
8207
8282
|
}
|
|
8208
8283
|
const sessionId = input.sessionId.trim();
|
|
8209
8284
|
if (!sessionId) {
|
|
@@ -8240,10 +8315,7 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8240
8315
|
await activeTurns.get(state.sessionId)?.bridge.notifyTaskStart(state);
|
|
8241
8316
|
},
|
|
8242
8317
|
async notifyCheckpoint(reason, state) {
|
|
8243
|
-
await activeTurns.get(state.sessionId)?.bridge.notifyCheckpoint(
|
|
8244
|
-
reason,
|
|
8245
|
-
state
|
|
8246
|
-
);
|
|
8318
|
+
await activeTurns.get(state.sessionId)?.bridge.notifyCheckpoint(reason, state);
|
|
8247
8319
|
},
|
|
8248
8320
|
async notifyTaskComplete(state) {
|
|
8249
8321
|
try {
|
|
@@ -8258,10 +8330,7 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8258
8330
|
},
|
|
8259
8331
|
async notifyTaskError(state, error) {
|
|
8260
8332
|
try {
|
|
8261
|
-
await activeTurns.get(state.sessionId)?.bridge.notifyTaskError(
|
|
8262
|
-
state,
|
|
8263
|
-
error
|
|
8264
|
-
);
|
|
8333
|
+
await activeTurns.get(state.sessionId)?.bridge.notifyTaskError(state, error);
|
|
8265
8334
|
} finally {
|
|
8266
8335
|
await closeEventChannel(state.sessionId, {
|
|
8267
8336
|
type: "error",
|
|
@@ -8337,7 +8406,7 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8337
8406
|
host: () => options.agent.getHost(),
|
|
8338
8407
|
middleware: () => options.agent.getMiddlewareRunner(),
|
|
8339
8408
|
reasoningLevel: () => options.agent.reasoningLevel,
|
|
8340
|
-
resolveSystemPrompts: (sessionId,
|
|
8409
|
+
resolveSystemPrompts: (sessionId, _current) => options.agent.buildSystemPrompts(sessionId),
|
|
8341
8410
|
...options.createAbortSignal ? { createAbortSignal: options.createAbortSignal } : {},
|
|
8342
8411
|
...onEvent ? { onEvent } : {},
|
|
8343
8412
|
now
|
|
@@ -8345,9 +8414,7 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8345
8414
|
...options.humanInputRuntime?.hasHumanInputTools ? {
|
|
8346
8415
|
humanInputCheckActivity: {
|
|
8347
8416
|
check: async (input) => {
|
|
8348
|
-
const result = await options.humanInputRuntime.evaluateToolRequest(
|
|
8349
|
-
input
|
|
8350
|
-
);
|
|
8417
|
+
const result = await options.humanInputRuntime.evaluateToolRequest(input);
|
|
8351
8418
|
switch (result.action) {
|
|
8352
8419
|
case "allow":
|
|
8353
8420
|
case "deny":
|
|
@@ -8366,9 +8433,7 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8366
8433
|
...options.approvalRuntime?.hasApprovalMiddleware ? {
|
|
8367
8434
|
approvalCheckActivity: {
|
|
8368
8435
|
check: async (input) => {
|
|
8369
|
-
const result = await options.approvalRuntime.evaluateToolApproval(
|
|
8370
|
-
input
|
|
8371
|
-
);
|
|
8436
|
+
const result = await options.approvalRuntime.evaluateToolApproval(input);
|
|
8372
8437
|
switch (result.action) {
|
|
8373
8438
|
case "allow":
|
|
8374
8439
|
return result;
|
|
@@ -8519,9 +8584,7 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8519
8584
|
preparedRun.workflowInstanceId
|
|
8520
8585
|
);
|
|
8521
8586
|
if (ctx) {
|
|
8522
|
-
const otelApi = await import("@opentelemetry/api").catch(
|
|
8523
|
-
() => null
|
|
8524
|
-
);
|
|
8587
|
+
const otelApi = await import("@opentelemetry/api").catch(() => null);
|
|
8525
8588
|
if (otelApi) {
|
|
8526
8589
|
await otelApi.context.with(
|
|
8527
8590
|
ctx,
|
|
@@ -8538,8 +8601,9 @@ function createDaprAgentWorkflowHost(options) {
|
|
|
8538
8601
|
preparedRun.workflowInstanceId
|
|
8539
8602
|
);
|
|
8540
8603
|
} catch (error) {
|
|
8541
|
-
|
|
8542
|
-
`[${options.workflowName ?? options.agent.name}] Failed to mark seeded follow-ups as applied for session "${preparedRun.sessionId}": ${error instanceof Error ? error.message : String(error)}
|
|
8604
|
+
process2.stderr.write(
|
|
8605
|
+
`[${options.workflowName ?? options.agent.name}] Failed to mark seeded follow-ups as applied for session "${preparedRun.sessionId}": ${error instanceof Error ? error.message : String(error)}
|
|
8606
|
+
`
|
|
8543
8607
|
);
|
|
8544
8608
|
}
|
|
8545
8609
|
}
|
|
@@ -8670,7 +8734,9 @@ function createDaprWorkflowWorker(options) {
|
|
|
8670
8734
|
if (!running) {
|
|
8671
8735
|
return;
|
|
8672
8736
|
}
|
|
8673
|
-
logger?.info?.(
|
|
8737
|
+
logger?.info?.(
|
|
8738
|
+
"Stopping workflow worker (gRPC stream cancel is expected)..."
|
|
8739
|
+
);
|
|
8674
8740
|
await options.runtime.stop();
|
|
8675
8741
|
running = false;
|
|
8676
8742
|
logger?.info?.("Dapr workflow worker stopped.");
|
|
@@ -9040,7 +9106,10 @@ async function handleAgentRunRoutes(method, segments, request, app, workflowClie
|
|
|
9040
9106
|
if (method === "POST" && segments.length === 2 && segments[0] === "agents" && segments[1] === "run") {
|
|
9041
9107
|
const body = await parseJsonBody(request);
|
|
9042
9108
|
if (!body.message || typeof body.message !== "string" || !body.message.trim()) {
|
|
9043
|
-
return json2(
|
|
9109
|
+
return json2(
|
|
9110
|
+
{ error: '"message" is required and must be a non-empty string.' },
|
|
9111
|
+
400
|
|
9112
|
+
);
|
|
9044
9113
|
}
|
|
9045
9114
|
const selectedId = body.agentId?.trim() || resolveSingleAgent(app)?.id;
|
|
9046
9115
|
if (!selectedId) {
|
|
@@ -9062,11 +9131,7 @@ async function handleAgentRunRoutes(method, segments, request, app, workflowClie
|
|
|
9062
9131
|
}
|
|
9063
9132
|
}
|
|
9064
9133
|
if (method === "POST" && segments.length === 2 && segments[0] === "agents" && segments[1] === "run-durable") {
|
|
9065
|
-
return await handleRunDurable(
|
|
9066
|
-
request,
|
|
9067
|
-
app,
|
|
9068
|
-
workflowClient
|
|
9069
|
-
);
|
|
9134
|
+
return await handleRunDurable(request, app, workflowClient);
|
|
9070
9135
|
}
|
|
9071
9136
|
if (method === "POST" && segments.length === 3 && segments[0] === "agents" && segments[2] === "run") {
|
|
9072
9137
|
const agent = app.getAgent(segments[1]);
|
|
@@ -9083,12 +9148,7 @@ async function handleAgentRunRoutes(method, segments, request, app, workflowClie
|
|
|
9083
9148
|
return void 0;
|
|
9084
9149
|
}
|
|
9085
9150
|
const body = await parseJsonBody(request);
|
|
9086
|
-
return await handleRunDurableForAgent(
|
|
9087
|
-
agent,
|
|
9088
|
-
body,
|
|
9089
|
-
request,
|
|
9090
|
-
workflowClient
|
|
9091
|
-
);
|
|
9151
|
+
return await handleRunDurableForAgent(agent, body, request, workflowClient);
|
|
9092
9152
|
}
|
|
9093
9153
|
return void 0;
|
|
9094
9154
|
}
|
|
@@ -9098,7 +9158,10 @@ async function handleRunDurable(request, app, workflowClient) {
|
|
|
9098
9158
|
}
|
|
9099
9159
|
const body = await parseJsonBody(request);
|
|
9100
9160
|
if (!body.message || typeof body.message !== "string" || !body.message.trim()) {
|
|
9101
|
-
return json2(
|
|
9161
|
+
return json2(
|
|
9162
|
+
{ error: '"message" is required and must be a non-empty string.' },
|
|
9163
|
+
400
|
|
9164
|
+
);
|
|
9102
9165
|
}
|
|
9103
9166
|
const selectedId = body.agentId?.trim() || resolveSingleAgent(app)?.id;
|
|
9104
9167
|
if (!selectedId) {
|
|
@@ -9120,18 +9183,16 @@ async function handleRunDurableForAgent(agent, body, request, workflowClient) {
|
|
|
9120
9183
|
return json2({ error: "Workflow client is not configured." }, 501);
|
|
9121
9184
|
}
|
|
9122
9185
|
if (!body.message || typeof body.message !== "string" || !body.message.trim()) {
|
|
9123
|
-
return json2(
|
|
9186
|
+
return json2(
|
|
9187
|
+
{ error: '"message" is required and must be a non-empty string.' },
|
|
9188
|
+
400
|
|
9189
|
+
);
|
|
9124
9190
|
}
|
|
9125
9191
|
try {
|
|
9126
|
-
const result = await agent.workflowHost.startTurn(
|
|
9127
|
-
workflowClient,
|
|
9128
|
-
body
|
|
9129
|
-
);
|
|
9192
|
+
const result = await agent.workflowHost.startTurn(workflowClient, body);
|
|
9130
9193
|
const wantsStream = request.headers.get("accept")?.includes("text/event-stream");
|
|
9131
9194
|
const eventBus = agent.workflowHost.eventBus;
|
|
9132
|
-
const afterSeq = parseLastEventId(
|
|
9133
|
-
request.headers.get("last-event-id")
|
|
9134
|
-
);
|
|
9195
|
+
const afterSeq = parseLastEventId(request.headers.get("last-event-id"));
|
|
9135
9196
|
if (wantsStream && eventBus) {
|
|
9136
9197
|
return createSSEResponse(
|
|
9137
9198
|
eventBus,
|
|
@@ -9140,12 +9201,15 @@ async function handleRunDurableForAgent(agent, body, request, workflowClient) {
|
|
|
9140
9201
|
request.signal
|
|
9141
9202
|
);
|
|
9142
9203
|
}
|
|
9143
|
-
return json2(
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9204
|
+
return json2(
|
|
9205
|
+
{
|
|
9206
|
+
instanceId: result.workflowInstanceId,
|
|
9207
|
+
agentId: agent.id,
|
|
9208
|
+
workflowName: agent.workflowHost.workflowName,
|
|
9209
|
+
sessionId: result.sessionId
|
|
9210
|
+
},
|
|
9211
|
+
202
|
|
9212
|
+
);
|
|
9149
9213
|
} catch (error) {
|
|
9150
9214
|
return json2({ error: toSafeErrorMessage(error) }, 500);
|
|
9151
9215
|
}
|
|
@@ -9361,12 +9425,14 @@ async function handleHumanInputRoutes(method, segments, request, agent, workflow
|
|
|
9361
9425
|
}
|
|
9362
9426
|
|
|
9363
9427
|
// src/host/http/routers/follow-up.ts
|
|
9364
|
-
async function handleFollowUpRoutes(method, segments, request, agent,
|
|
9428
|
+
async function handleFollowUpRoutes(method, segments, request, agent, _workflowClient) {
|
|
9365
9429
|
const followUpRuntime = agent.workflowHost.followUpRuntime;
|
|
9366
9430
|
if (method === "GET" && segments.length === 0) {
|
|
9367
9431
|
if (!followUpRuntime) {
|
|
9368
9432
|
return json2(
|
|
9369
|
-
{
|
|
9433
|
+
{
|
|
9434
|
+
error: "Durable follow-up management is not enabled for this agent."
|
|
9435
|
+
},
|
|
9370
9436
|
501
|
|
9371
9437
|
);
|
|
9372
9438
|
}
|
|
@@ -9390,20 +9456,27 @@ async function handleFollowUpRoutes(method, segments, request, agent, workflowCl
|
|
|
9390
9456
|
if (method === "GET" && segments.length === 1) {
|
|
9391
9457
|
if (!followUpRuntime) {
|
|
9392
9458
|
return json2(
|
|
9393
|
-
{
|
|
9459
|
+
{
|
|
9460
|
+
error: "Durable follow-up management is not enabled for this agent."
|
|
9461
|
+
},
|
|
9394
9462
|
501
|
|
9395
9463
|
);
|
|
9396
9464
|
}
|
|
9397
9465
|
const record = await followUpRuntime.getRequest(segments[0]);
|
|
9398
9466
|
if (!record) {
|
|
9399
|
-
return json2(
|
|
9467
|
+
return json2(
|
|
9468
|
+
{ error: `Follow-up request not found: ${segments[0]}` },
|
|
9469
|
+
404
|
|
9470
|
+
);
|
|
9400
9471
|
}
|
|
9401
9472
|
return json2(record);
|
|
9402
9473
|
}
|
|
9403
9474
|
if (method === "POST" && segments.length === 2 && segments[1] === "respond") {
|
|
9404
9475
|
if (!followUpRuntime) {
|
|
9405
9476
|
return json2(
|
|
9406
|
-
{
|
|
9477
|
+
{
|
|
9478
|
+
error: "Durable follow-up management is not enabled for this agent."
|
|
9479
|
+
},
|
|
9407
9480
|
501
|
|
9408
9481
|
);
|
|
9409
9482
|
}
|
|
@@ -9417,7 +9490,10 @@ async function handleFollowUpRoutes(method, segments, request, agent, workflowCl
|
|
|
9417
9490
|
400
|
|
9418
9491
|
);
|
|
9419
9492
|
}
|
|
9420
|
-
return json2(
|
|
9493
|
+
return json2(
|
|
9494
|
+
await followUpRuntime.respondToRequest(segments[0], action),
|
|
9495
|
+
202
|
|
9496
|
+
);
|
|
9421
9497
|
}
|
|
9422
9498
|
return void 0;
|
|
9423
9499
|
}
|
|
@@ -9429,12 +9505,17 @@ async function handleSteerRoute(method, segments, request, agent, workflowClient
|
|
|
9429
9505
|
return json2({ error: "Workflow client is not configured." }, 501);
|
|
9430
9506
|
}
|
|
9431
9507
|
if (!agent.workflowHost.steerTurn) {
|
|
9432
|
-
return json2(
|
|
9508
|
+
return json2(
|
|
9509
|
+
{ error: "Durable steering is not enabled for this agent." },
|
|
9510
|
+
501
|
|
9511
|
+
);
|
|
9433
9512
|
}
|
|
9434
9513
|
const body = await parseJsonBody(request);
|
|
9435
9514
|
if (!body.workflowInstanceId || typeof body.workflowInstanceId !== "string" || !body.workflowInstanceId.trim()) {
|
|
9436
9515
|
return json2(
|
|
9437
|
-
{
|
|
9516
|
+
{
|
|
9517
|
+
error: '"workflowInstanceId" is required and must be a non-empty string.'
|
|
9518
|
+
},
|
|
9438
9519
|
400
|
|
9439
9520
|
);
|
|
9440
9521
|
}
|
|
@@ -9487,7 +9568,9 @@ async function handleFollowUpQueueRoute(method, segments, request, agent, workfl
|
|
|
9487
9568
|
const body = await parseJsonBody(request);
|
|
9488
9569
|
if (!body.workflowInstanceId || typeof body.workflowInstanceId !== "string" || !body.workflowInstanceId.trim()) {
|
|
9489
9570
|
return json2(
|
|
9490
|
-
{
|
|
9571
|
+
{
|
|
9572
|
+
error: '"workflowInstanceId" is required and must be a non-empty string.'
|
|
9573
|
+
},
|
|
9491
9574
|
400
|
|
9492
9575
|
);
|
|
9493
9576
|
}
|
|
@@ -9534,7 +9617,9 @@ async function handleWorkflowRoutes(method, segments, request, agent, workflowCl
|
|
|
9534
9617
|
501
|
|
9535
9618
|
);
|
|
9536
9619
|
}
|
|
9537
|
-
const record = await agent.runtimeBundle.executionStore.getExecution(
|
|
9620
|
+
const record = await agent.runtimeBundle.executionStore.getExecution(
|
|
9621
|
+
segments[1]
|
|
9622
|
+
);
|
|
9538
9623
|
if (!record) {
|
|
9539
9624
|
return json2({ error: `Execution not found: ${segments[1]}` }, 404);
|
|
9540
9625
|
}
|
|
@@ -9616,7 +9701,11 @@ function createDaprHostHttpHandler(options) {
|
|
|
9616
9701
|
const method = request.method;
|
|
9617
9702
|
const health = handleHealthRoutes(method, segments, options.app);
|
|
9618
9703
|
if (health) return health;
|
|
9619
|
-
const readiness = await handleReadinessRoutes(
|
|
9704
|
+
const readiness = await handleReadinessRoutes(
|
|
9705
|
+
method,
|
|
9706
|
+
segments,
|
|
9707
|
+
options.app
|
|
9708
|
+
);
|
|
9620
9709
|
if (readiness) return readiness;
|
|
9621
9710
|
const agentList = handleAgentListRoute(method, segments, options.app);
|
|
9622
9711
|
if (agentList) return agentList;
|
|
@@ -9855,9 +9944,15 @@ async function startDaprHttpServer(options) {
|
|
|
9855
9944
|
await writeResponse2(response, res);
|
|
9856
9945
|
} catch (error) {
|
|
9857
9946
|
if (error instanceof PayloadTooLargeError) {
|
|
9858
|
-
await writeResponse2(
|
|
9947
|
+
await writeResponse2(
|
|
9948
|
+
json2({ error: "Request body too large" }, 413),
|
|
9949
|
+
res
|
|
9950
|
+
);
|
|
9859
9951
|
} else {
|
|
9860
|
-
await writeResponse2(
|
|
9952
|
+
await writeResponse2(
|
|
9953
|
+
json2({ error: toSafeErrorMessage(error) }, 500),
|
|
9954
|
+
res
|
|
9955
|
+
);
|
|
9861
9956
|
}
|
|
9862
9957
|
}
|
|
9863
9958
|
});
|
|
@@ -10000,7 +10095,9 @@ async function readWorkflowTerminalEvent(input) {
|
|
|
10000
10095
|
if (!workflow) {
|
|
10001
10096
|
return {
|
|
10002
10097
|
type: "error",
|
|
10003
|
-
error: new Error(
|
|
10098
|
+
error: new Error(
|
|
10099
|
+
`Workflow for session "${sessionId}" did not return a terminal state.`
|
|
10100
|
+
)
|
|
10004
10101
|
};
|
|
10005
10102
|
}
|
|
10006
10103
|
const fromOutput = toCompletionEventFromObject(
|
|
@@ -10122,7 +10219,11 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10122
10219
|
cwd: agent.cwd,
|
|
10123
10220
|
getCapabilities: () => mergeCapabilities(
|
|
10124
10221
|
{
|
|
10125
|
-
protocol: {
|
|
10222
|
+
protocol: {
|
|
10223
|
+
transport: "in-process",
|
|
10224
|
+
reconnectable: false,
|
|
10225
|
+
multiClient: true
|
|
10226
|
+
},
|
|
10126
10227
|
turns: { steer: true, followUp: true, followUpManagement: true },
|
|
10127
10228
|
interactive: {
|
|
10128
10229
|
approvalRequests: Boolean(runner.workflowHost.approvalRuntime),
|
|
@@ -10186,15 +10287,20 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10186
10287
|
undoSessionTurn,
|
|
10187
10288
|
getSessionTurnDiff,
|
|
10188
10289
|
async *chat(sessionId, message, chatOptions) {
|
|
10189
|
-
const started = await runner.workflowHost.startTurn(
|
|
10190
|
-
|
|
10191
|
-
|
|
10192
|
-
|
|
10193
|
-
|
|
10290
|
+
const started = await runner.workflowHost.startTurn(
|
|
10291
|
+
runner.workflowClient,
|
|
10292
|
+
{
|
|
10293
|
+
sessionId,
|
|
10294
|
+
message,
|
|
10295
|
+
...chatOptions?.system ? { system: chatOptions.system } : {}
|
|
10296
|
+
}
|
|
10297
|
+
);
|
|
10194
10298
|
activeTurns.set(started.sessionId, {
|
|
10195
10299
|
workflowInstanceId: started.workflowInstanceId
|
|
10196
10300
|
});
|
|
10197
|
-
const subscription = runner.workflowHost.eventBus?.subscribe(
|
|
10301
|
+
const subscription = runner.workflowHost.eventBus?.subscribe(
|
|
10302
|
+
started.sessionId
|
|
10303
|
+
);
|
|
10198
10304
|
const completionPromise = runner.workflowClient.waitForWorkflowCompletion(
|
|
10199
10305
|
started.workflowInstanceId
|
|
10200
10306
|
);
|
|
@@ -10205,7 +10311,9 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10205
10311
|
if (chatOptions.abort.aborted) {
|
|
10206
10312
|
abortHandler();
|
|
10207
10313
|
} else {
|
|
10208
|
-
chatOptions.abort.addEventListener("abort", abortHandler, {
|
|
10314
|
+
chatOptions.abort.addEventListener("abort", abortHandler, {
|
|
10315
|
+
once: true
|
|
10316
|
+
});
|
|
10209
10317
|
}
|
|
10210
10318
|
}
|
|
10211
10319
|
try {
|
|
@@ -10230,7 +10338,9 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10230
10338
|
if (chatOptions?.abort) {
|
|
10231
10339
|
chatOptions.abort.removeEventListener("abort", abortHandler);
|
|
10232
10340
|
}
|
|
10233
|
-
const completedInstanceId = activeTurns.get(
|
|
10341
|
+
const completedInstanceId = activeTurns.get(
|
|
10342
|
+
started.sessionId
|
|
10343
|
+
)?.workflowInstanceId;
|
|
10234
10344
|
activeTurns.delete(started.sessionId);
|
|
10235
10345
|
if (completedInstanceId) {
|
|
10236
10346
|
runner.workflowClient.purgeWorkflow(completedInstanceId).catch(() => {
|
|
@@ -10277,11 +10387,15 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10277
10387
|
if (!runtime2) {
|
|
10278
10388
|
return;
|
|
10279
10389
|
}
|
|
10280
|
-
void runtime2.respondToRequest(
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10390
|
+
void runtime2.respondToRequest(
|
|
10391
|
+
requestId,
|
|
10392
|
+
{
|
|
10393
|
+
action: payload.action,
|
|
10394
|
+
...payload.feedback ? { feedback: payload.feedback } : {},
|
|
10395
|
+
...payload.rememberScope ? { rememberScope: payload.rememberScope } : {}
|
|
10396
|
+
},
|
|
10397
|
+
runner.workflowClient
|
|
10398
|
+
);
|
|
10285
10399
|
return;
|
|
10286
10400
|
}
|
|
10287
10401
|
const runtime = runner.workflowHost.humanInputRuntime;
|
|
@@ -10330,7 +10444,9 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10330
10444
|
getSessionStorage: () => agent.getSessionManager().getStorage(),
|
|
10331
10445
|
listPluginCommands: () => pluginCommandInfos,
|
|
10332
10446
|
executePluginCommand: async (name, args) => {
|
|
10333
|
-
const command = pluginCommandTokens.get(
|
|
10447
|
+
const command = pluginCommandTokens.get(
|
|
10448
|
+
normalizePluginCommandToken(name)
|
|
10449
|
+
);
|
|
10334
10450
|
if (!command) {
|
|
10335
10451
|
throw new Error(`Plugin command not found: ${name}`);
|
|
10336
10452
|
}
|
|
@@ -10340,7 +10456,7 @@ function createDaprAgentServerAdapter(runner, options = {}) {
|
|
|
10340
10456
|
}
|
|
10341
10457
|
|
|
10342
10458
|
// src/host/events/pubsub-bridge.ts
|
|
10343
|
-
import
|
|
10459
|
+
import process3 from "process";
|
|
10344
10460
|
function isAgentCloudEvent(value) {
|
|
10345
10461
|
if (!value || typeof value !== "object") return false;
|
|
10346
10462
|
const obj = value;
|
|
@@ -10358,7 +10474,7 @@ function extractAgentEvent(cloudEvent) {
|
|
|
10358
10474
|
return null;
|
|
10359
10475
|
}
|
|
10360
10476
|
function getDefaultDaprHttpEndpoint() {
|
|
10361
|
-
const port =
|
|
10477
|
+
const port = process3.env.DAPR_HTTP_PORT ?? "3500";
|
|
10362
10478
|
return `http://127.0.0.1:${port}`;
|
|
10363
10479
|
}
|
|
10364
10480
|
var DEFAULT_PUBSUB_NAME = "pubsub";
|
|
@@ -10495,13 +10611,13 @@ function createDaprPubSubEventBridge(options) {
|
|
|
10495
10611
|
}
|
|
10496
10612
|
|
|
10497
10613
|
// src/host/runner/runner.ts
|
|
10498
|
-
import
|
|
10614
|
+
import process6 from "process";
|
|
10499
10615
|
import { getConfiguredSubAgents as getConfiguredSubAgents2 } from "@cuylabs/agent-core";
|
|
10500
10616
|
|
|
10501
10617
|
// src/host/runner/http-middleware.ts
|
|
10502
10618
|
import { readFile } from "fs/promises";
|
|
10503
10619
|
import { extname, join, relative, resolve } from "path";
|
|
10504
|
-
import
|
|
10620
|
+
import process4 from "process";
|
|
10505
10621
|
function normalizeRouteMethods(methods) {
|
|
10506
10622
|
if (!methods) {
|
|
10507
10623
|
return void 0;
|
|
@@ -10551,7 +10667,7 @@ async function maybeServeStaticAsset(request, options) {
|
|
|
10551
10667
|
const relativePath = decodedPath === "/" ? indexFile : decodedPath.replace(/^\/+/, "");
|
|
10552
10668
|
const assetPath = resolve(join(staticRoot, relativePath));
|
|
10553
10669
|
const traversal = relative(staticRoot, assetPath);
|
|
10554
|
-
if (traversal === ".." || traversal.startsWith(`..${
|
|
10670
|
+
if (traversal === ".." || traversal.startsWith(`..${process4.platform === "win32" ? "\\" : "/"}`)) {
|
|
10555
10671
|
return new Response("Not found", { status: 404 });
|
|
10556
10672
|
}
|
|
10557
10673
|
try {
|
|
@@ -10592,10 +10708,10 @@ function composeRunnerHttpHandler(baseHandler, options = {}) {
|
|
|
10592
10708
|
}
|
|
10593
10709
|
|
|
10594
10710
|
// src/host/runner/helpers.ts
|
|
10595
|
-
import
|
|
10711
|
+
import process5 from "process";
|
|
10596
10712
|
function resolveDaprConfig(options) {
|
|
10597
|
-
const daprHost =
|
|
10598
|
-
const daprHttpPort =
|
|
10713
|
+
const daprHost = process5.env.DAPR_HOST ?? "127.0.0.1";
|
|
10714
|
+
const daprHttpPort = process5.env.DAPR_HTTP_PORT ?? "3500";
|
|
10599
10715
|
return {
|
|
10600
10716
|
daprHttpEndpoint: options.daprHttpEndpoint ?? `http://${daprHost}:${daprHttpPort}`,
|
|
10601
10717
|
stateStoreName: options.stateStoreName ?? "statestore",
|
|
@@ -10742,10 +10858,9 @@ function createDaprAgentRunner(options) {
|
|
|
10742
10858
|
},
|
|
10743
10859
|
roles: subagentConfig.roles,
|
|
10744
10860
|
workflowHosts: new Map(
|
|
10745
|
-
subagentGraph.entries.map(
|
|
10746
|
-
entry.role.name,
|
|
10747
|
-
|
|
10748
|
-
])
|
|
10861
|
+
subagentGraph.entries.map(
|
|
10862
|
+
(entry) => [entry.role.name, entry.bundle.workflowHost]
|
|
10863
|
+
)
|
|
10749
10864
|
),
|
|
10750
10865
|
stateStoreName: config.stateStoreName,
|
|
10751
10866
|
daprHttpEndpoint: config.daprHttpEndpoint,
|
|
@@ -10811,7 +10926,8 @@ function createDaprAgentRunner(options) {
|
|
|
10811
10926
|
let httpServer;
|
|
10812
10927
|
function log(message) {
|
|
10813
10928
|
if (options.logging !== false) {
|
|
10814
|
-
|
|
10929
|
+
process6.stdout.write(`[${name}] ${message}
|
|
10930
|
+
`);
|
|
10815
10931
|
}
|
|
10816
10932
|
}
|
|
10817
10933
|
return {
|
|
@@ -10882,8 +10998,8 @@ function createDaprAgentRunner(options) {
|
|
|
10882
10998
|
await this.stop();
|
|
10883
10999
|
resolve2();
|
|
10884
11000
|
};
|
|
10885
|
-
|
|
10886
|
-
|
|
11001
|
+
process6.once("SIGINT", () => void shutdown("SIGINT"));
|
|
11002
|
+
process6.once("SIGTERM", () => void shutdown("SIGTERM"));
|
|
10887
11003
|
});
|
|
10888
11004
|
},
|
|
10889
11005
|
async run(message, runOptions) {
|
|
@@ -10948,7 +11064,7 @@ function createDaprAgentRunner(options) {
|
|
|
10948
11064
|
}
|
|
10949
11065
|
|
|
10950
11066
|
// src/host/runner/multi-runner.ts
|
|
10951
|
-
import
|
|
11067
|
+
import process7 from "process";
|
|
10952
11068
|
function createDaprMultiAgentRunner(options) {
|
|
10953
11069
|
const config = resolveDaprConfig({
|
|
10954
11070
|
...options,
|
|
@@ -11083,7 +11199,8 @@ function createDaprMultiAgentRunner(options) {
|
|
|
11083
11199
|
let httpServer;
|
|
11084
11200
|
function log(message) {
|
|
11085
11201
|
if (loggingEnabled) {
|
|
11086
|
-
|
|
11202
|
+
process7.stdout.write(`[multi-agent] ${message}
|
|
11203
|
+
`);
|
|
11087
11204
|
}
|
|
11088
11205
|
}
|
|
11089
11206
|
return {
|
|
@@ -11142,8 +11259,8 @@ function createDaprMultiAgentRunner(options) {
|
|
|
11142
11259
|
await this.stop();
|
|
11143
11260
|
resolve2();
|
|
11144
11261
|
};
|
|
11145
|
-
|
|
11146
|
-
|
|
11262
|
+
process7.once("SIGINT", () => void shutdown("SIGINT"));
|
|
11263
|
+
process7.once("SIGTERM", () => void shutdown("SIGTERM"));
|
|
11147
11264
|
});
|
|
11148
11265
|
},
|
|
11149
11266
|
async stop() {
|