@relayfx/sdk 0.4.0 → 0.4.2
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/{index-cs3be24t.js → index-4y9111jh.js} +1 -1
- package/dist/{index-p43mg4kt.js → index-y9ncz0zd.js} +43 -74
- package/dist/index.js +1 -1
- package/dist/mysql.js +2 -2
- package/dist/postgres.js +2 -2
- package/dist/sqlite.js +2 -2
- package/dist/types/runtime/agent/agent-loop-events.d.ts +1 -1
- package/dist/types/runtime/agent/relay-tool-executor.d.ts +0 -1
- package/dist/types/runtime/tool/tool-runtime-contract.d.ts +0 -1
- package/package.json +1 -1
|
@@ -10887,12 +10887,6 @@ var makeService = (initialTools) => Effect55.gen(function* () {
|
|
|
10887
10887
|
yield* input.onRequested;
|
|
10888
10888
|
}),
|
|
10889
10889
|
run: Effect55.fn("ToolRuntime.run")(function* (input) {
|
|
10890
|
-
let settlementSequence;
|
|
10891
|
-
const beginSettlement = Effect55.suspend(() => {
|
|
10892
|
-
if (settlementSequence !== undefined)
|
|
10893
|
-
return Effect55.succeed(settlementSequence);
|
|
10894
|
-
return (input.beforeSettlement ?? Effect55.succeed(input.eventSequence)).pipe(Effect55.tap((sequence) => Effect55.sync(() => settlementSequence = sequence)));
|
|
10895
|
-
});
|
|
10896
10890
|
const stored = yield* Ref12.get(tools);
|
|
10897
10891
|
const registry = (input.extraTools ?? []).reduce(upsertTool, stored);
|
|
10898
10892
|
const registeredTool = Chunk.findFirst(registry, sameToolName(input.call.name)).pipe(Option12.getOrUndefined);
|
|
@@ -10907,7 +10901,6 @@ var makeService = (initialTools) => Effect55.gen(function* () {
|
|
|
10907
10901
|
yield* input.onRequested;
|
|
10908
10902
|
const existingResult = yield* repository.getResult(input.executionId, input.call.id).pipe(Effect55.mapError(mapRepositoryError2));
|
|
10909
10903
|
if (existingResult !== undefined) {
|
|
10910
|
-
yield* beginSettlement;
|
|
10911
10904
|
yield* repairResultEvent(eventLog, input, existingResult);
|
|
10912
10905
|
return existingResult.result;
|
|
10913
10906
|
}
|
|
@@ -10915,17 +10908,11 @@ var makeService = (initialTools) => Effect55.gen(function* () {
|
|
|
10915
10908
|
if (registeredTool.definition.needs_approval === true) {
|
|
10916
10909
|
const bypass = yield* hasPermissionApprovalBypass(waits, input);
|
|
10917
10910
|
if (!bypass) {
|
|
10918
|
-
const
|
|
10911
|
+
const decision = yield* resolveApproval(waits, eventLog, input);
|
|
10919
10912
|
effectiveInput = {
|
|
10920
10913
|
...input,
|
|
10921
|
-
eventSequence:
|
|
10922
|
-
createdAt: input.createdAt +
|
|
10923
|
-
};
|
|
10924
|
-
const decision = yield* resolveApproval(waits, eventLog, effectiveInput);
|
|
10925
|
-
effectiveInput = {
|
|
10926
|
-
...effectiveInput,
|
|
10927
|
-
eventSequence: effectiveInput.eventSequence + 1,
|
|
10928
|
-
createdAt: effectiveInput.createdAt + 1
|
|
10914
|
+
eventSequence: input.eventSequence + 1,
|
|
10915
|
+
createdAt: input.createdAt + 1
|
|
10929
10916
|
};
|
|
10930
10917
|
if (decision._tag === "denied") {
|
|
10931
10918
|
const deniedRecord = yield* persistReceived(repository, effectiveInput, {
|
|
@@ -10944,18 +10931,8 @@ var makeService = (initialTools) => Effect55.gen(function* () {
|
|
|
10944
10931
|
callId: input.call.id,
|
|
10945
10932
|
startedAt: effectiveInput.createdAt
|
|
10946
10933
|
}).pipe(Effect55.mapError(mapRepositoryError2), Effect55.flatMap(() => finalToolResult(registeredTool, effectiveInput, call.idempotencyKey)), Effect55.catchTag("ToolExecutionFailed", (error5) => Effect55.succeed(placementFailureResult(input, error5.message))));
|
|
10947
|
-
const
|
|
10948
|
-
|
|
10949
|
-
if (effectiveInput === input) {
|
|
10950
|
-
const sequence = yield* beginSettlement;
|
|
10951
|
-
effectiveInput = {
|
|
10952
|
-
...input,
|
|
10953
|
-
eventSequence: sequence,
|
|
10954
|
-
createdAt: input.createdAt + sequence - input.eventSequence
|
|
10955
|
-
};
|
|
10956
|
-
}
|
|
10957
|
-
const received = yield* recordReceived(eventLog, effectiveInput, record2);
|
|
10958
|
-
yield* recordToolCall(input.call.name, result.error === undefined ? "success" : "failure");
|
|
10934
|
+
const received = yield* Effect55.uninterruptibleMask((restore) => restore(executeHandler).pipe(Effect55.flatMap((rawResult) => input.transformResult === undefined || rawResult.error !== undefined ? Effect55.succeed(rawResult) : input.transformResult(rawResult)), Effect55.flatMap((result) => persistReceived(repository, effectiveInput, result)), Effect55.flatMap((record2) => recordReceived(eventLog, effectiveInput, record2))));
|
|
10935
|
+
yield* recordToolCall(input.call.name, received.error === undefined ? "success" : "failure");
|
|
10959
10936
|
return received;
|
|
10960
10937
|
}).pipe(Effect55.tapError((error5) => recordToolCall(input.call.name, error5._tag === "ToolExecutionWaitRequested" ? "wait" : error5._tag === "ToolPermissionDenied" ? "denied" : "failure")));
|
|
10961
10938
|
})
|
|
@@ -15616,15 +15593,6 @@ var boundResult = (config, result) => {
|
|
|
15616
15593
|
return exports_tool_output.bound({ _tag: "Success", result: result.output, encodedResult: result.output }, { toolCallId: result.call_id, maxBytes: config.toolOutputMaxBytes }).pipe(Effect90.map((bounded) => ({ ...result, output: jsonValue5(bounded.encodedResult) })));
|
|
15617
15594
|
};
|
|
15618
15595
|
var batchKey = (request) => `${request.turn}:${request.toolCallBatch.calls.map((call) => call.id).join(":")}`;
|
|
15619
|
-
var gateKey = (turn, toolCallIndex) => `${turn}:${toolCallIndex}`;
|
|
15620
|
-
var gateFor = (gates, key4) => {
|
|
15621
|
-
const existing = gates.get(key4);
|
|
15622
|
-
if (existing !== undefined)
|
|
15623
|
-
return existing;
|
|
15624
|
-
const created = Deferred3.makeUnsafe();
|
|
15625
|
-
gates.set(key4, created);
|
|
15626
|
-
return created;
|
|
15627
|
-
};
|
|
15628
15596
|
var callFrom = (call) => ({
|
|
15629
15597
|
id: exports_ids_schema.ToolCallId.make(call.id),
|
|
15630
15598
|
name: call.name,
|
|
@@ -15640,13 +15608,6 @@ var frameworkFailure = (call, error5) => {
|
|
|
15640
15608
|
};
|
|
15641
15609
|
var make9 = (config) => Effect90.sync(() => {
|
|
15642
15610
|
const prepared = new Map;
|
|
15643
|
-
const settled = new Map;
|
|
15644
|
-
const awaitPrevious = (gates, request) => {
|
|
15645
|
-
if (request.toolCallIndex === 0 || config.resumedToolCallId === request.call.id)
|
|
15646
|
-
return Effect90.void;
|
|
15647
|
-
return Deferred3.await(gateFor(gates, gateKey(request.turn, request.toolCallIndex - 1)));
|
|
15648
|
-
};
|
|
15649
|
-
const completeSettlement = (request) => Deferred3.succeed(gateFor(settled, gateKey(request.turn, request.toolCallIndex)), undefined).pipe(Effect90.asVoid);
|
|
15650
15611
|
return exports_tool_executor.ToolExecutor.of({
|
|
15651
15612
|
execute: (request) => {
|
|
15652
15613
|
const key4 = batchKey(request);
|
|
@@ -15674,12 +15635,6 @@ var make9 = (config) => Effect90.sync(() => {
|
|
|
15674
15635
|
}).pipe(Effect90.exit, Effect90.flatMap((exit) => Deferred3.done(preparation, exit)), Effect90.andThen(Deferred3.await(preparation)), Effect90.uninterruptible) : Deferred3.await(preparation);
|
|
15675
15636
|
return Effect90.gen(function* () {
|
|
15676
15637
|
yield* prepareBatch;
|
|
15677
|
-
let settlementSequence;
|
|
15678
|
-
const beginSettlement = Effect90.suspend(() => {
|
|
15679
|
-
if (settlementSequence !== undefined)
|
|
15680
|
-
return Effect90.succeed(settlementSequence);
|
|
15681
|
-
return awaitPrevious(settled, request).pipe(Effect90.andThen(config.allocator.current), Effect90.map((sequence) => sequence - 1), Effect90.tap((sequence) => Effect90.sync(() => settlementSequence = sequence)));
|
|
15682
|
-
});
|
|
15683
15638
|
const first = yield* config.allocator.current;
|
|
15684
15639
|
const call = callFrom(request.call);
|
|
15685
15640
|
const existingRequest = yield* hasRequestedEvent(config, call.id);
|
|
@@ -15691,13 +15646,12 @@ var make9 = (config) => Effect90.sync(() => {
|
|
|
15691
15646
|
eventSequence,
|
|
15692
15647
|
createdAt: config.startedAt + eventSequence - config.eventSequence,
|
|
15693
15648
|
...config.extraTools === undefined ? {} : { extraTools: config.extraTools },
|
|
15694
|
-
beforeSettlement: beginSettlement,
|
|
15695
15649
|
transformResult: (result) => boundResult(config, result)
|
|
15696
15650
|
}).pipe(Effect90.flatMap((result) => nextLoggedSequence2(config.eventLog, config.executionId, existingRequest ? first + 1 : first + 2).pipe(Effect90.flatMap(config.allocator.advanceTo), Effect90.as(result.error === undefined ? { _tag: "Success", result: result.output, encodedResult: result.output } : {
|
|
15697
15651
|
_tag: "DomainFailure",
|
|
15698
15652
|
failure: result.error,
|
|
15699
15653
|
encodedFailure: result.error
|
|
15700
|
-
}))), Effect90.catch((error5) =>
|
|
15654
|
+
}))), Effect90.catch((error5) => nextLoggedSequence2(config.eventLog, config.executionId, first).pipe(Effect90.flatMap(config.allocator.advanceTo), Effect90.flatMap(() => {
|
|
15701
15655
|
if (error5._tag === "ToolExecutionWaitRequested") {
|
|
15702
15656
|
return Effect90.succeed({ _tag: "Suspend", token: error5.wait_id });
|
|
15703
15657
|
}
|
|
@@ -15706,7 +15660,7 @@ var make9 = (config) => Effect90.sync(() => {
|
|
|
15706
15660
|
return Effect90.succeed({ _tag: "DomainFailure", failure: failure2, encodedFailure: failure2 });
|
|
15707
15661
|
}
|
|
15708
15662
|
return Effect90.fail(frameworkFailure(call, error5));
|
|
15709
|
-
})))
|
|
15663
|
+
}))));
|
|
15710
15664
|
});
|
|
15711
15665
|
}
|
|
15712
15666
|
});
|
|
@@ -15772,6 +15726,13 @@ var modelMetadata = (agent) => ({
|
|
|
15772
15726
|
model: agent.model.model,
|
|
15773
15727
|
...agent.model.registration_key === undefined ? {} : { registration_key: agent.model.registration_key }
|
|
15774
15728
|
});
|
|
15729
|
+
var serviceTier = (part) => {
|
|
15730
|
+
const openai = part.metadata.openai;
|
|
15731
|
+
if (openai === null || typeof openai !== "object" || Array.isArray(openai))
|
|
15732
|
+
return;
|
|
15733
|
+
const value = openai.serviceTier;
|
|
15734
|
+
return typeof value === "string" ? value : undefined;
|
|
15735
|
+
};
|
|
15775
15736
|
var inputPreparedEvent = (input, definitions2) => ({
|
|
15776
15737
|
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${input.eventSequence}:input-prepared`),
|
|
15777
15738
|
execution_id: input.executionId,
|
|
@@ -15787,25 +15748,30 @@ var inputPreparedEvent = (input, definitions2) => ({
|
|
|
15787
15748
|
},
|
|
15788
15749
|
created_at: input.startedAt
|
|
15789
15750
|
});
|
|
15790
|
-
var usageReportedEvent = (input, part, sequence) =>
|
|
15791
|
-
|
|
15792
|
-
|
|
15793
|
-
|
|
15794
|
-
|
|
15795
|
-
|
|
15796
|
-
|
|
15797
|
-
|
|
15798
|
-
|
|
15799
|
-
|
|
15800
|
-
|
|
15801
|
-
|
|
15802
|
-
|
|
15803
|
-
|
|
15804
|
-
|
|
15805
|
-
|
|
15806
|
-
|
|
15807
|
-
|
|
15808
|
-
|
|
15751
|
+
var usageReportedEvent = (input, part, modelSnapshot, sequence) => {
|
|
15752
|
+
const tier = serviceTier(part);
|
|
15753
|
+
return {
|
|
15754
|
+
id: exports_ids_schema.EventId.make(`event:${input.executionId}:model:${sequence}:usage`),
|
|
15755
|
+
execution_id: input.executionId,
|
|
15756
|
+
type: "model.usage.reported",
|
|
15757
|
+
sequence,
|
|
15758
|
+
cursor: `${input.executionId}:model:${sequence}:usage`,
|
|
15759
|
+
data: {
|
|
15760
|
+
provider: input.agent.model.provider,
|
|
15761
|
+
model: input.agent.model.model,
|
|
15762
|
+
...modelSnapshot === undefined ? {} : { model_snapshot: modelSnapshot },
|
|
15763
|
+
...tier === undefined ? {} : { service_tier: tier },
|
|
15764
|
+
finish_reason: part.reason,
|
|
15765
|
+
input_tokens: part.usage.inputTokens.total ?? null,
|
|
15766
|
+
input_tokens_uncached: part.usage.inputTokens.uncached ?? null,
|
|
15767
|
+
input_tokens_cache_read: part.usage.inputTokens.cacheRead ?? null,
|
|
15768
|
+
input_tokens_cache_write: part.usage.inputTokens.cacheWrite ?? null,
|
|
15769
|
+
output_tokens: part.usage.outputTokens.total ?? null,
|
|
15770
|
+
output_tokens_reasoning: part.usage.outputTokens.reasoning ?? null
|
|
15771
|
+
},
|
|
15772
|
+
created_at: input.startedAt + (sequence - input.eventSequence)
|
|
15773
|
+
};
|
|
15774
|
+
};
|
|
15809
15775
|
var budgetExceededEvent = (input, tokensUsed, tokenBudget, sequence) => ({
|
|
15810
15776
|
id: exports_ids_schema.EventId.make(`event:${input.executionId}:budget:${sequence}:exceeded`),
|
|
15811
15777
|
execution_id: input.executionId,
|
|
@@ -16454,7 +16420,6 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
|
|
|
16454
16420
|
startedAt: input.startedAt,
|
|
16455
16421
|
eventSequence: input.eventSequence,
|
|
16456
16422
|
...toolOutputMaxBytes === undefined ? {} : { toolOutputMaxBytes },
|
|
16457
|
-
...resumeToolCall === undefined ? {} : { resumedToolCallId: resumeToolCall.id },
|
|
16458
16423
|
...allCoreTools.length === 0 ? {} : { extraTools: allCoreTools }
|
|
16459
16424
|
});
|
|
16460
16425
|
const activeBlobStore = toolOutputMaxBytes === undefined || Option24.isNone(blobStore) ? undefined : blobStore.value;
|
|
@@ -16500,6 +16465,8 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
|
|
|
16500
16465
|
if (part.type === "tool-params-start") {
|
|
16501
16466
|
return { ...state, toolCallNames: { ...state.toolCallNames, [part.id]: part.name } };
|
|
16502
16467
|
}
|
|
16468
|
+
if (part.type === "response-metadata")
|
|
16469
|
+
return { ...state, modelId: part.modelId };
|
|
16503
16470
|
if (part.type === "tool-params-delta") {
|
|
16504
16471
|
const sequence = yield* allocator.allocate(1);
|
|
16505
16472
|
const deltaIndex = state.toolCallDeltaIndexes[part.id] ?? 0;
|
|
@@ -16512,7 +16479,7 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
|
|
|
16512
16479
|
if (part.type === "finish") {
|
|
16513
16480
|
const finish = part;
|
|
16514
16481
|
const sequence = yield* allocator.allocate(1);
|
|
16515
|
-
yield* appendEvent(eventLog, allocator, usageReportedEvent2(input, finish, sequence), sequence + 1);
|
|
16482
|
+
yield* appendEvent(eventLog, allocator, usageReportedEvent2(input, finish, state.modelId, sequence), sequence + 1);
|
|
16516
16483
|
yield* recordModelUsage({
|
|
16517
16484
|
provider: input.agent.model.provider,
|
|
16518
16485
|
model: input.agent.model.model,
|
|
@@ -16522,6 +16489,7 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
|
|
|
16522
16489
|
});
|
|
16523
16490
|
return {
|
|
16524
16491
|
...state,
|
|
16492
|
+
modelId: undefined,
|
|
16525
16493
|
tokensUsed: state.tokensUsed + (finish.usage.inputTokens.total ?? 0) + (finish.usage.outputTokens.total ?? 0)
|
|
16526
16494
|
};
|
|
16527
16495
|
}
|
|
@@ -16555,6 +16523,7 @@ var make12 = (layerOptions) => Effect93.gen(function* () {
|
|
|
16555
16523
|
text: "",
|
|
16556
16524
|
transcript: undefined,
|
|
16557
16525
|
turn: undefined,
|
|
16526
|
+
modelId: undefined,
|
|
16558
16527
|
tokensUsed: seededTokens,
|
|
16559
16528
|
toolCallNames: {},
|
|
16560
16529
|
toolCallDeltaIndexes: {}
|
package/dist/index.js
CHANGED
package/dist/mysql.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import {
|
|
3
3
|
database,
|
|
4
4
|
normalizeMigrationCause
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-4y9111jh.js";
|
|
6
6
|
import {
|
|
7
7
|
MigratorError,
|
|
8
8
|
RuntimeMigrationError,
|
|
9
9
|
SqlFailure
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-y9ncz0zd.js";
|
|
11
11
|
import"./index-x32kbvxv.js";
|
|
12
12
|
import"./index-3w6txjtg.js";
|
|
13
13
|
import"./index-nb39b5ae.js";
|
package/dist/postgres.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
database,
|
|
4
4
|
normalizeMigrationCause
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-4y9111jh.js";
|
|
6
6
|
import {
|
|
7
7
|
Dialect,
|
|
8
8
|
RuntimeMigrationError,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
fromDbTimestamp,
|
|
15
15
|
fromNullableDbTimestamp,
|
|
16
16
|
timestampParam
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-y9ncz0zd.js";
|
|
18
18
|
import"./index-x32kbvxv.js";
|
|
19
19
|
import {
|
|
20
20
|
exports_ids_schema
|
package/dist/sqlite.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
database,
|
|
4
4
|
normalizeMigrationCause
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-4y9111jh.js";
|
|
6
6
|
import {
|
|
7
7
|
DatabaseAlreadyOwned,
|
|
8
8
|
RuntimeConfigurationError,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
make,
|
|
13
13
|
makeDatabaseIdentity,
|
|
14
14
|
runtimeLayer
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-y9ncz0zd.js";
|
|
16
16
|
import"./index-x32kbvxv.js";
|
|
17
17
|
import"./index-3w6txjtg.js";
|
|
18
18
|
import"./index-nb39b5ae.js";
|
|
@@ -2,7 +2,7 @@ import { Content, Execution, Shared, Tool } from "../../schema/index";
|
|
|
2
2
|
import type { Response } from "effect/unstable/ai";
|
|
3
3
|
import type { RunInput } from "./agent-loop-service";
|
|
4
4
|
declare const inputPreparedEvent: (input: RunInput, definitions: ReadonlyArray<Tool.Definition>) => Execution.ExecutionEvent;
|
|
5
|
-
declare const usageReportedEvent: (input: RunInput, part: Response.FinishPart, sequence: Execution.ExecutionEventSequence) => Execution.ExecutionEvent;
|
|
5
|
+
declare const usageReportedEvent: (input: RunInput, part: Response.FinishPart, modelSnapshot: string | undefined, sequence: Execution.ExecutionEventSequence) => Execution.ExecutionEvent;
|
|
6
6
|
declare const budgetExceededEvent: (input: RunInput, tokensUsed: number, tokenBudget: number, sequence: Execution.ExecutionEventSequence) => Execution.ExecutionEvent;
|
|
7
7
|
declare const outputDeltaEvent: (input: RunInput, part: Response.TextDeltaPart, deltaIndex: number) => Execution.ExecutionEvent;
|
|
8
8
|
declare const reasoningDeltaEvent: (input: RunInput, part: Response.ReasoningPart | Response.ReasoningDeltaPart, deltaIndex: number) => Execution.ExecutionEvent;
|
|
@@ -15,7 +15,6 @@ export interface Config {
|
|
|
15
15
|
readonly startedAt: number;
|
|
16
16
|
readonly eventSequence: Execution.ExecutionEventSequence;
|
|
17
17
|
readonly toolOutputMaxBytes?: number;
|
|
18
|
-
readonly resumedToolCallId?: Ids.ToolCallId;
|
|
19
18
|
readonly extraTools?: ReadonlyArray<RegisteredTool>;
|
|
20
19
|
}
|
|
21
20
|
export declare const make: (config: Config) => Effect.Effect<ToolExecutor.Interface>;
|
|
@@ -106,7 +106,6 @@ export interface RunInput {
|
|
|
106
106
|
readonly createdAt: number;
|
|
107
107
|
readonly extraTools?: ReadonlyArray<RegisteredTool>;
|
|
108
108
|
readonly onRequested?: Effect.Effect<void>;
|
|
109
|
-
readonly beforeSettlement?: Effect.Effect<Execution.ExecutionEventSequence>;
|
|
110
109
|
readonly transformResult?: (result: Tool.Result) => Effect.Effect<Tool.Result, ToolRuntimeError>;
|
|
111
110
|
}
|
|
112
111
|
export type RunError = ToolNotRegistered | ToolPermissionDenied | ToolInputInvalid | ToolExecutionFailed | ToolExecutionWaitRequested | ToolRuntimeError;
|
package/package.json
CHANGED