@relayfx/sdk 0.3.4 → 0.3.6
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/ai.js +1 -1
- package/dist/http-server.js +1 -1
- package/dist/{index-pr9133xv.js → index-2vsf6dks.js} +1 -1
- package/dist/{index-25gwk9tj.js → index-8fpd6kvj.js} +46 -31
- package/dist/{index-01rpd00m.js → index-e02krw55.js} +291 -272
- package/dist/{index-cphmds30.js → index-mtvz1bjn.js} +13 -6
- package/dist/index.js +10 -9
- package/dist/migrations/20260718140000_execution_scoped_tool_calls/migration.sql +35 -0
- package/dist/migrations/mysql/0011_execution_scoped_tool_calls.sql +29 -0
- package/dist/migrations/pg/20260718140000_execution_scoped_tool_calls/migration.sql +35 -0
- package/dist/migrations/sqlite/0011_execution_scoped_tool_calls.sql +53 -0
- package/dist/mysql.js +4 -4
- package/dist/postgres.js +21 -10
- package/dist/sqlite.js +62 -5
- package/dist/types/relay/operation.d.ts +9 -0
- package/dist/types/relay/sqlite-migrations.d.ts +6 -1
- package/dist/types/runtime/agent/relay-permissions.d.ts +0 -1
- package/dist/types/runtime/tool/tool-runtime-identifiers.d.ts +9 -0
- package/dist/types/runtime/tool/tool-runtime-service.d.ts +1 -0
- package/dist/types/store-sql/schema/relay-schema.d.ts +30 -0
- package/dist/types/store-sql/tool/tool-call-repository.d.ts +11 -6
- package/package.json +3 -3
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
exports_tool_executor,
|
|
17
17
|
exports_tool_output,
|
|
18
18
|
exports_turn_policy
|
|
19
|
-
} from "./index-
|
|
19
|
+
} from "./index-8fpd6kvj.js";
|
|
20
20
|
import {
|
|
21
21
|
ClientError,
|
|
22
22
|
CommandReplyInvalid,
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
followExecutionFrom,
|
|
52
52
|
inputSchemaRef,
|
|
53
53
|
outputSchemaRef
|
|
54
|
-
} from "./index-
|
|
54
|
+
} from "./index-mtvz1bjn.js";
|
|
55
55
|
import {
|
|
56
56
|
__export
|
|
57
57
|
} from "./index-nb39b5ae.js";
|
|
@@ -7679,9 +7679,10 @@ var MaxAttemptRow = Schema35.Struct({
|
|
|
7679
7679
|
});
|
|
7680
7680
|
var ExpiredCallRow = Schema35.Struct({
|
|
7681
7681
|
id: Schema35.String,
|
|
7682
|
+
execution_id: Schema35.String,
|
|
7682
7683
|
active_attempt_id: Schema35.NullishOr(Schema35.String)
|
|
7683
7684
|
});
|
|
7684
|
-
var IdRow = Schema35.Struct({ id: Schema35.String });
|
|
7685
|
+
var IdRow = Schema35.Struct({ id: Schema35.String, execution_id: Schema35.String });
|
|
7685
7686
|
var metadata8 = (input) => input ?? {};
|
|
7686
7687
|
var normalizeCall = (call) => ({ ...call, metadata: metadata8(call.metadata) });
|
|
7687
7688
|
var sameCallIdentity = (left, right) => exports_shared_schema.canonicalEquals(normalizeCall(left), normalizeCall(right));
|
|
@@ -7776,15 +7777,15 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7776
7777
|
"completed_at"
|
|
7777
7778
|
].join(", "));
|
|
7778
7779
|
const resultColumns = sql.literal(["tool_call_id", "output_json", "error", "metadata_json", "created_at"].join(", "));
|
|
7779
|
-
const selectCallByKey = (tenantId, id) => sql`
|
|
7780
|
+
const selectCallByKey = (tenantId, executionId, id) => sql`
|
|
7780
7781
|
SELECT ${callColumns}
|
|
7781
7782
|
FROM relay_tool_calls
|
|
7782
|
-
WHERE tenant_id = ${tenantId} AND id = ${id}
|
|
7783
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${id}
|
|
7783
7784
|
`;
|
|
7784
|
-
const selectResultByKey = (tenantId, callId) => sql`
|
|
7785
|
+
const selectResultByKey = (tenantId, executionId, callId) => sql`
|
|
7785
7786
|
SELECT ${resultColumns}
|
|
7786
7787
|
FROM relay_tool_results
|
|
7787
|
-
WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId}
|
|
7788
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId}
|
|
7788
7789
|
`;
|
|
7789
7790
|
const insertCallBody = (tenantId, input, definition, placement = { kind: "local" }) => sql`
|
|
7790
7791
|
(
|
|
@@ -7823,13 +7824,13 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7823
7824
|
`,
|
|
7824
7825
|
orElse: () => (tenantId, input, definition, placement) => sql`
|
|
7825
7826
|
INSERT INTO relay_tool_calls ${insertCallBody(tenantId, input, definition, placement)}
|
|
7826
|
-
ON CONFLICT (tenant_id, id) DO NOTHING
|
|
7827
|
+
ON CONFLICT (tenant_id, execution_id, id) DO NOTHING
|
|
7827
7828
|
`
|
|
7828
7829
|
});
|
|
7829
7830
|
const insertCall = sql.onDialectOrElse({
|
|
7830
7831
|
mysql: () => (tenantId, input, definition, placement) => sql.withTransaction(Effect37.gen(function* () {
|
|
7831
7832
|
yield* insertCallStatement(tenantId, input, definition, placement);
|
|
7832
|
-
return yield* selectCallByKey(tenantId, input.call.id);
|
|
7833
|
+
return yield* selectCallByKey(tenantId, input.executionId, input.call.id);
|
|
7833
7834
|
})),
|
|
7834
7835
|
orElse: () => (tenantId, input, definition, placement) => sql`
|
|
7835
7836
|
${insertCallStatement(tenantId, input, definition, placement)}
|
|
@@ -7838,10 +7839,11 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7838
7839
|
});
|
|
7839
7840
|
const insertResultStatement = (tenantId, input) => sql`
|
|
7840
7841
|
INSERT INTO relay_tool_results (
|
|
7841
|
-
tenant_id, ${resultColumns}
|
|
7842
|
+
tenant_id, execution_id, ${resultColumns}
|
|
7842
7843
|
)
|
|
7843
7844
|
VALUES (
|
|
7844
7845
|
${tenantId},
|
|
7846
|
+
${input.executionId},
|
|
7845
7847
|
${input.result.call_id},
|
|
7846
7848
|
${encodeJson(input.result.output)},
|
|
7847
7849
|
${input.result.error ?? null},
|
|
@@ -7849,19 +7851,19 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7849
7851
|
${timestampParam(sql, input.createdAt)}
|
|
7850
7852
|
)
|
|
7851
7853
|
`;
|
|
7852
|
-
const selectAttempts = (tenantId, callId) => sql`
|
|
7854
|
+
const selectAttempts = (tenantId, executionId, callId) => sql`
|
|
7853
7855
|
SELECT ${attemptColumns}
|
|
7854
7856
|
FROM relay_tool_attempts
|
|
7855
|
-
WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId}
|
|
7857
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId}
|
|
7856
7858
|
ORDER BY attempt_number ASC
|
|
7857
7859
|
`;
|
|
7858
7860
|
const lockedCallRows = sql.onDialectOrElse({
|
|
7859
|
-
pg: () => (tenantId, callId) => sql`
|
|
7860
|
-
${selectCallByKey(tenantId, callId)}
|
|
7861
|
+
pg: () => (tenantId, executionId, callId) => sql`
|
|
7862
|
+
${selectCallByKey(tenantId, executionId, callId)}
|
|
7861
7863
|
FOR UPDATE
|
|
7862
7864
|
`,
|
|
7863
|
-
mysql: () => (tenantId, callId) => sql`
|
|
7864
|
-
${selectCallByKey(tenantId, callId)}
|
|
7865
|
+
mysql: () => (tenantId, executionId, callId) => sql`
|
|
7866
|
+
${selectCallByKey(tenantId, executionId, callId)}
|
|
7865
7867
|
FOR UPDATE
|
|
7866
7868
|
`,
|
|
7867
7869
|
orElse: () => selectCallByKey
|
|
@@ -7874,35 +7876,35 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7874
7876
|
const decoded = yield* decodeAttemptRow(row);
|
|
7875
7877
|
return yield* Effect37.try({ try: () => toAttemptRecord(decoded), catch: toRepositoryError17 });
|
|
7876
7878
|
});
|
|
7877
|
-
const readLockedCall = Effect37.fn("ToolCallRepository.readLockedCall")(function* (tenantId, callId) {
|
|
7878
|
-
const rows = yield* lockedCallRows(tenantId, callId).pipe(Effect37.mapError(toRepositoryError17));
|
|
7879
|
+
const readLockedCall = Effect37.fn("ToolCallRepository.readLockedCall")(function* (tenantId, executionId, callId) {
|
|
7880
|
+
const rows = yield* lockedCallRows(tenantId, executionId, callId).pipe(Effect37.mapError(toRepositoryError17));
|
|
7879
7881
|
if (rows[0] === undefined)
|
|
7880
7882
|
return yield* ToolCallNotFound.make({ id: callId });
|
|
7881
7883
|
return yield* decodeCall(rows[0]);
|
|
7882
7884
|
});
|
|
7883
|
-
const readAttempts = Effect37.fn("ToolCallRepository.readAttempts")(function* (tenantId, callId) {
|
|
7884
|
-
const rows = yield* selectAttempts(tenantId, callId).pipe(Effect37.mapError(toRepositoryError17));
|
|
7885
|
+
const readAttempts = Effect37.fn("ToolCallRepository.readAttempts")(function* (tenantId, executionId, callId) {
|
|
7886
|
+
const rows = yield* selectAttempts(tenantId, executionId, callId).pipe(Effect37.mapError(toRepositoryError17));
|
|
7885
7887
|
return yield* Effect37.forEach(rows, decodeAttempt);
|
|
7886
7888
|
});
|
|
7887
|
-
const nextAttemptNumber = Effect37.fn("ToolCallRepository.nextAttemptNumber")(function* (tenantId, callId) {
|
|
7889
|
+
const nextAttemptNumber = Effect37.fn("ToolCallRepository.nextAttemptNumber")(function* (tenantId, executionId, callId) {
|
|
7888
7890
|
const rows = yield* sql`
|
|
7889
7891
|
SELECT COALESCE(MAX(attempt_number), 0) AS max_attempt
|
|
7890
7892
|
FROM relay_tool_attempts
|
|
7891
|
-
WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId}
|
|
7893
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId}
|
|
7892
7894
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
7893
7895
|
const row = yield* decodeMaxAttemptRow(rows[0]);
|
|
7894
7896
|
const max = Number(row?.max_attempt ?? 0);
|
|
7895
7897
|
return max + 1;
|
|
7896
7898
|
});
|
|
7897
|
-
const insertAttemptNumber = Effect37.fn("ToolCallRepository.insertAttemptNumber")(function* (tenantId, callId, attemptNumber, createdAt, workerId, claimExpiresAt) {
|
|
7899
|
+
const insertAttemptNumber = Effect37.fn("ToolCallRepository.insertAttemptNumber")(function* (tenantId, executionId, callId, attemptNumber, createdAt, workerId, claimExpiresAt) {
|
|
7898
7900
|
const attemptId = toolAttemptId(attemptNumber);
|
|
7899
7901
|
yield* sql`
|
|
7900
7902
|
INSERT INTO relay_tool_attempts (
|
|
7901
|
-
tenant_id, id, tool_call_id, attempt_number, state, worker_id, claim_expires_at,
|
|
7903
|
+
tenant_id, execution_id, id, tool_call_id, attempt_number, state, worker_id, claim_expires_at,
|
|
7902
7904
|
error, created_at, completed_at
|
|
7903
7905
|
)
|
|
7904
7906
|
VALUES (
|
|
7905
|
-
${tenantId}, ${attemptId}, ${callId}, ${attemptNumber}, 'running', ${workerId ?? null},
|
|
7907
|
+
${tenantId}, ${executionId}, ${attemptId}, ${callId}, ${attemptNumber}, 'running', ${workerId ?? null},
|
|
7906
7908
|
${claimExpiresAt === undefined ? null : ts(claimExpiresAt)}, ${null}, ${ts(createdAt)}, ${null}
|
|
7907
7909
|
)
|
|
7908
7910
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
@@ -7916,25 +7918,25 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7916
7918
|
createdAt
|
|
7917
7919
|
};
|
|
7918
7920
|
});
|
|
7919
|
-
const insertAttempt = Effect37.fn("ToolCallRepository.insertAttempt")(function* (tenantId, callId, createdAt, workerId, claimExpiresAt) {
|
|
7920
|
-
const attemptNumber = yield* nextAttemptNumber(tenantId, callId);
|
|
7921
|
-
return yield* insertAttemptNumber(tenantId, callId, attemptNumber, createdAt, workerId, claimExpiresAt);
|
|
7921
|
+
const insertAttempt = Effect37.fn("ToolCallRepository.insertAttempt")(function* (tenantId, executionId, callId, createdAt, workerId, claimExpiresAt) {
|
|
7922
|
+
const attemptNumber = yield* nextAttemptNumber(tenantId, executionId, callId);
|
|
7923
|
+
return yield* insertAttemptNumber(tenantId, executionId, callId, attemptNumber, createdAt, workerId, claimExpiresAt);
|
|
7922
7924
|
});
|
|
7923
|
-
const loadAttempt = Effect37.fn("ToolCallRepository.loadAttempt")(function* (tenantId, callId, attemptId) {
|
|
7925
|
+
const loadAttempt = Effect37.fn("ToolCallRepository.loadAttempt")(function* (tenantId, executionId, callId, attemptId) {
|
|
7924
7926
|
const rows = yield* sql`
|
|
7925
7927
|
SELECT ${attemptColumns}
|
|
7926
7928
|
FROM relay_tool_attempts
|
|
7927
|
-
WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId} AND id = ${attemptId}
|
|
7929
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId} AND id = ${attemptId}
|
|
7928
7930
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
7929
7931
|
return rows[0] === undefined ? undefined : yield* decodeAttempt(rows[0]);
|
|
7930
7932
|
});
|
|
7931
|
-
const completeAttempt = Effect37.fn("ToolCallRepository.completeAttempt")(function* (tenantId, callId, attemptId, state, completedAt, error5) {
|
|
7933
|
+
const completeAttempt = Effect37.fn("ToolCallRepository.completeAttempt")(function* (tenantId, executionId, callId, attemptId, state, completedAt, error5) {
|
|
7932
7934
|
yield* sql`
|
|
7933
7935
|
UPDATE relay_tool_attempts
|
|
7934
7936
|
SET state = ${state}, error = ${error5 ?? null}, completed_at = ${ts(completedAt)}
|
|
7935
|
-
WHERE tenant_id = ${tenantId} AND tool_call_id = ${callId} AND id = ${attemptId} AND state = 'running'
|
|
7937
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND tool_call_id = ${callId} AND id = ${attemptId} AND state = 'running'
|
|
7936
7938
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
7937
|
-
const attempt = yield* loadAttempt(tenantId, callId, attemptId);
|
|
7939
|
+
const attempt = yield* loadAttempt(tenantId, executionId, callId, attemptId);
|
|
7938
7940
|
if (attempt === undefined) {
|
|
7939
7941
|
return yield* ToolCallRepositoryError.make({ message: `Tool attempt not found: ${attemptId}` });
|
|
7940
7942
|
}
|
|
@@ -7944,7 +7946,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7944
7946
|
const tenantId = yield* current();
|
|
7945
7947
|
return yield* sql.withTransaction(Effect37.gen(function* () {
|
|
7946
7948
|
yield* insertCallIgnore(tenantId, input, input.definition, input.placement);
|
|
7947
|
-
const rows = yield* lockedCallRows(tenantId, input.call.id);
|
|
7949
|
+
const rows = yield* lockedCallRows(tenantId, input.executionId, input.call.id);
|
|
7948
7950
|
if (rows[0] === undefined)
|
|
7949
7951
|
return yield* ToolCallNotFound.make({ id: input.call.id });
|
|
7950
7952
|
const existing = yield* decodeCall(rows[0]);
|
|
@@ -7960,7 +7962,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7960
7962
|
const prepareExternalWait = Effect37.fn("ToolCallRepository.prepareExternalWait")(function* (input) {
|
|
7961
7963
|
const tenantId = yield* current();
|
|
7962
7964
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
7963
|
-
const call = yield* readLockedCall(tenantId, input.callId);
|
|
7965
|
+
const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
7964
7966
|
if (call.placement.kind !== "client" && call.placement.kind !== "remote") {
|
|
7965
7967
|
return yield* ToolCallTransitionRejected.make({
|
|
7966
7968
|
id: input.callId,
|
|
@@ -7976,15 +7978,15 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7976
7978
|
UPDATE relay_tool_calls
|
|
7977
7979
|
SET state = 'waiting', wait_id = ${input.waitId}, available_at = ${ts(input.availableAt)},
|
|
7978
7980
|
updated_at = ${ts(input.updatedAt)}
|
|
7979
|
-
WHERE tenant_id = ${tenantId} AND id = ${input.callId} AND state = 'requested'
|
|
7981
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId} AND state = 'requested'
|
|
7980
7982
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
7981
|
-
return yield* readLockedCall(tenantId, input.callId);
|
|
7983
|
+
return yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
7982
7984
|
}));
|
|
7983
7985
|
});
|
|
7984
7986
|
const beginAttempt = Effect37.fn("ToolCallRepository.beginAttempt")(function* (input) {
|
|
7985
7987
|
const tenantId = yield* current();
|
|
7986
7988
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
7987
|
-
const call = yield* readLockedCall(tenantId, input.callId);
|
|
7989
|
+
const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
7988
7990
|
if (call.placement.kind !== "local" && call.placement.kind !== "mcp") {
|
|
7989
7991
|
return yield* ToolCallTransitionRejected.make({
|
|
7990
7992
|
id: input.callId,
|
|
@@ -7995,13 +7997,13 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
7995
7997
|
return yield* ToolCallTransitionRejected.make({ id: input.callId, message: `Call is ${call.state}` });
|
|
7996
7998
|
}
|
|
7997
7999
|
if (call.activeAttemptId !== undefined) {
|
|
7998
|
-
yield* completeAttempt(tenantId, input.callId, call.activeAttemptId, "abandoned", input.startedAt);
|
|
8000
|
+
yield* completeAttempt(tenantId, input.executionId, input.callId, call.activeAttemptId, "abandoned", input.startedAt);
|
|
7999
8001
|
}
|
|
8000
|
-
const attempt = yield* insertAttempt(tenantId, input.callId, input.startedAt);
|
|
8002
|
+
const attempt = yield* insertAttempt(tenantId, input.executionId, input.callId, input.startedAt);
|
|
8001
8003
|
yield* sql`
|
|
8002
8004
|
UPDATE relay_tool_calls
|
|
8003
8005
|
SET state = 'running', active_attempt_id = ${attempt.id}, updated_at = ${ts(input.startedAt)}
|
|
8004
|
-
WHERE tenant_id = ${tenantId} AND id = ${input.callId}
|
|
8006
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
|
|
8005
8007
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8006
8008
|
return attempt;
|
|
8007
8009
|
}));
|
|
@@ -8009,7 +8011,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8009
8011
|
const acceptClientOutcome = Effect37.fn("ToolCallRepository.acceptClientOutcome")(function* (input) {
|
|
8010
8012
|
const tenantId = yield* current();
|
|
8011
8013
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
8012
|
-
const call = yield* readLockedCall(tenantId, input.callId);
|
|
8014
|
+
const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
8013
8015
|
if (call.executionId !== input.executionId || call.placement.kind !== "client") {
|
|
8014
8016
|
return yield* ToolCallTransitionRejected.make({
|
|
8015
8017
|
id: input.callId,
|
|
@@ -8026,7 +8028,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8026
8028
|
message: "Accepted attempt is missing"
|
|
8027
8029
|
});
|
|
8028
8030
|
}
|
|
8029
|
-
const attempt2 = yield* loadAttempt(tenantId, input.callId, call.activeAttemptId);
|
|
8031
|
+
const attempt2 = yield* loadAttempt(tenantId, input.executionId, input.callId, call.activeAttemptId);
|
|
8030
8032
|
if (attempt2 === undefined) {
|
|
8031
8033
|
return yield* ToolCallTransitionRejected.make({
|
|
8032
8034
|
id: input.callId,
|
|
@@ -8038,21 +8040,21 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8038
8040
|
if (call.state !== "waiting") {
|
|
8039
8041
|
return yield* ToolCallTransitionRejected.make({ id: input.callId, message: `Call is ${call.state}` });
|
|
8040
8042
|
}
|
|
8041
|
-
const running = yield* insertAttempt(tenantId, input.callId, input.submittedAt);
|
|
8042
|
-
const attempt = yield* completeAttempt(tenantId, input.callId, running.id, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
|
|
8043
|
+
const running = yield* insertAttempt(tenantId, input.executionId, input.callId, input.submittedAt);
|
|
8044
|
+
const attempt = yield* completeAttempt(tenantId, input.executionId, input.callId, running.id, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
|
|
8043
8045
|
yield* sql`
|
|
8044
8046
|
UPDATE relay_tool_calls
|
|
8045
8047
|
SET state = 'submitted', active_attempt_id = ${attempt.id},
|
|
8046
8048
|
external_outcome_json = ${encodeJson(input.outcome)},
|
|
8047
8049
|
external_outcome_at = ${ts(input.submittedAt)}, updated_at = ${ts(input.submittedAt)}
|
|
8048
|
-
WHERE tenant_id = ${tenantId} AND id = ${input.callId}
|
|
8050
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
|
|
8049
8051
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8050
|
-
const updated = yield* readLockedCall(tenantId, input.callId);
|
|
8052
|
+
const updated = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
8051
8053
|
return { call: updated, attempt, duplicate: false };
|
|
8052
8054
|
}));
|
|
8053
8055
|
});
|
|
8054
8056
|
const claimCandidate = (tenantId, input) => sql`
|
|
8055
|
-
SELECT id
|
|
8057
|
+
SELECT execution_id, id
|
|
8056
8058
|
FROM relay_tool_calls
|
|
8057
8059
|
WHERE tenant_id = ${tenantId} AND placement_kind = 'remote' AND placement_key = ${input.queue}
|
|
8058
8060
|
AND state = 'waiting' AND available_at <= ${ts(input.now)}
|
|
@@ -8071,20 +8073,20 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8071
8073
|
orElse: () => claimCandidate
|
|
8072
8074
|
});
|
|
8073
8075
|
const claimCall = sql.onDialectOrElse({
|
|
8074
|
-
mysql: () => (tenantId, callId, attemptId, input) => sql`
|
|
8076
|
+
mysql: () => (tenantId, executionId, callId, attemptId, input) => sql`
|
|
8075
8077
|
UPDATE relay_tool_calls
|
|
8076
8078
|
SET state = 'running', active_attempt_id = ${attemptId}, claim_owner = ${input.workerId},
|
|
8077
8079
|
claimed_at = ${ts(input.now)}, claim_expires_at = ${ts(input.claimExpiresAt)},
|
|
8078
8080
|
updated_at = ${ts(input.now)}
|
|
8079
|
-
WHERE tenant_id = ${tenantId} AND id = ${callId} AND state = 'waiting'
|
|
8081
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state = 'waiting'
|
|
8080
8082
|
AND available_at <= ${ts(input.now)}
|
|
8081
8083
|
`.pipe(Effect37.as([{ id: callId }])),
|
|
8082
|
-
orElse: () => (tenantId, callId, attemptId, input) => sql`
|
|
8084
|
+
orElse: () => (tenantId, executionId, callId, attemptId, input) => sql`
|
|
8083
8085
|
UPDATE relay_tool_calls
|
|
8084
8086
|
SET state = 'running', active_attempt_id = ${attemptId}, claim_owner = ${input.workerId},
|
|
8085
8087
|
claimed_at = ${ts(input.now)}, claim_expires_at = ${ts(input.claimExpiresAt)},
|
|
8086
8088
|
updated_at = ${ts(input.now)}
|
|
8087
|
-
WHERE tenant_id = ${tenantId} AND id = ${callId} AND state = 'waiting'
|
|
8089
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state = 'waiting'
|
|
8088
8090
|
AND available_at <= ${ts(input.now)}
|
|
8089
8091
|
RETURNING id
|
|
8090
8092
|
`
|
|
@@ -8096,21 +8098,22 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8096
8098
|
const tenantId = yield* current();
|
|
8097
8099
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
8098
8100
|
const expiredRows = yield* sql`
|
|
8099
|
-
SELECT id, active_attempt_id
|
|
8101
|
+
SELECT execution_id, id, active_attempt_id
|
|
8100
8102
|
FROM relay_tool_calls
|
|
8101
8103
|
WHERE tenant_id = ${tenantId} AND placement_kind = 'remote' AND placement_key = ${input.queue}
|
|
8102
8104
|
AND state = 'running' AND claim_expires_at IS NOT NULL AND claim_expires_at <= ${ts(input.now)}
|
|
8103
8105
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8104
8106
|
const expired = yield* Schema35.decodeUnknownEffect(Schema35.Array(ExpiredCallRow))(expiredRows).pipe(Effect37.mapError(toRepositoryError17));
|
|
8105
8107
|
for (const row of expired) {
|
|
8108
|
+
const executionId2 = exports_ids_schema.ExecutionId.make(row.execution_id);
|
|
8106
8109
|
if (row.active_attempt_id !== null && row.active_attempt_id !== undefined) {
|
|
8107
|
-
yield* completeAttempt(tenantId, exports_ids_schema.ToolCallId.make(row.id), exports_ids_schema.ToolAttemptId.make(row.active_attempt_id), "expired", input.now);
|
|
8110
|
+
yield* completeAttempt(tenantId, executionId2, exports_ids_schema.ToolCallId.make(row.id), exports_ids_schema.ToolAttemptId.make(row.active_attempt_id), "expired", input.now);
|
|
8108
8111
|
}
|
|
8109
8112
|
yield* sql`
|
|
8110
8113
|
UPDATE relay_tool_calls
|
|
8111
8114
|
SET state = 'waiting', active_attempt_id = NULL, claim_owner = NULL, claimed_at = NULL,
|
|
8112
8115
|
claim_expires_at = NULL, updated_at = ${ts(input.now)}
|
|
8113
|
-
WHERE tenant_id = ${tenantId} AND id = ${row.id} AND state = 'running'
|
|
8116
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId2} AND id = ${row.id} AND state = 'running'
|
|
8114
8117
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8115
8118
|
}
|
|
8116
8119
|
const candidateRows = yield* selectClaimCandidate(tenantId, input).pipe(Effect37.mapError(toRepositoryError17));
|
|
@@ -8118,21 +8121,22 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8118
8121
|
const candidate = candidates[0];
|
|
8119
8122
|
if (candidate === undefined)
|
|
8120
8123
|
return;
|
|
8124
|
+
const executionId = exports_ids_schema.ExecutionId.make(candidate.execution_id);
|
|
8121
8125
|
const callId = exports_ids_schema.ToolCallId.make(candidate.id);
|
|
8122
|
-
const call = yield* readLockedCall(tenantId, callId);
|
|
8126
|
+
const call = yield* readLockedCall(tenantId, executionId, callId);
|
|
8123
8127
|
if (call.definition === undefined || call.placement.kind !== "remote") {
|
|
8124
8128
|
return yield* ToolCallTransitionRejected.make({
|
|
8125
8129
|
id: callId,
|
|
8126
8130
|
message: "Remote call definition snapshot is missing"
|
|
8127
8131
|
});
|
|
8128
8132
|
}
|
|
8129
|
-
const attemptNumber = yield* nextAttemptNumber(tenantId, callId);
|
|
8133
|
+
const attemptNumber = yield* nextAttemptNumber(tenantId, executionId, callId);
|
|
8130
8134
|
const attemptId = toolAttemptId(attemptNumber);
|
|
8131
|
-
const claimed = yield* claimCall(tenantId, callId, attemptId, input).pipe(Effect37.mapError(toRepositoryError17));
|
|
8135
|
+
const claimed = yield* claimCall(tenantId, executionId, callId, attemptId, input).pipe(Effect37.mapError(toRepositoryError17));
|
|
8132
8136
|
if (claimed[0] === undefined)
|
|
8133
8137
|
return;
|
|
8134
|
-
const attempt = yield* insertAttemptNumber(tenantId, callId, attemptNumber, input.now, input.workerId, input.claimExpiresAt);
|
|
8135
|
-
const updated = yield* readLockedCall(tenantId, callId);
|
|
8138
|
+
const attempt = yield* insertAttemptNumber(tenantId, executionId, callId, attemptNumber, input.now, input.workerId, input.claimExpiresAt);
|
|
8139
|
+
const updated = yield* readLockedCall(tenantId, executionId, callId);
|
|
8136
8140
|
if (updated.definition === undefined || updated.placement.kind !== "remote") {
|
|
8137
8141
|
return yield* ToolCallTransitionRejected.make({
|
|
8138
8142
|
id: callId,
|
|
@@ -8152,25 +8156,25 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8152
8156
|
const releaseRemote = Effect37.fn("ToolCallRepository.releaseRemote")(function* (input) {
|
|
8153
8157
|
const tenantId = yield* current();
|
|
8154
8158
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
8155
|
-
const call = yield* readLockedCall(tenantId, input.callId);
|
|
8159
|
+
const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
8156
8160
|
if (call.placement.kind !== "remote" || call.state !== "running" || call.activeAttemptId !== input.attemptId || call.claimOwner !== input.workerId || call.claimExpiresAt === undefined || call.claimExpiresAt <= input.releasedAt) {
|
|
8157
8161
|
return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
|
|
8158
8162
|
}
|
|
8159
|
-
yield* completeAttempt(tenantId, input.callId, input.attemptId, "released", input.releasedAt, input.error);
|
|
8163
|
+
yield* completeAttempt(tenantId, input.executionId, input.callId, input.attemptId, "released", input.releasedAt, input.error);
|
|
8160
8164
|
yield* sql`
|
|
8161
8165
|
UPDATE relay_tool_calls
|
|
8162
8166
|
SET state = 'waiting', available_at = ${ts(input.nextAvailableAt)}, active_attempt_id = NULL,
|
|
8163
8167
|
claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
|
|
8164
8168
|
updated_at = ${ts(input.releasedAt)}
|
|
8165
|
-
WHERE tenant_id = ${tenantId} AND id = ${input.callId}
|
|
8169
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
|
|
8166
8170
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8167
|
-
return yield* readLockedCall(tenantId, input.callId);
|
|
8171
|
+
return yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
8168
8172
|
}));
|
|
8169
8173
|
});
|
|
8170
8174
|
const acceptRemoteOutcome = Effect37.fn("ToolCallRepository.acceptRemoteOutcome")(function* (input) {
|
|
8171
8175
|
const tenantId = yield* current();
|
|
8172
8176
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
8173
|
-
const call = yield* readLockedCall(tenantId, input.callId);
|
|
8177
|
+
const call = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
8174
8178
|
if (call.externalOutcome !== undefined) {
|
|
8175
8179
|
if (!exports_shared_schema.canonicalEquals(call.externalOutcome, input.outcome)) {
|
|
8176
8180
|
return yield* ToolOutcomeConflict.make({ id: input.callId });
|
|
@@ -8178,7 +8182,7 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8178
8182
|
if (call.activeAttemptId !== input.attemptId) {
|
|
8179
8183
|
return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
|
|
8180
8184
|
}
|
|
8181
|
-
const attempt2 = yield* loadAttempt(tenantId, input.callId, input.attemptId);
|
|
8185
|
+
const attempt2 = yield* loadAttempt(tenantId, input.executionId, input.callId, input.attemptId);
|
|
8182
8186
|
if (attempt2 === undefined || attempt2.callId !== input.callId || attempt2.workerId !== input.workerId) {
|
|
8183
8187
|
return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
|
|
8184
8188
|
}
|
|
@@ -8187,21 +8191,21 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8187
8191
|
if (call.placement.kind !== "remote" || call.state !== "running" || call.activeAttemptId !== input.attemptId || call.claimOwner !== input.workerId || call.claimExpiresAt === undefined || call.claimExpiresAt <= input.submittedAt) {
|
|
8188
8192
|
return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
|
|
8189
8193
|
}
|
|
8190
|
-
const attempt = yield* completeAttempt(tenantId, input.callId, input.attemptId, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
|
|
8194
|
+
const attempt = yield* completeAttempt(tenantId, input.executionId, input.callId, input.attemptId, input.outcome.kind === "success" ? "completed" : "failed", input.submittedAt, input.outcome.kind === "failure" ? input.outcome.message : undefined);
|
|
8191
8195
|
yield* sql`
|
|
8192
8196
|
UPDATE relay_tool_calls
|
|
8193
8197
|
SET state = 'submitted', external_outcome_json = ${encodeJson(input.outcome)},
|
|
8194
8198
|
external_outcome_at = ${ts(input.submittedAt)}, claim_owner = NULL, claimed_at = NULL,
|
|
8195
8199
|
claim_expires_at = NULL, updated_at = ${ts(input.submittedAt)}
|
|
8196
|
-
WHERE tenant_id = ${tenantId} AND id = ${input.callId}
|
|
8200
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.callId}
|
|
8197
8201
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8198
|
-
const updated = yield* readLockedCall(tenantId, input.callId);
|
|
8202
|
+
const updated = yield* readLockedCall(tenantId, input.executionId, input.callId);
|
|
8199
8203
|
return { call: updated, attempt, duplicate: false };
|
|
8200
8204
|
}));
|
|
8201
8205
|
});
|
|
8202
|
-
const listAttempts = Effect37.fn("ToolCallRepository.listAttempts")(function* (callId) {
|
|
8206
|
+
const listAttempts = Effect37.fn("ToolCallRepository.listAttempts")(function* (executionId, callId) {
|
|
8203
8207
|
const tenantId = yield* current();
|
|
8204
|
-
return yield* readAttempts(tenantId, callId);
|
|
8208
|
+
return yield* readAttempts(tenantId, executionId, callId);
|
|
8205
8209
|
});
|
|
8206
8210
|
const selectOpenCalls = sql.onDialectOrElse({
|
|
8207
8211
|
pg: () => (tenantId, input) => sql`
|
|
@@ -8229,17 +8233,17 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8229
8233
|
`
|
|
8230
8234
|
});
|
|
8231
8235
|
const failCall = sql.onDialectOrElse({
|
|
8232
|
-
mysql: () => (tenantId, callId, failedAt) => sql`
|
|
8236
|
+
mysql: () => (tenantId, executionId, callId, failedAt) => sql`
|
|
8233
8237
|
UPDATE relay_tool_calls
|
|
8234
8238
|
SET state = 'failed', claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
|
|
8235
8239
|
updated_at = ${ts(failedAt)}
|
|
8236
|
-
WHERE tenant_id = ${tenantId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
|
|
8240
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
|
|
8237
8241
|
`.pipe(Effect37.as([{ id: callId }])),
|
|
8238
|
-
orElse: () => (tenantId, callId, failedAt) => sql`
|
|
8242
|
+
orElse: () => (tenantId, executionId, callId, failedAt) => sql`
|
|
8239
8243
|
UPDATE relay_tool_calls
|
|
8240
8244
|
SET state = 'failed', claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
|
|
8241
8245
|
updated_at = ${ts(failedAt)}
|
|
8242
|
-
WHERE tenant_id = ${tenantId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
|
|
8246
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${executionId} AND id = ${callId} AND state NOT IN ('submitted', 'completed', 'failed')
|
|
8243
8247
|
RETURNING id
|
|
8244
8248
|
`
|
|
8245
8249
|
});
|
|
@@ -8253,30 +8257,31 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8253
8257
|
for (const call of open) {
|
|
8254
8258
|
if (selected !== undefined && !selected.has(call.call.id))
|
|
8255
8259
|
continue;
|
|
8256
|
-
const transitioned = yield* failCall(tenantId, call.call.id, input.failedAt).pipe(Effect37.mapError(toRepositoryError17));
|
|
8260
|
+
const transitioned = yield* failCall(tenantId, input.executionId, call.call.id, input.failedAt).pipe(Effect37.mapError(toRepositoryError17));
|
|
8257
8261
|
if (transitioned[0] === undefined)
|
|
8258
8262
|
continue;
|
|
8259
8263
|
if (call.activeAttemptId !== undefined) {
|
|
8260
|
-
const attempt = yield* loadAttempt(tenantId, call.call.id, call.activeAttemptId);
|
|
8264
|
+
const attempt = yield* loadAttempt(tenantId, input.executionId, call.call.id, call.activeAttemptId);
|
|
8261
8265
|
if (attempt?.state === "running") {
|
|
8262
|
-
yield* completeAttempt(tenantId, call.call.id, call.activeAttemptId, "failed", input.failedAt, input.message);
|
|
8266
|
+
yield* completeAttempt(tenantId, input.executionId, call.call.id, call.activeAttemptId, "failed", input.failedAt, input.message);
|
|
8263
8267
|
}
|
|
8264
8268
|
}
|
|
8265
|
-
const existingResult = yield* selectResultByKey(tenantId, call.call.id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8269
|
+
const existingResult = yield* selectResultByKey(tenantId, input.executionId, call.call.id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8266
8270
|
if (existingResult[0] === undefined) {
|
|
8267
8271
|
yield* insertResultStatement(tenantId, {
|
|
8272
|
+
executionId: input.executionId,
|
|
8268
8273
|
result: { call_id: call.call.id, output: null, error: input.message },
|
|
8269
8274
|
createdAt: input.failedAt
|
|
8270
8275
|
}).pipe(Effect37.mapError(toRepositoryError17));
|
|
8271
8276
|
}
|
|
8272
|
-
failed.push(yield* readLockedCall(tenantId, call.call.id));
|
|
8277
|
+
failed.push(yield* readLockedCall(tenantId, input.executionId, call.call.id));
|
|
8273
8278
|
}
|
|
8274
8279
|
return failed;
|
|
8275
8280
|
}));
|
|
8276
8281
|
});
|
|
8277
8282
|
const recordCall = Effect37.fn("ToolCallRepository.recordCall")(function* (input) {
|
|
8278
8283
|
const tenantId = yield* current();
|
|
8279
|
-
const existing = yield* selectCallByKey(tenantId, input.call.id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8284
|
+
const existing = yield* selectCallByKey(tenantId, input.executionId, input.call.id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8280
8285
|
if (existing[0] !== undefined)
|
|
8281
8286
|
return yield* DuplicateToolCall.make({ id: input.call.id });
|
|
8282
8287
|
const rows = yield* insertCall(tenantId, input).pipe(Effect37.mapError(toRepositoryError17));
|
|
@@ -8286,9 +8291,9 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8286
8291
|
}
|
|
8287
8292
|
return yield* decodeCall(row);
|
|
8288
8293
|
});
|
|
8289
|
-
const getCall = Effect37.fn("ToolCallRepository.getCall")(function* (id) {
|
|
8294
|
+
const getCall = Effect37.fn("ToolCallRepository.getCall")(function* (executionId, id) {
|
|
8290
8295
|
const tenantId = yield* current();
|
|
8291
|
-
const rows = yield* selectCallByKey(tenantId, id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8296
|
+
const rows = yield* selectCallByKey(tenantId, executionId, id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8292
8297
|
return rows[0] === undefined ? undefined : yield* decodeCall(rows[0]);
|
|
8293
8298
|
});
|
|
8294
8299
|
const listCalls = Effect37.fn("ToolCallRepository.listCalls")(function* (executionId) {
|
|
@@ -8304,16 +8309,16 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8304
8309
|
const recordResult = Effect37.fn("ToolCallRepository.recordResult")(function* (input) {
|
|
8305
8310
|
const tenantId = yield* current();
|
|
8306
8311
|
return yield* repositoryTransaction(Effect37.gen(function* () {
|
|
8307
|
-
const call = yield* readLockedCall(tenantId, input.result.call_id);
|
|
8308
|
-
const existing = yield* selectResultByKey(tenantId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8312
|
+
const call = yield* readLockedCall(tenantId, input.executionId, input.result.call_id);
|
|
8313
|
+
const existing = yield* selectResultByKey(tenantId, input.executionId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8309
8314
|
if (existing[0] !== undefined) {
|
|
8310
8315
|
return yield* DuplicateToolResult.make({ call_id: input.result.call_id });
|
|
8311
8316
|
}
|
|
8312
8317
|
yield* insertResultStatement(tenantId, input).pipe(Effect37.mapError(toRepositoryError17));
|
|
8313
8318
|
if (call.activeAttemptId !== undefined) {
|
|
8314
|
-
const attempt = yield* loadAttempt(tenantId, input.result.call_id, call.activeAttemptId);
|
|
8319
|
+
const attempt = yield* loadAttempt(tenantId, input.executionId, input.result.call_id, call.activeAttemptId);
|
|
8315
8320
|
if (attempt?.state === "running") {
|
|
8316
|
-
yield* completeAttempt(tenantId, input.result.call_id, call.activeAttemptId, input.result.error === undefined ? "completed" : "failed", input.createdAt, input.result.error);
|
|
8321
|
+
yield* completeAttempt(tenantId, input.executionId, input.result.call_id, call.activeAttemptId, input.result.error === undefined ? "completed" : "failed", input.createdAt, input.result.error);
|
|
8317
8322
|
}
|
|
8318
8323
|
}
|
|
8319
8324
|
yield* sql`
|
|
@@ -8321,18 +8326,18 @@ var layer31 = Layer36.effect(Service38, Effect37.gen(function* () {
|
|
|
8321
8326
|
SET state = ${input.result.error === undefined ? "completed" : "failed"},
|
|
8322
8327
|
claim_owner = NULL, claimed_at = NULL, claim_expires_at = NULL,
|
|
8323
8328
|
updated_at = ${ts(input.createdAt)}
|
|
8324
|
-
WHERE tenant_id = ${tenantId} AND id = ${input.result.call_id}
|
|
8329
|
+
WHERE tenant_id = ${tenantId} AND execution_id = ${input.executionId} AND id = ${input.result.call_id}
|
|
8325
8330
|
`.pipe(Effect37.mapError(toRepositoryError17));
|
|
8326
|
-
const rows = yield* selectResultByKey(tenantId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8331
|
+
const rows = yield* selectResultByKey(tenantId, input.executionId, input.result.call_id).pipe(Effect37.mapError(toRepositoryError17));
|
|
8327
8332
|
if (rows[0] === undefined) {
|
|
8328
8333
|
return yield* ToolCallRepositoryError.make({ message: "Tool result insert returned no row" });
|
|
8329
8334
|
}
|
|
8330
8335
|
return toResultRecord(yield* decodeResultRow(rows[0]));
|
|
8331
8336
|
}));
|
|
8332
8337
|
});
|
|
8333
|
-
const getResult = Effect37.fn("ToolCallRepository.getResult")(function* (callId) {
|
|
8338
|
+
const getResult = Effect37.fn("ToolCallRepository.getResult")(function* (executionId, callId) {
|
|
8334
8339
|
const tenantId = yield* current();
|
|
8335
|
-
const rows = yield* selectResultByKey(tenantId, callId).pipe(Effect37.mapError(toRepositoryError17));
|
|
8340
|
+
const rows = yield* selectResultByKey(tenantId, executionId, callId).pipe(Effect37.mapError(toRepositoryError17));
|
|
8336
8341
|
return rows[0] === undefined ? undefined : toResultRecord(yield* decodeResultRow(rows[0]));
|
|
8337
8342
|
});
|
|
8338
8343
|
return Service38.of({
|
|
@@ -8357,7 +8362,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8357
8362
|
const callTenants = new Map;
|
|
8358
8363
|
const results = new Map;
|
|
8359
8364
|
const attempts = new Map;
|
|
8360
|
-
const key3 = (tenantId, callId) => exports_shared_schema.canonicalString([tenantId, callId]);
|
|
8365
|
+
const key3 = (tenantId, executionId, callId) => exports_shared_schema.canonicalString([tenantId, executionId, callId]);
|
|
8361
8366
|
const same = (left, right) => exports_shared_schema.canonicalEquals(left, right);
|
|
8362
8367
|
const callRecord = (tenantId, input, definition, placement = { kind: "local" }) => ({
|
|
8363
8368
|
executionId: input.executionId,
|
|
@@ -8370,13 +8375,13 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8370
8375
|
createdAt: input.createdAt,
|
|
8371
8376
|
updatedAt: input.createdAt
|
|
8372
8377
|
});
|
|
8373
|
-
const attemptsFor = (tenantId, callId) => attempts.get(key3(tenantId, callId)) ?? [];
|
|
8374
|
-
const replaceAttempt = (tenantId, attempt) => {
|
|
8375
|
-
const callAttempts = attemptsFor(tenantId, attempt.callId);
|
|
8376
|
-
attempts.set(key3(tenantId, attempt.callId), callAttempts.map((existing) => existing.id === attempt.id ? attempt : existing));
|
|
8378
|
+
const attemptsFor = (tenantId, executionId, callId) => attempts.get(key3(tenantId, executionId, callId)) ?? [];
|
|
8379
|
+
const replaceAttempt = (tenantId, executionId, attempt) => {
|
|
8380
|
+
const callAttempts = attemptsFor(tenantId, executionId, attempt.callId);
|
|
8381
|
+
attempts.set(key3(tenantId, executionId, attempt.callId), callAttempts.map((existing) => existing.id === attempt.id ? attempt : existing));
|
|
8377
8382
|
};
|
|
8378
|
-
const appendAttempt = (tenantId, callId, createdAt, options = {}) => {
|
|
8379
|
-
const callAttempts = attemptsFor(tenantId, callId);
|
|
8383
|
+
const appendAttempt = (tenantId, executionId, callId, createdAt, options = {}) => {
|
|
8384
|
+
const callAttempts = attemptsFor(tenantId, executionId, callId);
|
|
8380
8385
|
const attemptNumber = callAttempts.length + 1;
|
|
8381
8386
|
const attempt = {
|
|
8382
8387
|
id: toolAttemptId(attemptNumber),
|
|
@@ -8387,18 +8392,18 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8387
8392
|
...options.claimExpiresAt === undefined ? {} : { claimExpiresAt: options.claimExpiresAt },
|
|
8388
8393
|
createdAt
|
|
8389
8394
|
};
|
|
8390
|
-
attempts.set(key3(tenantId, callId), [...callAttempts, attempt]);
|
|
8395
|
+
attempts.set(key3(tenantId, executionId, callId), [...callAttempts, attempt]);
|
|
8391
8396
|
return attempt;
|
|
8392
8397
|
};
|
|
8393
|
-
const requireCall = (tenantId, callId) => {
|
|
8394
|
-
const record2 = calls.get(key3(tenantId, callId));
|
|
8398
|
+
const requireCall = (tenantId, executionId, callId) => {
|
|
8399
|
+
const record2 = calls.get(key3(tenantId, executionId, callId));
|
|
8395
8400
|
return record2 === undefined ? Effect37.fail(ToolCallNotFound.make({ id: callId })) : Effect37.succeed(record2);
|
|
8396
8401
|
};
|
|
8397
8402
|
const transitionRejected = (id, message) => Effect37.fail(ToolCallTransitionRejected.make({ id, message }));
|
|
8398
8403
|
return Service38.of({
|
|
8399
8404
|
ensureCall: Effect37.fn("ToolCallRepository.memory.ensureCall")(function* (input) {
|
|
8400
8405
|
const tenantId = yield* current();
|
|
8401
|
-
const storageKey = key3(tenantId, input.call.id);
|
|
8406
|
+
const storageKey = key3(tenantId, input.executionId, input.call.id);
|
|
8402
8407
|
const existing = calls.get(storageKey);
|
|
8403
8408
|
if (existing !== undefined) {
|
|
8404
8409
|
if (existing.executionId !== input.executionId || !sameCallIdentity(existing.call, input.call) || !same(existing.definition, input.definition) || !same(existing.placement, input.placement)) {
|
|
@@ -8413,7 +8418,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8413
8418
|
}),
|
|
8414
8419
|
recordCall: Effect37.fn("ToolCallRepository.memory.recordCall")(function* (input) {
|
|
8415
8420
|
const tenantId = yield* current();
|
|
8416
|
-
const storageKey = key3(tenantId, input.call.id);
|
|
8421
|
+
const storageKey = key3(tenantId, input.executionId, input.call.id);
|
|
8417
8422
|
if (calls.has(storageKey))
|
|
8418
8423
|
return yield* DuplicateToolCall.make({ id: input.call.id });
|
|
8419
8424
|
const record2 = callRecord(tenantId, input);
|
|
@@ -8421,9 +8426,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8421
8426
|
callTenants.set(storageKey, tenantId);
|
|
8422
8427
|
return record2;
|
|
8423
8428
|
}),
|
|
8424
|
-
getCall: Effect37.fn("ToolCallRepository.memory.getCall")(function* (id) {
|
|
8429
|
+
getCall: Effect37.fn("ToolCallRepository.memory.getCall")(function* (executionId, id) {
|
|
8425
8430
|
const tenantId = yield* current();
|
|
8426
|
-
return calls.get(key3(tenantId, id));
|
|
8431
|
+
return calls.get(key3(tenantId, executionId, id));
|
|
8427
8432
|
}),
|
|
8428
8433
|
listCalls: Effect37.fn("ToolCallRepository.memory.listCalls")(function* (executionId) {
|
|
8429
8434
|
const tenantId = yield* current();
|
|
@@ -8431,7 +8436,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8431
8436
|
}),
|
|
8432
8437
|
recordResult: Effect37.fn("ToolCallRepository.memory.recordResult")(function* (input) {
|
|
8433
8438
|
const tenantId = yield* current();
|
|
8434
|
-
const storageKey = key3(tenantId, input.result.call_id);
|
|
8439
|
+
const storageKey = key3(tenantId, input.executionId, input.result.call_id);
|
|
8435
8440
|
const call = calls.get(storageKey);
|
|
8436
8441
|
if (call === undefined)
|
|
8437
8442
|
return yield* ToolCallNotFound.make({ id: input.result.call_id });
|
|
@@ -8439,9 +8444,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8439
8444
|
return yield* DuplicateToolResult.make({ call_id: input.result.call_id });
|
|
8440
8445
|
}
|
|
8441
8446
|
if (call.activeAttemptId !== undefined) {
|
|
8442
|
-
const active = attemptsFor(tenantId, input.result.call_id).find((attempt) => attempt.id === call.activeAttemptId);
|
|
8447
|
+
const active = attemptsFor(tenantId, input.executionId, input.result.call_id).find((attempt) => attempt.id === call.activeAttemptId);
|
|
8443
8448
|
if (active?.state === "running") {
|
|
8444
|
-
replaceAttempt(tenantId, {
|
|
8449
|
+
replaceAttempt(tenantId, input.executionId, {
|
|
8445
8450
|
...active,
|
|
8446
8451
|
state: input.result.error === undefined ? "completed" : "failed",
|
|
8447
8452
|
...input.result.error === undefined ? {} : { error: input.result.error },
|
|
@@ -8458,13 +8463,13 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8458
8463
|
});
|
|
8459
8464
|
return record2;
|
|
8460
8465
|
}),
|
|
8461
|
-
getResult: Effect37.fn("ToolCallRepository.memory.getResult")(function* (callId) {
|
|
8466
|
+
getResult: Effect37.fn("ToolCallRepository.memory.getResult")(function* (executionId, callId) {
|
|
8462
8467
|
const tenantId = yield* current();
|
|
8463
|
-
return results.get(key3(tenantId, callId));
|
|
8468
|
+
return results.get(key3(tenantId, executionId, callId));
|
|
8464
8469
|
}),
|
|
8465
8470
|
prepareExternalWait: Effect37.fn("ToolCallRepository.memory.prepareExternalWait")(function* (input) {
|
|
8466
8471
|
const tenantId = yield* current();
|
|
8467
|
-
const call = yield* requireCall(tenantId, input.callId);
|
|
8472
|
+
const call = yield* requireCall(tenantId, input.executionId, input.callId);
|
|
8468
8473
|
if (call.placement.kind !== "client" && call.placement.kind !== "remote") {
|
|
8469
8474
|
return yield* transitionRejected(input.callId, "Tool placement is not external");
|
|
8470
8475
|
}
|
|
@@ -8479,12 +8484,12 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8479
8484
|
availableAt: input.availableAt,
|
|
8480
8485
|
updatedAt: input.updatedAt
|
|
8481
8486
|
};
|
|
8482
|
-
calls.set(key3(tenantId, input.callId), updated);
|
|
8487
|
+
calls.set(key3(tenantId, input.executionId, input.callId), updated);
|
|
8483
8488
|
return updated;
|
|
8484
8489
|
}),
|
|
8485
8490
|
beginAttempt: Effect37.fn("ToolCallRepository.memory.beginAttempt")(function* (input) {
|
|
8486
8491
|
const tenantId = yield* current();
|
|
8487
|
-
const call = yield* requireCall(tenantId, input.callId);
|
|
8492
|
+
const call = yield* requireCall(tenantId, input.executionId, input.callId);
|
|
8488
8493
|
if (call.placement.kind !== "local" && call.placement.kind !== "mcp") {
|
|
8489
8494
|
return yield* transitionRejected(input.callId, "Tool placement is not immediate");
|
|
8490
8495
|
}
|
|
@@ -8492,13 +8497,13 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8492
8497
|
return yield* transitionRejected(input.callId, `Call is ${call.state}`);
|
|
8493
8498
|
}
|
|
8494
8499
|
if (call.activeAttemptId !== undefined) {
|
|
8495
|
-
const active = attemptsFor(tenantId, input.callId).find((attempt2) => attempt2.id === call.activeAttemptId);
|
|
8500
|
+
const active = attemptsFor(tenantId, input.executionId, input.callId).find((attempt2) => attempt2.id === call.activeAttemptId);
|
|
8496
8501
|
if (active?.state === "running") {
|
|
8497
|
-
replaceAttempt(tenantId, { ...active, state: "abandoned", completedAt: input.startedAt });
|
|
8502
|
+
replaceAttempt(tenantId, input.executionId, { ...active, state: "abandoned", completedAt: input.startedAt });
|
|
8498
8503
|
}
|
|
8499
8504
|
}
|
|
8500
|
-
const attempt = appendAttempt(tenantId, input.callId, input.startedAt);
|
|
8501
|
-
calls.set(key3(tenantId, input.callId), {
|
|
8505
|
+
const attempt = appendAttempt(tenantId, input.executionId, input.callId, input.startedAt);
|
|
8506
|
+
calls.set(key3(tenantId, input.executionId, input.callId), {
|
|
8502
8507
|
...call,
|
|
8503
8508
|
state: "running",
|
|
8504
8509
|
activeAttemptId: attempt.id,
|
|
@@ -8508,7 +8513,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8508
8513
|
}),
|
|
8509
8514
|
acceptClientOutcome: Effect37.fn("ToolCallRepository.memory.acceptClientOutcome")(function* (input) {
|
|
8510
8515
|
const tenantId = yield* current();
|
|
8511
|
-
const call = yield* requireCall(tenantId, input.callId);
|
|
8516
|
+
const call = yield* requireCall(tenantId, input.executionId, input.callId);
|
|
8512
8517
|
if (call.executionId !== input.executionId || call.placement.kind !== "client") {
|
|
8513
8518
|
return yield* transitionRejected(input.callId, "Client outcome does not match the call");
|
|
8514
8519
|
}
|
|
@@ -8516,21 +8521,21 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8516
8521
|
if (!same(call.externalOutcome, input.outcome)) {
|
|
8517
8522
|
return yield* ToolOutcomeConflict.make({ id: input.callId });
|
|
8518
8523
|
}
|
|
8519
|
-
const attempt2 = attemptsFor(tenantId, input.callId).find((item) => item.id === call.activeAttemptId);
|
|
8524
|
+
const attempt2 = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === call.activeAttemptId);
|
|
8520
8525
|
if (attempt2 === undefined)
|
|
8521
8526
|
return yield* transitionRejected(input.callId, "Accepted attempt is missing");
|
|
8522
8527
|
return { call, attempt: attempt2, duplicate: true };
|
|
8523
8528
|
}
|
|
8524
8529
|
if (call.state !== "waiting")
|
|
8525
8530
|
return yield* transitionRejected(input.callId, `Call is ${call.state}`);
|
|
8526
|
-
const running = appendAttempt(tenantId, input.callId, input.submittedAt);
|
|
8531
|
+
const running = appendAttempt(tenantId, input.executionId, input.callId, input.submittedAt);
|
|
8527
8532
|
const attempt = {
|
|
8528
8533
|
...running,
|
|
8529
8534
|
state: input.outcome.kind === "success" ? "completed" : "failed",
|
|
8530
8535
|
...input.outcome.kind === "failure" ? { error: input.outcome.message } : {},
|
|
8531
8536
|
completedAt: input.submittedAt
|
|
8532
8537
|
};
|
|
8533
|
-
replaceAttempt(tenantId, attempt);
|
|
8538
|
+
replaceAttempt(tenantId, input.executionId, attempt);
|
|
8534
8539
|
const updated = {
|
|
8535
8540
|
...call,
|
|
8536
8541
|
state: "submitted",
|
|
@@ -8539,7 +8544,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8539
8544
|
externalOutcomeAt: input.submittedAt,
|
|
8540
8545
|
updatedAt: input.submittedAt
|
|
8541
8546
|
};
|
|
8542
|
-
calls.set(key3(tenantId, input.callId), updated);
|
|
8547
|
+
calls.set(key3(tenantId, input.executionId, input.callId), updated);
|
|
8543
8548
|
return { call: updated, attempt, duplicate: false };
|
|
8544
8549
|
}),
|
|
8545
8550
|
claimRemote: Effect37.fn("ToolCallRepository.memory.claimRemote")(function* (input) {
|
|
@@ -8551,9 +8556,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8551
8556
|
if (callTenants.get(storageKey) !== tenantId || call.placement.kind !== "remote" || call.state !== "running" || call.claimExpiresAt === undefined || call.claimExpiresAt > input.now) {
|
|
8552
8557
|
continue;
|
|
8553
8558
|
}
|
|
8554
|
-
const active = attemptsFor(tenantId, call.call.id).find((attempt2) => attempt2.id === call.activeAttemptId);
|
|
8559
|
+
const active = attemptsFor(tenantId, call.executionId, call.call.id).find((attempt2) => attempt2.id === call.activeAttemptId);
|
|
8555
8560
|
if (active?.state === "running") {
|
|
8556
|
-
replaceAttempt(tenantId, { ...active, state: "expired", completedAt: input.now });
|
|
8561
|
+
replaceAttempt(tenantId, call.executionId, { ...active, state: "expired", completedAt: input.now });
|
|
8557
8562
|
}
|
|
8558
8563
|
calls.set(storageKey, {
|
|
8559
8564
|
...call,
|
|
@@ -8571,7 +8576,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8571
8576
|
if (candidate.definition === undefined) {
|
|
8572
8577
|
return yield* transitionRejected(candidate.call.id, "Remote call definition snapshot is missing");
|
|
8573
8578
|
}
|
|
8574
|
-
const attempt = appendAttempt(tenantId, candidate.call.id, input.now, {
|
|
8579
|
+
const attempt = appendAttempt(tenantId, candidate.executionId, candidate.call.id, input.now, {
|
|
8575
8580
|
workerId: input.workerId,
|
|
8576
8581
|
claimExpiresAt: input.claimExpiresAt
|
|
8577
8582
|
});
|
|
@@ -8585,7 +8590,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8585
8590
|
claimExpiresAt: input.claimExpiresAt,
|
|
8586
8591
|
updatedAt: input.now
|
|
8587
8592
|
};
|
|
8588
|
-
calls.set(key3(tenantId, candidate.call.id), updated);
|
|
8593
|
+
calls.set(key3(tenantId, candidate.executionId, candidate.call.id), updated);
|
|
8589
8594
|
return {
|
|
8590
8595
|
call: updated,
|
|
8591
8596
|
attempt,
|
|
@@ -8597,14 +8602,14 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8597
8602
|
}),
|
|
8598
8603
|
releaseRemote: Effect37.fn("ToolCallRepository.memory.releaseRemote")(function* (input) {
|
|
8599
8604
|
const tenantId = yield* current();
|
|
8600
|
-
const call = yield* requireCall(tenantId, input.callId);
|
|
8605
|
+
const call = yield* requireCall(tenantId, input.executionId, input.callId);
|
|
8601
8606
|
const valid = call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attemptId && call.claimOwner === input.workerId && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.releasedAt;
|
|
8602
8607
|
if (!valid)
|
|
8603
8608
|
return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
|
|
8604
|
-
const attempt = attemptsFor(tenantId, input.callId).find((item) => item.id === input.attemptId);
|
|
8609
|
+
const attempt = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === input.attemptId);
|
|
8605
8610
|
if (attempt === undefined)
|
|
8606
8611
|
return yield* transitionRejected(input.callId, "Remote attempt is missing");
|
|
8607
|
-
replaceAttempt(tenantId, {
|
|
8612
|
+
replaceAttempt(tenantId, input.executionId, {
|
|
8608
8613
|
...attempt,
|
|
8609
8614
|
state: "released",
|
|
8610
8615
|
...input.error === undefined ? {} : { error: input.error },
|
|
@@ -8620,12 +8625,12 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8620
8625
|
claimExpiresAt: undefined,
|
|
8621
8626
|
updatedAt: input.releasedAt
|
|
8622
8627
|
};
|
|
8623
|
-
calls.set(key3(tenantId, input.callId), updated);
|
|
8628
|
+
calls.set(key3(tenantId, input.executionId, input.callId), updated);
|
|
8624
8629
|
return updated;
|
|
8625
8630
|
}),
|
|
8626
8631
|
acceptRemoteOutcome: Effect37.fn("ToolCallRepository.memory.acceptRemoteOutcome")(function* (input) {
|
|
8627
8632
|
const tenantId = yield* current();
|
|
8628
|
-
const call = yield* requireCall(tenantId, input.callId);
|
|
8633
|
+
const call = yield* requireCall(tenantId, input.executionId, input.callId);
|
|
8629
8634
|
if (call.externalOutcome !== undefined) {
|
|
8630
8635
|
if (!same(call.externalOutcome, input.outcome)) {
|
|
8631
8636
|
return yield* ToolOutcomeConflict.make({ id: input.callId });
|
|
@@ -8633,7 +8638,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8633
8638
|
if (call.activeAttemptId !== input.attemptId) {
|
|
8634
8639
|
return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
|
|
8635
8640
|
}
|
|
8636
|
-
const attempt2 = attemptsFor(tenantId, input.callId).find((item) => item.id === input.attemptId);
|
|
8641
|
+
const attempt2 = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === input.attemptId);
|
|
8637
8642
|
if (attempt2 === undefined || attempt2.callId !== input.callId || attempt2.workerId !== input.workerId) {
|
|
8638
8643
|
return yield* ToolClaimRejected.make({ message: "Remote attempt was not accepted" });
|
|
8639
8644
|
}
|
|
@@ -8642,7 +8647,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8642
8647
|
const valid = call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attemptId && call.claimOwner === input.workerId && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.submittedAt;
|
|
8643
8648
|
if (!valid)
|
|
8644
8649
|
return yield* ToolClaimRejected.make({ message: "Remote claim is not active" });
|
|
8645
|
-
const running = attemptsFor(tenantId, input.callId).find((item) => item.id === input.attemptId);
|
|
8650
|
+
const running = attemptsFor(tenantId, input.executionId, input.callId).find((item) => item.id === input.attemptId);
|
|
8646
8651
|
if (running === undefined)
|
|
8647
8652
|
return yield* transitionRejected(input.callId, "Remote attempt is missing");
|
|
8648
8653
|
const attempt = {
|
|
@@ -8651,7 +8656,7 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8651
8656
|
...input.outcome.kind === "failure" ? { error: input.outcome.message } : {},
|
|
8652
8657
|
completedAt: input.submittedAt
|
|
8653
8658
|
};
|
|
8654
|
-
replaceAttempt(tenantId, attempt);
|
|
8659
|
+
replaceAttempt(tenantId, input.executionId, attempt);
|
|
8655
8660
|
const updated = {
|
|
8656
8661
|
...call,
|
|
8657
8662
|
state: "submitted",
|
|
@@ -8662,12 +8667,12 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8662
8667
|
claimExpiresAt: undefined,
|
|
8663
8668
|
updatedAt: input.submittedAt
|
|
8664
8669
|
};
|
|
8665
|
-
calls.set(key3(tenantId, input.callId), updated);
|
|
8670
|
+
calls.set(key3(tenantId, input.executionId, input.callId), updated);
|
|
8666
8671
|
return { call: updated, attempt, duplicate: false };
|
|
8667
8672
|
}),
|
|
8668
|
-
listAttempts: Effect37.fn("ToolCallRepository.memory.listAttempts")(function* (callId) {
|
|
8673
|
+
listAttempts: Effect37.fn("ToolCallRepository.memory.listAttempts")(function* (executionId, callId) {
|
|
8669
8674
|
const tenantId = yield* current();
|
|
8670
|
-
return attemptsFor(tenantId, callId);
|
|
8675
|
+
return attemptsFor(tenantId, executionId, callId);
|
|
8671
8676
|
}),
|
|
8672
8677
|
failOpenForExecution: Effect37.fn("ToolCallRepository.memory.failOpenForExecution")(function* (input) {
|
|
8673
8678
|
const tenantId = yield* current();
|
|
@@ -8677,9 +8682,9 @@ var memoryLayer29 = Layer36.sync(Service38, () => {
|
|
|
8677
8682
|
continue;
|
|
8678
8683
|
}
|
|
8679
8684
|
if (call.activeAttemptId !== undefined) {
|
|
8680
|
-
const active = attemptsFor(tenantId, call.call.id).find((attempt) => attempt.id === call.activeAttemptId);
|
|
8685
|
+
const active = attemptsFor(tenantId, input.executionId, call.call.id).find((attempt) => attempt.id === call.activeAttemptId);
|
|
8681
8686
|
if (active?.state === "running") {
|
|
8682
|
-
replaceAttempt(tenantId, {
|
|
8687
|
+
replaceAttempt(tenantId, input.executionId, {
|
|
8683
8688
|
...active,
|
|
8684
8689
|
state: "failed",
|
|
8685
8690
|
error: input.message,
|
|
@@ -8723,9 +8728,9 @@ var recordCall = Effect37.fn("ToolCallRepository.recordCall.call")(function* (in
|
|
|
8723
8728
|
const repository = yield* Service38;
|
|
8724
8729
|
return yield* repository.recordCall(input);
|
|
8725
8730
|
});
|
|
8726
|
-
var getCall = Effect37.fn("ToolCallRepository.getCall.call")(function* (id) {
|
|
8731
|
+
var getCall = Effect37.fn("ToolCallRepository.getCall.call")(function* (executionId, id) {
|
|
8727
8732
|
const repository = yield* Service38;
|
|
8728
|
-
return yield* repository.getCall(id);
|
|
8733
|
+
return yield* repository.getCall(executionId, id);
|
|
8729
8734
|
});
|
|
8730
8735
|
var listCalls = Effect37.fn("ToolCallRepository.listCalls.call")(function* (executionId) {
|
|
8731
8736
|
const repository = yield* Service38;
|
|
@@ -8735,9 +8740,9 @@ var recordResult = Effect37.fn("ToolCallRepository.recordResult.call")(function*
|
|
|
8735
8740
|
const repository = yield* Service38;
|
|
8736
8741
|
return yield* repository.recordResult(input);
|
|
8737
8742
|
});
|
|
8738
|
-
var getResult = Effect37.fn("ToolCallRepository.getResult.call")(function* (callId) {
|
|
8743
|
+
var getResult = Effect37.fn("ToolCallRepository.getResult.call")(function* (executionId, callId) {
|
|
8739
8744
|
const repository = yield* Service38;
|
|
8740
|
-
return yield* repository.getResult(callId);
|
|
8745
|
+
return yield* repository.getResult(executionId, callId);
|
|
8741
8746
|
});
|
|
8742
8747
|
var ensureCall = Effect37.fn("ToolCallRepository.ensureCall.call")(function* (input) {
|
|
8743
8748
|
const repository = yield* Service38;
|
|
@@ -8767,9 +8772,9 @@ var acceptRemoteOutcome = Effect37.fn("ToolCallRepository.acceptRemoteOutcome.ca
|
|
|
8767
8772
|
const repository = yield* Service38;
|
|
8768
8773
|
return yield* repository.acceptRemoteOutcome(input);
|
|
8769
8774
|
});
|
|
8770
|
-
var listAttempts = Effect37.fn("ToolCallRepository.listAttempts.call")(function* (callId) {
|
|
8775
|
+
var listAttempts = Effect37.fn("ToolCallRepository.listAttempts.call")(function* (executionId, callId) {
|
|
8771
8776
|
const repository = yield* Service38;
|
|
8772
|
-
return yield* repository.listAttempts(callId);
|
|
8777
|
+
return yield* repository.listAttempts(executionId, callId);
|
|
8773
8778
|
});
|
|
8774
8779
|
var failOpenForExecution = Effect37.fn("ToolCallRepository.failOpenForExecution.call")(function* (input) {
|
|
8775
8780
|
const repository = yield* Service38;
|
|
@@ -10078,6 +10083,13 @@ var cancel3 = Effect42.fn("WaitService.cancel.call")(function* (input) {
|
|
|
10078
10083
|
const service = yield* Service42;
|
|
10079
10084
|
return yield* service.cancel(input);
|
|
10080
10085
|
});
|
|
10086
|
+
// ../runtime/src/tool/tool-runtime-identifiers.ts
|
|
10087
|
+
var scopedPart = (value) => encodeURIComponent(value);
|
|
10088
|
+
var toolScope = (executionId, toolCallId) => `${scopedPart(executionId)}:${scopedPart(toolCallId)}`;
|
|
10089
|
+
var eventId = (executionId, toolCallId, kind) => exports_ids_schema.EventId.make(`event:${toolScope(executionId, toolCallId)}:${kind}`);
|
|
10090
|
+
var waitId = (kind, executionId, toolCallId) => exports_ids_schema.WaitId.make(`wait:${kind}:${toolScope(executionId, toolCallId)}`);
|
|
10091
|
+
var Identifiers = { eventId, waitId };
|
|
10092
|
+
|
|
10081
10093
|
// ../runtime/src/tool/tool-runtime-service.ts
|
|
10082
10094
|
var permissionNames = (permissions) => HashSet3.fromIterable(permissions.map((permission) => permission.name));
|
|
10083
10095
|
var requiredPermissionNames = (tool) => tool.requiredPermissions ?? tool.definition.permissions.map((permission) => permission.name);
|
|
@@ -10112,7 +10124,7 @@ var preserveToolError = (toolName, error5) => {
|
|
|
10112
10124
|
};
|
|
10113
10125
|
var preserveRecordResultError = (error5) => error5._tag === "ToolRuntimeError" ? error5 : mapRepositoryError3(error5);
|
|
10114
10126
|
var requestedEvent = (input) => ({
|
|
10115
|
-
id:
|
|
10127
|
+
id: Identifiers.eventId(input.executionId, input.call.id, "tool-requested"),
|
|
10116
10128
|
execution_id: input.executionId,
|
|
10117
10129
|
type: "tool.call.requested",
|
|
10118
10130
|
sequence: input.eventSequence,
|
|
@@ -10130,7 +10142,7 @@ var ensureToolEvent = (eventLog, event) => eventLog.findByCursor({ executionId:
|
|
|
10130
10142
|
onSome: (existing) => sameToolEventPayload(existing, event) ? Effect43.void : Effect43.fail(ToolRuntimeError.make({ message: "EventLogError" }))
|
|
10131
10143
|
})));
|
|
10132
10144
|
var resultEvent = (input, result, sequence) => ({
|
|
10133
|
-
id:
|
|
10145
|
+
id: Identifiers.eventId(input.executionId, input.call.id, "tool-result"),
|
|
10134
10146
|
execution_id: input.executionId,
|
|
10135
10147
|
type: "tool.result.received",
|
|
10136
10148
|
sequence,
|
|
@@ -10199,11 +10211,11 @@ var finalToolResult = (tool, input, idempotencyKey) => Effect43.gen(function* ()
|
|
|
10199
10211
|
output: jsonValue2(output)
|
|
10200
10212
|
};
|
|
10201
10213
|
});
|
|
10202
|
-
var approvalWaitId = (input) =>
|
|
10203
|
-
var permissionWaitId = (input) =>
|
|
10214
|
+
var approvalWaitId = (input) => Identifiers.waitId("approval", input.executionId, input.call.id);
|
|
10215
|
+
var permissionWaitId = (input) => Identifiers.waitId("permission", input.executionId, input.call.id);
|
|
10204
10216
|
var mapWaitServiceError = (error5) => ToolRuntimeError.make({ message: error5.message });
|
|
10205
|
-
var approvalRequestedEvent = (input,
|
|
10206
|
-
id:
|
|
10217
|
+
var approvalRequestedEvent = (input, waitId2) => ({
|
|
10218
|
+
id: Identifiers.eventId(input.executionId, input.call.id, "approval-requested"),
|
|
10207
10219
|
execution_id: input.executionId,
|
|
10208
10220
|
type: "tool.approval.requested",
|
|
10209
10221
|
sequence: input.eventSequence + 2,
|
|
@@ -10211,13 +10223,13 @@ var approvalRequestedEvent = (input, waitId) => ({
|
|
|
10211
10223
|
data: {
|
|
10212
10224
|
tool_call_id: input.call.id,
|
|
10213
10225
|
tool_name: input.call.name,
|
|
10214
|
-
wait_id:
|
|
10226
|
+
wait_id: waitId2,
|
|
10215
10227
|
input: input.call.input
|
|
10216
10228
|
},
|
|
10217
10229
|
created_at: input.createdAt + 2
|
|
10218
10230
|
});
|
|
10219
10231
|
var approvalResolvedEvent = (input, wait, approved) => ({
|
|
10220
|
-
id:
|
|
10232
|
+
id: Identifiers.eventId(input.executionId, input.call.id, "approval-resolved"),
|
|
10221
10233
|
execution_id: input.executionId,
|
|
10222
10234
|
type: "tool.approval.resolved",
|
|
10223
10235
|
sequence: input.eventSequence + 1,
|
|
@@ -10232,14 +10244,14 @@ var approvalResolvedEvent = (input, wait, approved) => ({
|
|
|
10232
10244
|
created_at: input.createdAt + 1
|
|
10233
10245
|
});
|
|
10234
10246
|
var deniedReason = (state) => state === "timed_out" ? "Tool approval timed out" : state === "cancelled" ? "Tool approval cancelled" : "Tool approval denied";
|
|
10235
|
-
var waitRequested = (input,
|
|
10247
|
+
var waitRequested = (input, waitId2) => Effect43.fail(ToolExecutionWaitRequested.make({ tool_name: input.call.name, wait_id: waitId2 }));
|
|
10236
10248
|
var hasPermissionApprovalBypass = (waits, input) => waits.get(permissionWaitId(input)).pipe(Effect43.mapError(mapWaitServiceError), Effect43.map((wait) => wait !== undefined && wait.state === "resolved" && wait.metadata.kind === "tool-permission" && wait.metadata.tool_call_id === input.call.id && wait.metadata.tool_name === input.call.name && (wait.metadata.answer === "Approved" || wait.metadata.answer === "Always")));
|
|
10237
10249
|
var resolveApproval = (waits, eventLog, input) => Effect43.gen(function* () {
|
|
10238
|
-
const
|
|
10239
|
-
const existing = yield* waits.get(
|
|
10250
|
+
const waitId2 = approvalWaitId(input);
|
|
10251
|
+
const existing = yield* waits.get(waitId2).pipe(Effect43.mapError(mapWaitServiceError));
|
|
10240
10252
|
if (existing === undefined) {
|
|
10241
10253
|
yield* waits.createDetached({
|
|
10242
|
-
waitId,
|
|
10254
|
+
waitId: waitId2,
|
|
10243
10255
|
executionId: input.executionId,
|
|
10244
10256
|
mode: "event",
|
|
10245
10257
|
correlationKey: input.call.id,
|
|
@@ -10252,11 +10264,11 @@ var resolveApproval = (waits, eventLog, input) => Effect43.gen(function* () {
|
|
|
10252
10264
|
eventSequence: input.eventSequence + 1,
|
|
10253
10265
|
createdAt: input.createdAt
|
|
10254
10266
|
}).pipe(Effect43.mapError(mapWaitServiceError));
|
|
10255
|
-
yield* appendIdempotentTo(eventLog, approvalRequestedEvent(input,
|
|
10256
|
-
return yield* waitRequested(input,
|
|
10267
|
+
yield* appendIdempotentTo(eventLog, approvalRequestedEvent(input, waitId2)).pipe(Effect43.mapError(mapEventLogError2));
|
|
10268
|
+
return yield* waitRequested(input, waitId2);
|
|
10257
10269
|
}
|
|
10258
10270
|
if (existing.state === "open") {
|
|
10259
|
-
return yield* waitRequested(input,
|
|
10271
|
+
return yield* waitRequested(input, waitId2);
|
|
10260
10272
|
}
|
|
10261
10273
|
const approved = existing.state === "resolved" && existing.metadata.approved === true;
|
|
10262
10274
|
yield* appendIdempotentTo(eventLog, approvalResolvedEvent(input, existing, approved)).pipe(Effect43.mapError(mapEventLogError2));
|
|
@@ -10272,7 +10284,7 @@ var recordRequested = (repository, eventLog, input, tool) => repository.ensureCa
|
|
|
10272
10284
|
createdAt: input.createdAt
|
|
10273
10285
|
}).pipe(Effect43.mapError(mapRepositoryError3), Effect43.tap((call) => ensureToolEvent(eventLog, requestedEvent({ ...input, createdAt: call.createdAt }))));
|
|
10274
10286
|
var repairResultEvent = (eventLog, input, record2) => eventLog.maxSequence(input.executionId).pipe(Effect43.mapError(mapEventLogError2), Effect43.flatMap((max) => ensureToolEvent(eventLog, resultEvent({ ...input, createdAt: record2.createdAt - 1 }, record2.result, (max ?? input.eventSequence) + 1))));
|
|
10275
|
-
var recordReceived = (repository, eventLog, input, result) => repository.recordResult({ result, createdAt: input.createdAt + 1 }).pipe(Effect43.catchTag("DuplicateToolResult", () => repository.getResult(result.call_id).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap((existing) => existing === undefined ? Effect43.fail(ToolRuntimeError.make({ message: "DuplicateToolResult" })) : Effect43.succeed(existing)))), Effect43.mapError(preserveRecordResultError), Effect43.flatMap((record2) => eventLog.maxSequence(input.executionId).pipe(Effect43.mapError(mapEventLogError2), Effect43.flatMap((max) => appendIdempotentTo(eventLog, resultEvent(input, record2.result, (max ?? input.eventSequence) + 1)).pipe(Effect43.mapError(mapEventLogError2))), Effect43.as(record2.result))));
|
|
10287
|
+
var recordReceived = (repository, eventLog, input, result) => repository.recordResult({ executionId: input.executionId, result, createdAt: input.createdAt + 1 }).pipe(Effect43.catchTag("DuplicateToolResult", () => repository.getResult(input.executionId, result.call_id).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap((existing) => existing === undefined ? Effect43.fail(ToolRuntimeError.make({ message: "DuplicateToolResult" })) : Effect43.succeed(existing)))), Effect43.mapError(preserveRecordResultError), Effect43.flatMap((record2) => eventLog.maxSequence(input.executionId).pipe(Effect43.mapError(mapEventLogError2), Effect43.flatMap((max) => appendIdempotentTo(eventLog, resultEvent(input, record2.result, (max ?? input.eventSequence) + 1)).pipe(Effect43.mapError(mapEventLogError2))), Effect43.as(record2.result))));
|
|
10276
10288
|
var nonEmptyName = (name) => Schema40.decodeUnknownSync(exports_shared_schema.NonEmptyString)(name);
|
|
10277
10289
|
var needsApprovalFromEffectTool = (tool) => tool.needsApproval === undefined ? undefined : typeof tool.needsApproval === "boolean" ? tool.needsApproval : true;
|
|
10278
10290
|
var definitionFromEffectTool = (modelTool, options) => ({
|
|
@@ -10351,7 +10363,7 @@ var placedTool = (modelTool, placement, options = {}) => ({
|
|
|
10351
10363
|
});
|
|
10352
10364
|
var clientTool = Function7.dual((args) => args.length > 1 || args.length === 1 && typeof args[0] === "object" && args[0] !== null && ("name" in args[0]), (modelTool, options = {}) => placedTool(modelTool, { kind: "client" }, options));
|
|
10353
10365
|
var remoteTool = Function7.dual(2, (modelTool, options) => placedTool(modelTool, { kind: "remote", queue: options.queue }, options));
|
|
10354
|
-
var placementWaitId = (input) =>
|
|
10366
|
+
var placementWaitId = (input) => Identifiers.waitId("tool", input.executionId, input.call.id);
|
|
10355
10367
|
var placementFailureResult = (input, message) => ({
|
|
10356
10368
|
call_id: input.call.id,
|
|
10357
10369
|
output: null,
|
|
@@ -10371,11 +10383,11 @@ var externalOutcomeResult = (call, input) => {
|
|
|
10371
10383
|
return Schema40.decodeUnknownEffect(exports_tool_schema.resultSchema(call.definition.output_schema))(call.externalOutcome.output).pipe(Effect43.map((output) => ({ call_id: input.call.id, output: jsonValue2(output) })), Effect43.catch((error5) => Effect43.succeed(placementFailureResult(input, `invalid ${placement} result: ${error5.message}`))));
|
|
10372
10384
|
};
|
|
10373
10385
|
var runExternalTool = (repository, waits, call, input) => Effect43.gen(function* () {
|
|
10374
|
-
const
|
|
10375
|
-
let wait = yield* waits.get(
|
|
10386
|
+
const waitId2 = placementWaitId(input);
|
|
10387
|
+
let wait = yield* waits.get(waitId2).pipe(Effect43.mapError(mapWaitServiceError));
|
|
10376
10388
|
if (wait === undefined) {
|
|
10377
10389
|
wait = yield* waits.createDetached({
|
|
10378
|
-
waitId,
|
|
10390
|
+
waitId: waitId2,
|
|
10379
10391
|
executionId: input.executionId,
|
|
10380
10392
|
mode: "event",
|
|
10381
10393
|
correlationKey: input.call.id,
|
|
@@ -10390,13 +10402,14 @@ var runExternalTool = (repository, waits, call, input) => Effect43.gen(function*
|
|
|
10390
10402
|
}).pipe(Effect43.mapError(mapWaitServiceError));
|
|
10391
10403
|
}
|
|
10392
10404
|
const waitingCall = call.state === "requested" ? yield* repository.prepareExternalWait({
|
|
10405
|
+
executionId: input.executionId,
|
|
10393
10406
|
callId: input.call.id,
|
|
10394
|
-
waitId,
|
|
10407
|
+
waitId: waitId2,
|
|
10395
10408
|
availableAt: input.createdAt,
|
|
10396
10409
|
updatedAt: input.createdAt
|
|
10397
10410
|
}).pipe(Effect43.mapError(mapRepositoryError3)) : call;
|
|
10398
10411
|
if (wait.state === "open")
|
|
10399
|
-
return yield* waitRequested(input,
|
|
10412
|
+
return yield* waitRequested(input, waitId2);
|
|
10400
10413
|
if (wait.state === "timed_out")
|
|
10401
10414
|
return placementFailureResult(input, "Tool execution timed out");
|
|
10402
10415
|
if (wait.state === "cancelled")
|
|
@@ -10429,7 +10442,7 @@ var makeService = (initialTools) => Effect43.gen(function* () {
|
|
|
10429
10442
|
yield* ensureAllowed(registeredTool, input);
|
|
10430
10443
|
yield* validateInput(registeredTool, input);
|
|
10431
10444
|
const call = yield* recordRequested(repository, eventLog, input, registeredTool);
|
|
10432
|
-
const existingResult = yield* repository.getResult(input.call.id).pipe(Effect43.mapError(mapRepositoryError3));
|
|
10445
|
+
const existingResult = yield* repository.getResult(input.executionId, input.call.id).pipe(Effect43.mapError(mapRepositoryError3));
|
|
10433
10446
|
if (existingResult !== undefined) {
|
|
10434
10447
|
yield* repairResultEvent(eventLog, input, existingResult);
|
|
10435
10448
|
return existingResult.result;
|
|
@@ -10451,7 +10464,11 @@ var makeService = (initialTools) => Effect43.gen(function* () {
|
|
|
10451
10464
|
}
|
|
10452
10465
|
}
|
|
10453
10466
|
}
|
|
10454
|
-
const rawResult = call.placement.kind === "client" || call.placement.kind === "remote" ? yield* runExternalTool(repository, waits, call, effectiveInput) : yield* repository.beginAttempt({
|
|
10467
|
+
const rawResult = call.placement.kind === "client" || call.placement.kind === "remote" ? yield* runExternalTool(repository, waits, call, effectiveInput) : yield* repository.beginAttempt({
|
|
10468
|
+
executionId: input.executionId,
|
|
10469
|
+
callId: input.call.id,
|
|
10470
|
+
startedAt: effectiveInput.createdAt
|
|
10471
|
+
}).pipe(Effect43.mapError(mapRepositoryError3), Effect43.flatMap(() => finalToolResult(registeredTool, effectiveInput, call.idempotencyKey)), Effect43.catchTag("ToolExecutionFailed", (error5) => Effect43.succeed(placementFailureResult(input, error5.message))));
|
|
10455
10472
|
const result = input.transformResult === undefined || rawResult.error !== undefined ? rawResult : yield* input.transformResult(rawResult);
|
|
10456
10473
|
const received = yield* recordReceived(repository, eventLog, effectiveInput, result);
|
|
10457
10474
|
yield* recordToolCall(input.call.name, result.error === undefined ? "success" : "failure");
|
|
@@ -11452,10 +11469,10 @@ var presetMap = (agent) => new Map(Object.entries(agent.child_run_presets ?? {})
|
|
|
11452
11469
|
...preset.metadata === undefined ? {} : { metadata: preset.metadata }
|
|
11453
11470
|
}
|
|
11454
11471
|
]));
|
|
11455
|
-
var createJoinWait = Effect52.fn("SpawnChildRunTool.createJoinWait")(function* (config, input, id,
|
|
11472
|
+
var createJoinWait = Effect52.fn("SpawnChildRunTool.createJoinWait")(function* (config, input, id, waitId2, createdAt) {
|
|
11456
11473
|
const eventSequence = yield* nextEventSequence(config.eventLog, input.execution_id);
|
|
11457
11474
|
yield* config.waits.createDetached({
|
|
11458
|
-
waitId,
|
|
11475
|
+
waitId: waitId2,
|
|
11459
11476
|
executionId: input.execution_id,
|
|
11460
11477
|
mode: "child",
|
|
11461
11478
|
correlationKey: id,
|
|
@@ -11467,7 +11484,7 @@ var createJoinWait = Effect52.fn("SpawnChildRunTool.createJoinWait")(function* (
|
|
|
11467
11484
|
createdAt
|
|
11468
11485
|
}).pipe(Effect52.mapError(mapWaitError));
|
|
11469
11486
|
});
|
|
11470
|
-
var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (config, input, id, definition,
|
|
11487
|
+
var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (config, input, id, definition, waitId2) {
|
|
11471
11488
|
yield* config.dispatch({
|
|
11472
11489
|
executionId: exports_ids_schema.ExecutionId.make(id),
|
|
11473
11490
|
rootAddressId: input.address_id,
|
|
@@ -11483,7 +11500,7 @@ var dispatchChild = Effect52.fn("SpawnChildRunTool.dispatchChild")(function* (co
|
|
|
11483
11500
|
metadata: {
|
|
11484
11501
|
parent_execution_id: input.execution_id,
|
|
11485
11502
|
child_execution_id: id,
|
|
11486
|
-
parent_wait_id:
|
|
11503
|
+
parent_wait_id: waitId2
|
|
11487
11504
|
}
|
|
11488
11505
|
}).pipe(Effect52.mapError((error5) => ToolRuntimeError.make({ message: String(error5) })));
|
|
11489
11506
|
});
|
|
@@ -11507,10 +11524,10 @@ var run3 = Effect52.fn("SpawnChildRunTool.run")(function* (config, activeToolNam
|
|
|
11507
11524
|
if (enforceStaticOrDynamic)
|
|
11508
11525
|
yield* ensureStaticOrDynamic(input);
|
|
11509
11526
|
const id = childExecutionId(context);
|
|
11510
|
-
const
|
|
11511
|
-
const existingWait = yield* config.waits.get(
|
|
11527
|
+
const waitId2 = childWaitId(id);
|
|
11528
|
+
const existingWait = yield* config.waits.get(waitId2).pipe(Effect52.mapError(mapWaitError));
|
|
11512
11529
|
if (existingWait?.state === "open") {
|
|
11513
|
-
return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id:
|
|
11530
|
+
return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id: waitId2 });
|
|
11514
11531
|
}
|
|
11515
11532
|
if (existingWait !== undefined)
|
|
11516
11533
|
return yield* resultFromTerminal(config, id, existingWait);
|
|
@@ -11540,9 +11557,9 @@ var run3 = Effect52.fn("SpawnChildRunTool.run")(function* (config, activeToolNam
|
|
|
11540
11557
|
createdAt: context.createdAt + 1
|
|
11541
11558
|
}).pipe(Effect52.mapError((error5) => mapChildRunError(activeToolName, error5)));
|
|
11542
11559
|
}
|
|
11543
|
-
yield* createJoinWait(config, spawn, id,
|
|
11544
|
-
yield* dispatchChild(config, spawn, id, definition,
|
|
11545
|
-
return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id:
|
|
11560
|
+
yield* createJoinWait(config, spawn, id, waitId2, context.createdAt + 2);
|
|
11561
|
+
yield* dispatchChild(config, spawn, id, definition, waitId2);
|
|
11562
|
+
return yield* ToolExecutionWaitRequested.make({ tool_name: activeToolName, wait_id: waitId2 });
|
|
11546
11563
|
});
|
|
11547
11564
|
var registeredTool = (config) => tool(toolName, {
|
|
11548
11565
|
description: "Spawn a durable child run and wait for its terminal output.",
|
|
@@ -13343,9 +13360,9 @@ var ActivityNames = {
|
|
|
13343
13360
|
accept: `${StartExecutionWorkflowName}/Accept`,
|
|
13344
13361
|
cancel: (turn) => `${StartExecutionWorkflowName}/Cancel/${turn}`,
|
|
13345
13362
|
checkCancel: (turn) => `${StartExecutionWorkflowName}/CheckCancel/${turn}`,
|
|
13346
|
-
loadWaitBeforeSleep: (
|
|
13347
|
-
loadWaitAfterWake: (
|
|
13348
|
-
markWaiting: (
|
|
13363
|
+
loadWaitBeforeSleep: (waitId2) => `${StartExecutionWorkflowName}/LoadWaitBeforeSleep/${waitId2}`,
|
|
13364
|
+
loadWaitAfterWake: (waitId2) => `${StartExecutionWorkflowName}/LoadWaitAfterWake/${waitId2}`,
|
|
13365
|
+
markWaiting: (waitId2) => `${StartExecutionWorkflowName}/MarkWaiting/${waitId2}`,
|
|
13349
13366
|
ensureWorkspace: `${StartExecutionWorkflowName}/EnsureWorkspace`,
|
|
13350
13367
|
suspendWorkspace: (key4) => `${StartExecutionWorkflowName}/SuspendWorkspace/${key4}`,
|
|
13351
13368
|
resumeWorkspace: (key4) => `${StartExecutionWorkflowName}/ResumeWorkspace/${key4}`,
|
|
@@ -13400,7 +13417,7 @@ var mapChildExecutionRepositoryError = (error5) => ExecutionWorkflowFailed.make(
|
|
|
13400
13417
|
var mapSkillRegistryError = (error5) => ExecutionWorkflowFailed.make({ message: error5.message });
|
|
13401
13418
|
var mapEventLogError6 = (error5) => ExecutionWorkflowFailed.make({ message: error5._tag });
|
|
13402
13419
|
var mapWorkspaceError = (error5) => ExecutionWorkflowFailed.make({ message: error5._tag });
|
|
13403
|
-
var waitSignal = (
|
|
13420
|
+
var waitSignal = (waitId2) => DurableDeferred.make(`Relay/Execution/Wait/${waitId2}`, {
|
|
13404
13421
|
success: WaitSignal,
|
|
13405
13422
|
error: ExecutionWorkflowFailed
|
|
13406
13423
|
});
|
|
@@ -13474,8 +13491,8 @@ var acceptExecution = (input) => Activity.make({
|
|
|
13474
13491
|
});
|
|
13475
13492
|
var terminalExecutionStatuses = new Set(["completed", "failed", "cancelled"]);
|
|
13476
13493
|
var waitIdFromRecord = (record2) => {
|
|
13477
|
-
const
|
|
13478
|
-
return typeof
|
|
13494
|
+
const waitId2 = record2.metadata.wait_id;
|
|
13495
|
+
return typeof waitId2 === "string" ? exports_ids_schema.WaitId.make(waitId2) : undefined;
|
|
13479
13496
|
};
|
|
13480
13497
|
var prepareCancellation = Effect67.fn("ExecutionWorkflow.prepareCancellation")(function* (input) {
|
|
13481
13498
|
const repository = yield* exports_execution_repository.Service;
|
|
@@ -13623,11 +13640,11 @@ var loadCancellationRequested = (input, turn) => Activity.make({
|
|
|
13623
13640
|
return record2?.metadata?.cancellation_requested === true;
|
|
13624
13641
|
})
|
|
13625
13642
|
});
|
|
13626
|
-
var loadWait = (name,
|
|
13643
|
+
var loadWait = (name, waitId2) => Activity.make({
|
|
13627
13644
|
name,
|
|
13628
13645
|
success: Schema61.UndefinedOr(WaitSnapshot),
|
|
13629
13646
|
error: ExecutionWorkflowFailed,
|
|
13630
|
-
execute: get11(
|
|
13647
|
+
execute: get11(waitId2).pipe(Effect67.map((record2) => record2 === undefined ? undefined : toWaitSnapshot(record2)), Effect67.mapError(mapWaitError2))
|
|
13631
13648
|
});
|
|
13632
13649
|
var markWaiting = (input, repository, wait) => Activity.make({
|
|
13633
13650
|
name: ActivityNames.markWaiting(wait.id),
|
|
@@ -13747,7 +13764,7 @@ var failWorkspace = (input, error5) => fail({
|
|
|
13747
13764
|
}).pipe(Effect67.catch(() => Effect67.void));
|
|
13748
13765
|
var attachWorkspace = (input) => attach({ executionId: input.execution_id, now: input.started_at }).pipe(Effect67.mapError(mapWorkspaceError));
|
|
13749
13766
|
var sessionEntryScope = Function13.dual(2, (input, turn) => `${input.execution_id}:${workflowGenerationForStart(input)}:complete:${turn}`);
|
|
13750
|
-
var completeExecution = (input,
|
|
13767
|
+
var completeExecution = (input, waitId2, waitState, workspaceRuntimeLayer, turn, pendingSuspension) => Activity.make({
|
|
13751
13768
|
name: ActivityNames.complete(turn),
|
|
13752
13769
|
success: exports_execution_schema.Execution,
|
|
13753
13770
|
error: ExecutionWorkflowFailed,
|
|
@@ -13801,8 +13818,8 @@ var completeExecution = (input, waitId, waitState, workspaceRuntimeLayer, turn,
|
|
|
13801
13818
|
const program = activeProgram.pipe(Effect67.map((result) => ({
|
|
13802
13819
|
metadata: {
|
|
13803
13820
|
...result.metadata,
|
|
13804
|
-
...
|
|
13805
|
-
...
|
|
13821
|
+
...waitId2 === undefined ? {} : { wait_id: waitId2 },
|
|
13822
|
+
...waitId2 === undefined || waitState === undefined ? {} : { wait_state: waitState }
|
|
13806
13823
|
},
|
|
13807
13824
|
nextEventSequence: result.nextEventSequence
|
|
13808
13825
|
})), Effect67.catchTag("AgentLoopWaitRequested", (wait) => Effect67.succeed({
|
|
@@ -13896,8 +13913,8 @@ var terminalOutput = (execution) => {
|
|
|
13896
13913
|
const output = execution.metadata?.model_output;
|
|
13897
13914
|
return typeof output === "string" ? [exports_content_schema.text(output)] : [];
|
|
13898
13915
|
};
|
|
13899
|
-
var missingWait = (
|
|
13900
|
-
var stillOpen = (
|
|
13916
|
+
var missingWait = (waitId2) => ExecutionWorkflowFailed.make({ message: `Wait not found: ${waitId2}` });
|
|
13917
|
+
var stillOpen = (waitId2) => ExecutionWorkflowFailed.make({ message: `Wait remained open after wake: ${waitId2}` });
|
|
13901
13918
|
var resolveWaitState = Effect67.fn("ExecutionWorkflow.resolveWaitState")(function* (input, repository) {
|
|
13902
13919
|
if (input.wait_id === undefined)
|
|
13903
13920
|
return;
|
|
@@ -13920,32 +13937,32 @@ var resolveWaitState = Effect67.fn("ExecutionWorkflow.resolveWaitState")(functio
|
|
|
13920
13937
|
return afterTerminal;
|
|
13921
13938
|
});
|
|
13922
13939
|
var waitIdFromExecution = (execution) => {
|
|
13923
|
-
const
|
|
13924
|
-
return typeof
|
|
13940
|
+
const waitId2 = execution.metadata?.wait_id;
|
|
13941
|
+
return typeof waitId2 === "string" ? exports_ids_schema.WaitId.make(waitId2) : undefined;
|
|
13925
13942
|
};
|
|
13926
13943
|
var pendingSuspensionFromExecution = (execution) => {
|
|
13927
13944
|
const pending = execution.metadata?.pending_agent_suspension;
|
|
13928
13945
|
return Schema61.decodeUnknownOption(exports_agent_event.AgentSuspended)(pending).pipe(Option15.getOrUndefined);
|
|
13929
13946
|
};
|
|
13930
|
-
var finishCancelledWait = Effect67.fn("ExecutionWorkflow.finishCancelledWait")(function* (startInput, turn,
|
|
13947
|
+
var finishCancelledWait = Effect67.fn("ExecutionWorkflow.finishCancelledWait")(function* (startInput, turn, waitId2) {
|
|
13931
13948
|
const cancelled = yield* cancelExecution(startInput, turn, "wait cancelled");
|
|
13932
13949
|
yield* releaseWorkspace(startInput);
|
|
13933
13950
|
yield* notifyParent(startInput, "cancelled", []);
|
|
13934
13951
|
return {
|
|
13935
13952
|
execution_id: cancelled.id,
|
|
13936
13953
|
status: cancelled.status,
|
|
13937
|
-
wait_id:
|
|
13954
|
+
wait_id: waitId2,
|
|
13938
13955
|
wait_state: "cancelled",
|
|
13939
13956
|
...cancelled.metadata === undefined ? {} : { metadata: cancelled.metadata }
|
|
13940
13957
|
};
|
|
13941
13958
|
});
|
|
13942
|
-
var continueAsNew = (startInput, turn,
|
|
13959
|
+
var continueAsNew = (startInput, turn, waitId2, pendingSuspension) => Activity.make({
|
|
13943
13960
|
name: ActivityNames.continueAsNew(turn),
|
|
13944
13961
|
success: StartResult,
|
|
13945
13962
|
error: ExecutionWorkflowError,
|
|
13946
13963
|
execute: StartExecutionWorkflow.execute({
|
|
13947
13964
|
...startInput,
|
|
13948
|
-
wait_id:
|
|
13965
|
+
wait_id: waitId2,
|
|
13949
13966
|
resume_suspension: pendingSuspension,
|
|
13950
13967
|
workflow_generation: workflowGenerationForStart(startInput) + 1
|
|
13951
13968
|
})
|
|
@@ -14006,8 +14023,8 @@ var runWorkflow = Effect67.fn("ExecutionWorkflow.run")(function* (input) {
|
|
|
14006
14023
|
break;
|
|
14007
14024
|
if (turn >= maxWaitTurns)
|
|
14008
14025
|
return yield* ExecutionWorkflowFailed.make({ message: "Agent wait turn limit exceeded" });
|
|
14009
|
-
const
|
|
14010
|
-
if (
|
|
14026
|
+
const waitId2 = waitIdFromExecution(execution);
|
|
14027
|
+
if (waitId2 === undefined)
|
|
14011
14028
|
return yield* ExecutionWorkflowFailed.make({ message: "Waiting execution missing wait id" });
|
|
14012
14029
|
pendingSuspension = pendingSuspensionFromExecution(execution);
|
|
14013
14030
|
if (pendingSuspension === undefined) {
|
|
@@ -14017,14 +14034,14 @@ var runWorkflow = Effect67.fn("ExecutionWorkflow.run")(function* (input) {
|
|
|
14017
14034
|
yield* failIncompatibleCheckpoint(startInput, error5);
|
|
14018
14035
|
return yield* error5;
|
|
14019
14036
|
}
|
|
14020
|
-
activeWaitId =
|
|
14021
|
-
waitState = yield* resolveWaitState({ ...startInput, wait_id:
|
|
14037
|
+
activeWaitId = waitId2;
|
|
14038
|
+
waitState = yield* resolveWaitState({ ...startInput, wait_id: waitId2 }, repository);
|
|
14022
14039
|
if (waitState === "cancelled") {
|
|
14023
|
-
return yield* finishCancelledWait(startInput, turn + 1,
|
|
14040
|
+
return yield* finishCancelledWait(startInput, turn + 1, waitId2);
|
|
14024
14041
|
}
|
|
14025
14042
|
turn += 1;
|
|
14026
14043
|
if (continueAsNewAfterTurns !== undefined && turn >= continueAsNewAfterTurns) {
|
|
14027
|
-
return yield* continueAsNew(startInput, turn,
|
|
14044
|
+
return yield* continueAsNew(startInput, turn, waitId2, pendingSuspension);
|
|
14028
14045
|
}
|
|
14029
14046
|
}
|
|
14030
14047
|
yield* releaseWorkspace(startInput);
|
|
@@ -14043,11 +14060,11 @@ var awaitCanonicalSettledResult = Effect67.fn("ExecutionWorkflow.awaitCanonicalS
|
|
|
14043
14060
|
until: (record2) => record2?.status === "waiting" || record2 !== undefined && terminalExecutionStatuses.has(record2.status)
|
|
14044
14061
|
}));
|
|
14045
14062
|
const canonicalWaitId = execution?.metadata?.wait_id;
|
|
14046
|
-
const
|
|
14063
|
+
const waitId2 = typeof canonicalWaitId === "string" ? exports_ids_schema.WaitId.make(canonicalWaitId) : input.wait_id;
|
|
14047
14064
|
const result = {
|
|
14048
14065
|
execution_id: input.execution_id,
|
|
14049
14066
|
status: execution?.status ?? "waiting",
|
|
14050
|
-
...
|
|
14067
|
+
...waitId2 === undefined ? {} : { wait_id: waitId2 },
|
|
14051
14068
|
...execution?.metadata === undefined ? {} : { metadata: execution.metadata }
|
|
14052
14069
|
};
|
|
14053
14070
|
return result;
|
|
@@ -14085,14 +14102,14 @@ var startRequest = Effect67.fn("ExecutionWorkflow.startRequest")(function* (inpu
|
|
|
14085
14102
|
}
|
|
14086
14103
|
const workflowExecutionId2 = yield* activeWorkflowExecutionIdForExecution(input.execution_id);
|
|
14087
14104
|
const existingWaitId = existing.metadata?.wait_id;
|
|
14088
|
-
const
|
|
14089
|
-
if (existing.status === "waiting" &&
|
|
14090
|
-
const wait = yield* get11(
|
|
14105
|
+
const waitId2 = typeof existingWaitId === "string" ? exports_ids_schema.WaitId.make(existingWaitId) : undefined;
|
|
14106
|
+
if (existing.status === "waiting" && waitId2 !== undefined) {
|
|
14107
|
+
const wait = yield* get11(waitId2).pipe(Effect67.mapError(mapWaitError2));
|
|
14091
14108
|
const state = wait === undefined ? undefined : terminalWaitState(toWaitSnapshot(wait));
|
|
14092
14109
|
if (state !== undefined) {
|
|
14093
14110
|
yield* signalWait({
|
|
14094
14111
|
workflow_execution_id: workflowExecutionId2,
|
|
14095
|
-
wait_id:
|
|
14112
|
+
wait_id: waitId2,
|
|
14096
14113
|
state,
|
|
14097
14114
|
signaled_at: wait?.resolvedAt ?? input.started_at
|
|
14098
14115
|
});
|
|
@@ -14231,9 +14248,9 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
|
|
|
14231
14248
|
const findOpenByCorrelation = envelopes.findOpenByCorrelation;
|
|
14232
14249
|
const wait = findOpenByCorrelation === undefined ? undefined : yield* findOpenByCorrelation(input.executionId, `inbox:${input.executionId}`).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: input.executionId, message: error5.message })));
|
|
14233
14250
|
if (wait?.state === "open") {
|
|
14234
|
-
const
|
|
14251
|
+
const waitId2 = wait.id;
|
|
14235
14252
|
const sequence = yield* nextSequence(eventLog, input.executionId).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: input.executionId, message: error5._tag })));
|
|
14236
|
-
const transition3 = yield* waits.wake({ waitId, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({
|
|
14253
|
+
const transition3 = yield* waits.wake({ waitId: waitId2, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({
|
|
14237
14254
|
execution_id: input.executionId,
|
|
14238
14255
|
message: error5._tag === "WaitNotFound" ? error5.wait_id : error5.message
|
|
14239
14256
|
})));
|
|
@@ -14259,14 +14276,14 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
|
|
|
14259
14276
|
}),
|
|
14260
14277
|
undrainedCount: (id) => repository.countUndrained(id).pipe(Effect69.mapError((error5) => InboxServiceError.make({ message: error5.message }))),
|
|
14261
14278
|
reply: Effect69.fn("InboxService.reply")(function* (input) {
|
|
14262
|
-
const
|
|
14263
|
-
const wait = yield* waits.get(
|
|
14279
|
+
const waitId2 = exports_ids_schema.WaitId.make(input.replyToken);
|
|
14280
|
+
const wait = yield* waits.get(waitId2).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
|
|
14264
14281
|
if (wait === undefined || wait.state !== "open" || wait.envelopeId === undefined)
|
|
14265
14282
|
return yield* InboxReplyTokenInvalid.make({ reply_token: input.replyToken });
|
|
14266
14283
|
const original = yield* envelopes.getEnvelope(wait.envelopeId).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
|
|
14267
14284
|
if (original === undefined)
|
|
14268
14285
|
return yield* InboxReplyTokenInvalid.make({ reply_token: input.replyToken });
|
|
14269
|
-
const envelopeId = exports_ids_schema.EnvelopeId.make(`envelope:reply:${
|
|
14286
|
+
const envelopeId = exports_ids_schema.EnvelopeId.make(`envelope:reply:${waitId2}`);
|
|
14270
14287
|
yield* envelopes.acceptEnvelope({
|
|
14271
14288
|
envelope: {
|
|
14272
14289
|
id: envelopeId,
|
|
@@ -14279,7 +14296,7 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
|
|
|
14279
14296
|
}
|
|
14280
14297
|
}).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: wait.executionId, message: error5.message })));
|
|
14281
14298
|
const sequence = yield* nextSequence(eventLog, wait.executionId).pipe(Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: wait.executionId, message: error5._tag })));
|
|
14282
|
-
const transition3 = yield* waits.wake({ waitId, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
|
|
14299
|
+
const transition3 = yield* waits.wake({ waitId: waitId2, resolvedAt: input.createdAt, eventSequence: sequence }).pipe(Effect69.mapError(() => InboxReplyTokenInvalid.make({ reply_token: input.replyToken })));
|
|
14283
14300
|
if (!transition3.transitioned)
|
|
14284
14301
|
return yield* InboxReplyTokenInvalid.make({ reply_token: input.replyToken });
|
|
14285
14302
|
if (signalDependencies !== undefined) {
|
|
@@ -14291,7 +14308,7 @@ var makeLayer = (signalDependencies) => Layer63.effect(Service62, Effect69.gen(f
|
|
|
14291
14308
|
signaledAt: input.createdAt
|
|
14292
14309
|
}).pipe(Effect69.provideService(exports_execution_repository.Service, signalDependencies.executionRepository), Effect69.mapError((error5) => InboxDeliveryError.make({ execution_id: wait.executionId, message: String(error5) })));
|
|
14293
14310
|
}
|
|
14294
|
-
return { envelope_id: envelopeId, execution_id: wait.executionId, wait_id:
|
|
14311
|
+
return { envelope_id: envelopeId, execution_id: wait.executionId, wait_id: waitId2 };
|
|
14295
14312
|
})
|
|
14296
14313
|
});
|
|
14297
14314
|
}));
|
|
@@ -14444,8 +14461,8 @@ var registeredTool4 = (config) => tool(toolName4, {
|
|
|
14444
14461
|
requiredPermissions: [permissionName4],
|
|
14445
14462
|
metadata: { relay_core_tool: true },
|
|
14446
14463
|
run: (input, context) => Effect72.gen(function* () {
|
|
14447
|
-
const
|
|
14448
|
-
const existing = yield* config.waits.get(
|
|
14464
|
+
const waitId2 = exports_ids_schema.WaitId.make(`wait:inbox:${context.call.id}`);
|
|
14465
|
+
const existing = yield* config.waits.get(waitId2).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
|
|
14449
14466
|
const drain2 = () => config.inbox.drain({ executionId: context.executionId, drainId: context.call.id }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
|
|
14450
14467
|
if (existing?.state === "timed_out")
|
|
14451
14468
|
return { status: "timed_out", messages: [] };
|
|
@@ -14454,7 +14471,7 @@ var registeredTool4 = (config) => tool(toolName4, {
|
|
|
14454
14471
|
return { status: "messages", messages: drained.map(project) };
|
|
14455
14472
|
}
|
|
14456
14473
|
if (existing?.state === "open")
|
|
14457
|
-
return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id:
|
|
14474
|
+
return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id: waitId2 });
|
|
14458
14475
|
const count = yield* config.inbox.undrainedCount(context.executionId).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
|
|
14459
14476
|
if (count > 0) {
|
|
14460
14477
|
const drained = yield* drain2();
|
|
@@ -14462,7 +14479,7 @@ var registeredTool4 = (config) => tool(toolName4, {
|
|
|
14462
14479
|
}
|
|
14463
14480
|
if (existing === undefined)
|
|
14464
14481
|
yield* config.waits.createDetached({
|
|
14465
|
-
waitId,
|
|
14482
|
+
waitId: waitId2,
|
|
14466
14483
|
executionId: context.executionId,
|
|
14467
14484
|
mode: "event",
|
|
14468
14485
|
correlationKey: `inbox:${context.executionId}`,
|
|
@@ -14472,13 +14489,13 @@ var registeredTool4 = (config) => tool(toolName4, {
|
|
|
14472
14489
|
}).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })));
|
|
14473
14490
|
if ((yield* config.inbox.undrainedCount(context.executionId).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5.message })))) > 0) {
|
|
14474
14491
|
const sequence = yield* config.eventLog.maxSequence(context.executionId).pipe(Effect72.map((value) => (value ?? -1) + 1), Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5._tag })));
|
|
14475
|
-
const transition3 = yield* config.waits.wake({ waitId, resolvedAt: context.createdAt, eventSequence: sequence }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5._tag })));
|
|
14492
|
+
const transition3 = yield* config.waits.wake({ waitId: waitId2, resolvedAt: context.createdAt, eventSequence: sequence }).pipe(Effect72.mapError((error5) => ToolRuntimeError.make({ message: error5._tag })));
|
|
14476
14493
|
if (transition3.transitioned) {
|
|
14477
14494
|
const drained = yield* drain2();
|
|
14478
14495
|
return { status: "messages", messages: drained.map(project) };
|
|
14479
14496
|
}
|
|
14480
14497
|
}
|
|
14481
|
-
return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id:
|
|
14498
|
+
return yield* ToolExecutionWaitRequested.make({ tool_name: toolName4, wait_id: waitId2 });
|
|
14482
14499
|
})
|
|
14483
14500
|
});
|
|
14484
14501
|
|
|
@@ -14659,18 +14676,18 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
|
|
|
14659
14676
|
});
|
|
14660
14677
|
const envelope = envelopeFrom(input);
|
|
14661
14678
|
const ready = readyFor(input, route);
|
|
14662
|
-
const
|
|
14679
|
+
const waitId2 = waitIdFor(input);
|
|
14663
14680
|
const replayed = yield* repository.getEnvelope(envelope.id).pipe(Effect74.mapError(mapRepositoryError11));
|
|
14664
14681
|
if (replayed !== undefined) {
|
|
14665
14682
|
if (route.kind === "local-execution" && inbox._tag === "Some" && input.input.idempotency_key !== undefined) {
|
|
14666
|
-
if (
|
|
14667
|
-
yield* inbox.value.ensureReplyWait({ envelope, waitId }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
|
|
14683
|
+
if (waitId2 !== undefined) {
|
|
14684
|
+
yield* inbox.value.ensureReplyWait({ envelope, waitId: waitId2 }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
|
|
14668
14685
|
}
|
|
14669
14686
|
yield* inbox.value.deliver({
|
|
14670
14687
|
executionId: exports_ids_schema.ExecutionId.make(route.route_key),
|
|
14671
14688
|
envelope,
|
|
14672
14689
|
idempotencyKey: input.input.idempotency_key,
|
|
14673
|
-
...
|
|
14690
|
+
...waitId2 === undefined ? {} : { replyWaitId: waitId2 },
|
|
14674
14691
|
eventSequence: input.eventSequence,
|
|
14675
14692
|
createdAt: input.createdAt
|
|
14676
14693
|
}).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
|
|
@@ -14678,7 +14695,7 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
|
|
|
14678
14695
|
const recorded = {
|
|
14679
14696
|
envelope_id: envelope.id,
|
|
14680
14697
|
execution_id: envelope.execution_id,
|
|
14681
|
-
...
|
|
14698
|
+
...waitId2 === undefined ? {} : { wait_id: waitId2 }
|
|
14682
14699
|
};
|
|
14683
14700
|
return Object.defineProperty(recorded, "route_kind", { value: route.kind });
|
|
14684
14701
|
}
|
|
@@ -14691,17 +14708,17 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
|
|
|
14691
14708
|
envelope,
|
|
14692
14709
|
acceptance: {
|
|
14693
14710
|
envelope,
|
|
14694
|
-
...
|
|
14711
|
+
...waitId2 === undefined ? {} : { waitId: waitId2 }
|
|
14695
14712
|
},
|
|
14696
14713
|
...input.input.idempotency_key === undefined ? {} : { idempotencyKey: input.input.idempotency_key },
|
|
14697
|
-
...
|
|
14714
|
+
...waitId2 === undefined ? {} : { replyWaitId: waitId2 },
|
|
14698
14715
|
eventSequence: input.eventSequence,
|
|
14699
14716
|
createdAt: input.createdAt
|
|
14700
14717
|
}).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
|
|
14701
14718
|
accepted2 = {
|
|
14702
14719
|
envelope_id: envelope.id,
|
|
14703
14720
|
execution_id: envelope.execution_id,
|
|
14704
|
-
...
|
|
14721
|
+
...waitId2 === undefined ? {} : { wait_id: waitId2 }
|
|
14705
14722
|
};
|
|
14706
14723
|
if (delivery.deduplicated) {
|
|
14707
14724
|
return Object.defineProperty(accepted2, "route_kind", { value: route.kind });
|
|
@@ -14709,7 +14726,7 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
|
|
|
14709
14726
|
} else {
|
|
14710
14727
|
accepted2 = yield* repository.acceptEnvelope({
|
|
14711
14728
|
envelope,
|
|
14712
|
-
...
|
|
14729
|
+
...waitId2 === undefined ? {} : { waitId: waitId2 },
|
|
14713
14730
|
...ready === undefined ? {} : { ready }
|
|
14714
14731
|
}).pipe(Effect74.mapError(mapRepositoryError11));
|
|
14715
14732
|
}
|
|
@@ -14718,8 +14735,8 @@ var layer52 = Layer65.effect(Service64, Effect74.gen(function* () {
|
|
|
14718
14735
|
if (ready !== undefined) {
|
|
14719
14736
|
yield* appendIdempotentTo(eventLog, readyEvent(input, ready)).pipe(Effect74.mapError(mapEventLogError7));
|
|
14720
14737
|
}
|
|
14721
|
-
if (route.kind === "local-execution" && inbox._tag === "Some" &&
|
|
14722
|
-
yield* inbox.value.ensureReplyWait({ envelope, waitId }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
|
|
14738
|
+
if (route.kind === "local-execution" && inbox._tag === "Some" && waitId2 !== undefined) {
|
|
14739
|
+
yield* inbox.value.ensureReplyWait({ envelope, waitId: waitId2 }).pipe(Effect74.mapError((error5) => EnvelopeServiceError.make({ message: error5.message })));
|
|
14723
14740
|
}
|
|
14724
14741
|
yield* recordEnvelopeSent(route.kind);
|
|
14725
14742
|
return Object.defineProperty(accepted2, "route_kind", { value: route.kind });
|
|
@@ -14785,9 +14802,9 @@ var layerFromEpoch = (epoch) => exports_instructions.layer(epoch.baseline.length
|
|
|
14785
14802
|
// ../runtime/src/agent/relay-permissions.ts
|
|
14786
14803
|
import { Clock as Clock15, Effect as Effect76, Layer as Layer67, Option as Option16, Schema as Schema69 } from "effect";
|
|
14787
14804
|
var jsonValue3 = (value) => Schema69.decodeUnknownSync(exports_shared_schema.JsonValue)(value === undefined ? null : value);
|
|
14788
|
-
var waitIdForToolCall = (toolCallId) =>
|
|
14805
|
+
var waitIdForToolCall = (executionId, toolCallId) => Identifiers.waitId("permission", executionId, toolCallId);
|
|
14789
14806
|
var fallbackToolCallId = (request) => `${request.agentName}:${request.turn}:${request.tool}`;
|
|
14790
|
-
var tokenFor = (request) => waitIdForToolCall(request.toolCallId ?? fallbackToolCallId(request));
|
|
14807
|
+
var tokenFor = (executionId, request) => waitIdForToolCall(executionId, request.toolCallId ?? fallbackToolCallId(request));
|
|
14791
14808
|
var matchingRule = (rules, tool3, params) => {
|
|
14792
14809
|
let matched;
|
|
14793
14810
|
for (const rule of rules) {
|
|
@@ -14796,7 +14813,7 @@ var matchingRule = (rules, tool3, params) => {
|
|
|
14796
14813
|
}
|
|
14797
14814
|
return matched;
|
|
14798
14815
|
};
|
|
14799
|
-
var staticDecision = (ruleset, request) => {
|
|
14816
|
+
var staticDecision = (executionId, ruleset, request) => {
|
|
14800
14817
|
const rule = matchingRule(ruleset.rules, request.tool, request.params);
|
|
14801
14818
|
const level = rule?.level ?? ruleset.fallback ?? "ask";
|
|
14802
14819
|
switch (level) {
|
|
@@ -14808,7 +14825,7 @@ var staticDecision = (ruleset, request) => {
|
|
|
14808
14825
|
...rule?.reason === undefined ? {} : { reason: rule.reason }
|
|
14809
14826
|
};
|
|
14810
14827
|
case "ask":
|
|
14811
|
-
return { _tag: "Ask", token: tokenFor(request) };
|
|
14828
|
+
return { _tag: "Ask", token: tokenFor(executionId, request) };
|
|
14812
14829
|
}
|
|
14813
14830
|
};
|
|
14814
14831
|
var evaluateDecision = Effect76.fn("RelayPermissions.evaluateDecision")(function* (config, request) {
|
|
@@ -14824,10 +14841,10 @@ var evaluateDecision = Effect76.fn("RelayPermissions.evaluateDecision")(function
|
|
|
14824
14841
|
...rule.reason === undefined ? {} : { reason: rule.reason }
|
|
14825
14842
|
};
|
|
14826
14843
|
case "ask":
|
|
14827
|
-
return { _tag: "Ask", token: tokenFor(request) };
|
|
14844
|
+
return { _tag: "Ask", token: tokenFor(config.executionId, request) };
|
|
14828
14845
|
}
|
|
14829
14846
|
}
|
|
14830
|
-
return staticDecision(config.ruleset, request);
|
|
14847
|
+
return staticDecision(config.executionId, config.ruleset, request);
|
|
14831
14848
|
});
|
|
14832
14849
|
var permissionError = (message) => exports_permissions.PermissionError.make({ message });
|
|
14833
14850
|
var createdAtForSequence = (config, sequence) => config.startedAt + sequence - config.eventSequence;
|
|
@@ -14839,18 +14856,18 @@ var allocateEventSequence = Effect76.fn("RelayPermissions.allocateEventSequence"
|
|
|
14839
14856
|
return sequence;
|
|
14840
14857
|
});
|
|
14841
14858
|
var resetAllocatorToLog = (config) => config.allocator.current.pipe(Effect76.flatMap((current2) => nextLoggedSequence(config.eventLog, config.executionId, current2)), Effect76.flatMap(config.allocator.resetTo));
|
|
14842
|
-
var permissionRequestedCursor = (config, pending,
|
|
14859
|
+
var permissionRequestedCursor = (config, pending, waitId2) => `${config.executionId}:permission:${pending.toolCallId ?? waitId2}:requested`;
|
|
14843
14860
|
var permissionResolvedCursor = (config, pending, wait) => `${config.executionId}:permission:${pending.toolCallId ?? wait.id}:resolved`;
|
|
14844
|
-
var permissionRequestedEvent = (config, pending,
|
|
14845
|
-
id:
|
|
14861
|
+
var permissionRequestedEvent = (config, pending, waitId2, sequence) => ({
|
|
14862
|
+
id: Identifiers.eventId(config.executionId, pending.toolCallId ?? waitId2, "permission-requested"),
|
|
14846
14863
|
execution_id: config.executionId,
|
|
14847
14864
|
type: "permission.ask.requested",
|
|
14848
14865
|
sequence,
|
|
14849
|
-
cursor: permissionRequestedCursor(config, pending,
|
|
14866
|
+
cursor: permissionRequestedCursor(config, pending, waitId2),
|
|
14850
14867
|
data: {
|
|
14851
14868
|
tool_call_id: pending.toolCallId ?? pending.token,
|
|
14852
14869
|
tool_name: pending.tool,
|
|
14853
|
-
wait_id:
|
|
14870
|
+
wait_id: waitId2,
|
|
14854
14871
|
input: jsonValue3(pending.params),
|
|
14855
14872
|
agent_name: pending.agentName,
|
|
14856
14873
|
scope: config.scope
|
|
@@ -14877,7 +14894,7 @@ var answerForWait = (wait) => {
|
|
|
14877
14894
|
return { _tag: "Denied", reason: "Permission denied" };
|
|
14878
14895
|
};
|
|
14879
14896
|
var permissionResolvedEvent = (config, pending, wait, answer, sequence) => ({
|
|
14880
|
-
id:
|
|
14897
|
+
id: Identifiers.eventId(config.executionId, pending.toolCallId ?? wait.id, "permission-resolved"),
|
|
14881
14898
|
execution_id: config.executionId,
|
|
14882
14899
|
type: "permission.ask.resolved",
|
|
14883
14900
|
sequence,
|
|
@@ -14897,19 +14914,19 @@ var appendPermissionEvent = (config, event) => appendIdempotentTo(config.eventLo
|
|
|
14897
14914
|
onNone: () => Effect76.fail(permissionError(error5.message)),
|
|
14898
14915
|
onSome: (prior) => samePermissionEvent(prior, event) ? Effect76.succeed(prior) : Effect76.fail(permissionError(error5.message))
|
|
14899
14916
|
})))), Effect76.mapError((error5) => permissionError(error5.message)), Effect76.tap(() => resetAllocatorToLog(config)));
|
|
14900
|
-
var ensurePermissionRequestedEvent = Effect76.fn("RelayPermissions.ensurePermissionRequestedEvent")(function* (config, pending,
|
|
14901
|
-
const cursor = permissionRequestedCursor(config, pending,
|
|
14917
|
+
var ensurePermissionRequestedEvent = Effect76.fn("RelayPermissions.ensurePermissionRequestedEvent")(function* (config, pending, waitId2) {
|
|
14918
|
+
const cursor = permissionRequestedCursor(config, pending, waitId2);
|
|
14902
14919
|
const existing = yield* findEventByCursor(config, cursor);
|
|
14903
14920
|
if (Option16.isSome(existing))
|
|
14904
14921
|
return;
|
|
14905
14922
|
const requestedSequence = yield* allocateEventSequence(config);
|
|
14906
|
-
yield* appendPermissionEvent(config, permissionRequestedEvent(config, pending,
|
|
14923
|
+
yield* appendPermissionEvent(config, permissionRequestedEvent(config, pending, waitId2, requestedSequence));
|
|
14907
14924
|
});
|
|
14908
14925
|
var createAsk = Effect76.fn("RelayPermissions.createAsk")(function* (config, pending) {
|
|
14909
|
-
const
|
|
14926
|
+
const waitId2 = exports_ids_schema.WaitId.make(pending.token);
|
|
14910
14927
|
const waitSequence = yield* allocateEventSequence(config);
|
|
14911
14928
|
yield* config.waits.createDetached({
|
|
14912
|
-
waitId,
|
|
14929
|
+
waitId: waitId2,
|
|
14913
14930
|
executionId: config.executionId,
|
|
14914
14931
|
mode: "event",
|
|
14915
14932
|
correlationKey: pending.toolCallId ?? pending.token,
|
|
@@ -14924,17 +14941,17 @@ var createAsk = Effect76.fn("RelayPermissions.createAsk")(function* (config, pen
|
|
|
14924
14941
|
eventSequence: waitSequence,
|
|
14925
14942
|
createdAt: createdAtForSequence(config, waitSequence)
|
|
14926
14943
|
}).pipe(Effect76.mapError((error5) => permissionError(error5.message)));
|
|
14927
|
-
yield* ensurePermissionRequestedEvent(config, pending,
|
|
14944
|
+
yield* ensurePermissionRequestedEvent(config, pending, waitId2);
|
|
14928
14945
|
});
|
|
14929
14946
|
var awaitAnswer = Effect76.fn("RelayPermissions.awaitAnswer")(function* (config, pending) {
|
|
14930
|
-
const
|
|
14931
|
-
const existing = yield* config.waits.get(
|
|
14947
|
+
const waitId2 = exports_ids_schema.WaitId.make(pending.token);
|
|
14948
|
+
const existing = yield* config.waits.get(waitId2).pipe(Effect76.mapError((error5) => permissionError(error5.message)));
|
|
14932
14949
|
if (existing === undefined) {
|
|
14933
14950
|
yield* createAsk(config, pending);
|
|
14934
14951
|
return Option16.none();
|
|
14935
14952
|
}
|
|
14936
14953
|
if (existing.state === "open") {
|
|
14937
|
-
yield* ensurePermissionRequestedEvent(config, pending,
|
|
14954
|
+
yield* ensurePermissionRequestedEvent(config, pending, waitId2);
|
|
14938
14955
|
return Option16.none();
|
|
14939
14956
|
}
|
|
14940
14957
|
const answer = answerForWait(existing);
|
|
@@ -16334,16 +16351,16 @@ var make12 = Effect86.gen(function* () {
|
|
|
16334
16351
|
}).pipe(Effect86.mapError(toSchedulerError));
|
|
16335
16352
|
}).pipe(Effect86.withSpan("SchedulerService.dispatchStartExecution"));
|
|
16336
16353
|
const dispatchWaitTransition = (schedule, now) => Effect86.gen(function* () {
|
|
16337
|
-
const
|
|
16338
|
-
if (
|
|
16354
|
+
const waitId2 = schedule.wait_id;
|
|
16355
|
+
if (waitId2 === undefined) {
|
|
16339
16356
|
return yield* SchedulerError.make({ message: `Schedule ${schedule.id} is missing wait_id` });
|
|
16340
16357
|
}
|
|
16341
|
-
const wait = yield* waits.get(
|
|
16358
|
+
const wait = yield* waits.get(waitId2).pipe(Effect86.mapError(toSchedulerError));
|
|
16342
16359
|
if (wait === undefined || wait.state !== "open")
|
|
16343
16360
|
return;
|
|
16344
16361
|
const eventSequence = yield* nextEventSequence5(eventLog, wait.executionId);
|
|
16345
16362
|
const metadata11 = dispatchMetadata(schedule);
|
|
16346
|
-
const result = schedule.target_kind === "wake-wait" ? yield* waits.wake({ waitId, resolvedAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError)) : yield* waits.timeout({ waitId, timedOutAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError));
|
|
16363
|
+
const result = schedule.target_kind === "wake-wait" ? yield* waits.wake({ waitId: waitId2, resolvedAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError)) : yield* waits.timeout({ waitId: waitId2, timedOutAt: now, eventSequence, metadata: metadata11 }).pipe(Effect86.mapError(toSchedulerError));
|
|
16347
16364
|
if (!result.transitioned)
|
|
16348
16365
|
return;
|
|
16349
16366
|
yield* signalWorkflowWait({
|
|
@@ -17580,13 +17597,13 @@ var toToolWorkLease = (lease) => ({
|
|
|
17580
17597
|
claim_expires_at: lease.claimExpiresAt,
|
|
17581
17598
|
idempotency_key: lease.idempotencyKey
|
|
17582
17599
|
});
|
|
17583
|
-
var toolWaitId = (callId) =>
|
|
17600
|
+
var toolWaitId = (executionId, callId) => Identifiers.waitId("tool", executionId, callId);
|
|
17584
17601
|
var acceptedWaitOutcome = (wait) => Schema83.decodeUnknownEffect(exports_tool_schema.ExternalOutcome)(wait.metadata.external_outcome).pipe(Effect90.mapError(toClientError));
|
|
17585
17602
|
var resolveToolOutcomeWait = Effect90.fn("Client.resolveToolOutcomeWait")(function* (waits, eventLog, call, outcome, completedAt) {
|
|
17586
|
-
const
|
|
17587
|
-
const wait = yield* waits.get(
|
|
17603
|
+
const waitId2 = call.waitId ?? toolWaitId(call.executionId, call.call.id);
|
|
17604
|
+
const wait = yield* waits.get(waitId2).pipe(Effect90.mapError(toClientError));
|
|
17588
17605
|
if (wait === undefined)
|
|
17589
|
-
return yield* ClientError.make({ message: `Tool wait not found: ${
|
|
17606
|
+
return yield* ClientError.make({ message: `Tool wait not found: ${waitId2}` });
|
|
17590
17607
|
if (wait.executionId !== call.executionId) {
|
|
17591
17608
|
return yield* ClientError.make({ message: `Tool wait does not match call: ${call.call.id}` });
|
|
17592
17609
|
}
|
|
@@ -17602,7 +17619,7 @@ var resolveToolOutcomeWait = Effect90.fn("Client.resolveToolOutcomeWait")(functi
|
|
|
17602
17619
|
}
|
|
17603
17620
|
const eventSequence = yield* nextEventSequence6(eventLog, call.executionId);
|
|
17604
17621
|
const resolved = yield* waits.wake({
|
|
17605
|
-
waitId,
|
|
17622
|
+
waitId: waitId2,
|
|
17606
17623
|
resolvedAt: completedAt,
|
|
17607
17624
|
eventSequence,
|
|
17608
17625
|
metadata: { kind: "tool-placement", external_outcome: outcome }
|
|
@@ -17747,10 +17764,10 @@ var childSpawnFingerprint = (record2) => {
|
|
|
17747
17764
|
return typeof fingerprint === "string" ? fingerprint : undefined;
|
|
17748
17765
|
};
|
|
17749
17766
|
var createChildJoinWait = Effect90.fn("Client.createChildJoinWait")(function* (waits, eventLog, input, accepted2, createdAt) {
|
|
17750
|
-
const
|
|
17767
|
+
const waitId2 = childJoinWaitId(accepted2.child_execution_id);
|
|
17751
17768
|
const eventSequence = yield* nextEventSequence6(eventLog, input.execution_id);
|
|
17752
17769
|
yield* waits.createDetached({
|
|
17753
|
-
waitId,
|
|
17770
|
+
waitId: waitId2,
|
|
17754
17771
|
executionId: input.execution_id,
|
|
17755
17772
|
mode: "child",
|
|
17756
17773
|
correlationKey: accepted2.child_execution_id,
|
|
@@ -17761,7 +17778,7 @@ var createChildJoinWait = Effect90.fn("Client.createChildJoinWait")(function* (w
|
|
|
17761
17778
|
eventSequence,
|
|
17762
17779
|
createdAt
|
|
17763
17780
|
}).pipe(Effect90.mapError(toClientError));
|
|
17764
|
-
return
|
|
17781
|
+
return waitId2;
|
|
17765
17782
|
});
|
|
17766
17783
|
var reconcileExistingChildSpawn = Effect90.fn("Client.reconcileExistingChildSpawn")(function* (childExecutions, waits, eventLog, input) {
|
|
17767
17784
|
const childExecutionId3 = childExecutionIdForSpawn(input);
|
|
@@ -17941,7 +17958,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
|
|
|
17941
17958
|
return yield* ExecutionNotFound.make({ execution_id: executionId });
|
|
17942
17959
|
const openWaits = yield* envelopeReady.listAllWaits({ executionId, state: "open" }).pipe(Effect90.mapError(toClientError));
|
|
17943
17960
|
const calls = yield* toolCalls2.listCalls(executionId).pipe(Effect90.mapError(toClientError));
|
|
17944
|
-
const pendingChunks = yield* Effect90.forEach(calls, (call) => toolCalls2.getResult(call.call.id).pipe(Effect90.mapError(toClientError), Effect90.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
|
|
17961
|
+
const pendingChunks = yield* Effect90.forEach(calls, (call) => toolCalls2.getResult(call.executionId, call.call.id).pipe(Effect90.mapError(toClientError), Effect90.map((result) => result === undefined ? [toToolCallSummary(call)] : [])));
|
|
17945
17962
|
const children = yield* childExecutions.listByExecution(executionId).pipe(Effect90.mapError(toClientError));
|
|
17946
17963
|
const maxSequence3 = yield* eventLog.maxSequence(executionId).pipe(Effect90.mapError(toClientError));
|
|
17947
17964
|
const lastEvent = maxSequence3 === undefined ? undefined : yield* eventLog.findBySequence({ executionId, sequence: maxSequence3 }).pipe(Effect90.mapError(toClientError), Effect90.map(Option23.getOrUndefined));
|
|
@@ -18407,13 +18424,13 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
|
|
|
18407
18424
|
state: "open",
|
|
18408
18425
|
...input.execution_id === undefined ? {} : { executionId: input.execution_id }
|
|
18409
18426
|
}).pipe(Effect90.mapError(toClientError));
|
|
18410
|
-
const records = yield* Effect90.forEach(openWaits.filter((wait) => wait.metadata.kind === "tool-placement"), (wait) => toolCalls2.getCall(exports_ids_schema.ToolCallId.make(String(wait.metadata.tool_call_id ?? ""))).pipe(Effect90.mapError(toClientError), Effect90.map((call) => call?.placement.kind === "client" && call.state === "waiting" ? toPendingToolCall(call) : undefined)));
|
|
18427
|
+
const records = yield* Effect90.forEach(openWaits.filter((wait) => wait.metadata.kind === "tool-placement"), (wait) => toolCalls2.getCall(wait.executionId, exports_ids_schema.ToolCallId.make(String(wait.metadata.tool_call_id ?? ""))).pipe(Effect90.mapError(toClientError), Effect90.map((call) => call?.placement.kind === "client" && call.state === "waiting" ? toPendingToolCall(call) : undefined)));
|
|
18411
18428
|
const sorted = records.filter((record2) => record2 !== undefined).toSorted((left, right) => left.requested_at - right.requested_at || left.call.id.localeCompare(right.call.id));
|
|
18412
18429
|
return { tool_calls: input.limit === undefined ? sorted : sorted.slice(0, input.limit) };
|
|
18413
18430
|
}),
|
|
18414
18431
|
fulfillToolCall: Effect90.fn("Client.runtime.fulfillToolCall")(function* (input) {
|
|
18415
18432
|
const coordinated = yield* coordinateToolTransition(Effect90.gen(function* () {
|
|
18416
|
-
const call = yield* toolCalls2.getCall(input.tool_call_id).pipe(Effect90.mapError(toClientError));
|
|
18433
|
+
const call = yield* toolCalls2.getCall(input.execution_id, input.tool_call_id).pipe(Effect90.mapError(toClientError));
|
|
18417
18434
|
if (call === undefined || call.executionId !== input.execution_id || call.placement.kind !== "client") {
|
|
18418
18435
|
return yield* ClientError.make({ message: `Client tool call not found: ${input.tool_call_id}` });
|
|
18419
18436
|
}
|
|
@@ -18440,7 +18457,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
|
|
|
18440
18457
|
}),
|
|
18441
18458
|
completeToolWork: Effect90.fn("Client.runtime.completeToolWork")(function* (input) {
|
|
18442
18459
|
const coordinated = yield* coordinateToolTransition(Effect90.gen(function* () {
|
|
18443
|
-
const call = yield* toolCalls2.getCall(input.tool_call_id).pipe(Effect90.mapError(toClientError));
|
|
18460
|
+
const call = yield* toolCalls2.getCall(input.execution_id, input.tool_call_id).pipe(Effect90.mapError(toClientError));
|
|
18444
18461
|
const active = call !== undefined && call.placement.kind === "remote" && call.state === "running" && call.activeAttemptId === input.attempt_id && call.claimOwner === input.worker_id && call.claimExpiresAt !== undefined && call.claimExpiresAt > input.completed_at;
|
|
18445
18462
|
const acceptedRetry = call !== undefined && call.placement.kind === "remote" && call.state === "submitted" && call.activeAttemptId === input.attempt_id && call.externalOutcome !== undefined;
|
|
18446
18463
|
if (call === undefined || !active && !acceptedRetry) {
|
|
@@ -18448,6 +18465,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
|
|
|
18448
18465
|
}
|
|
18449
18466
|
const wait = yield* resolveToolOutcomeWait(waits, eventLog, call, input.outcome, input.completed_at);
|
|
18450
18467
|
const accepted2 = yield* toolCalls2.acceptRemoteOutcome({
|
|
18468
|
+
executionId: input.execution_id,
|
|
18451
18469
|
callId: input.tool_call_id,
|
|
18452
18470
|
attemptId: input.attempt_id,
|
|
18453
18471
|
workerId: input.worker_id,
|
|
@@ -18461,6 +18479,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
|
|
|
18461
18479
|
}),
|
|
18462
18480
|
releaseToolWork: Effect90.fn("Client.runtime.releaseToolWork")(function* (input) {
|
|
18463
18481
|
const call = yield* coordinateToolTransition(toolCalls2.releaseRemote({
|
|
18482
|
+
executionId: input.execution_id,
|
|
18464
18483
|
callId: input.tool_call_id,
|
|
18465
18484
|
attemptId: input.attempt_id,
|
|
18466
18485
|
workerId: input.worker_id,
|
|
@@ -18475,7 +18494,7 @@ var layerFromRuntime3 = Layer80.effect(Service, Effect90.gen(function* () {
|
|
|
18475
18494
|
};
|
|
18476
18495
|
}),
|
|
18477
18496
|
listToolAttempts: Effect90.fn("Client.runtime.listToolAttempts")(function* (input) {
|
|
18478
|
-
const attempts = yield* toolCalls2.listAttempts(input.tool_call_id).pipe(Effect90.mapError(toClientError));
|
|
18497
|
+
const attempts = yield* toolCalls2.listAttempts(input.execution_id, input.tool_call_id).pipe(Effect90.mapError(toClientError));
|
|
18479
18498
|
return { attempts: attempts.map(toToolAttempt) };
|
|
18480
18499
|
}),
|
|
18481
18500
|
submitInboundEnvelope: Effect90.fn("Client.runtime.submitInboundEnvelope")(function* (input) {
|