@relayfx/sdk 0.0.48 → 0.0.50

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.
Files changed (34) hide show
  1. package/dist/ai.js +2054 -576
  2. package/dist/index.js +2884 -860
  3. package/dist/migrations/20260709214238_faithful_black_widow/migration.sql +53 -0
  4. package/dist/migrations/20260709214238_faithful_black_widow/snapshot.json +5426 -0
  5. package/dist/migrations/20260709220016_fearless_aaron_stack/migration.sql +2 -0
  6. package/dist/migrations/20260709220016_fearless_aaron_stack/snapshot.json +5426 -0
  7. package/dist/migrations/mysql/0002_durable_tool_placement.sql +75 -0
  8. package/dist/migrations/pg/20260709214238_faithful_black_widow/migration.sql +53 -0
  9. package/dist/migrations/pg/20260709214238_faithful_black_widow/snapshot.json +5426 -0
  10. package/dist/migrations/pg/20260709220016_fearless_aaron_stack/migration.sql +2 -0
  11. package/dist/migrations/pg/20260709220016_fearless_aaron_stack/snapshot.json +5426 -0
  12. package/dist/migrations/sqlite/0002_durable_tool_placement.sql +71 -0
  13. package/dist/types/relay/client.d.ts +27 -6
  14. package/dist/types/relay/index.d.ts +1 -0
  15. package/dist/types/relay/operation.d.ts +525 -53
  16. package/dist/types/relay/tool-worker.d.ts +19 -0
  17. package/dist/types/runtime/address/address-resolution-service.d.ts +69 -54
  18. package/dist/types/runtime/agent/relay-compaction.d.ts +1 -0
  19. package/dist/types/runtime/cluster/execution-entity.d.ts +10 -477
  20. package/dist/types/runtime/execution/event-log-service.d.ts +6 -0
  21. package/dist/types/runtime/index.d.ts +1 -0
  22. package/dist/types/runtime/runner/runner-runtime-service.d.ts +18 -15
  23. package/dist/types/runtime/tool/tool-runtime-service.d.ts +17 -1
  24. package/dist/types/runtime/tool/tool-transition-coordinator.d.ts +13 -0
  25. package/dist/types/runtime/workflow/execution-workflow.d.ts +146 -114
  26. package/dist/types/schema/agent-schema.d.ts +431 -320
  27. package/dist/types/schema/execution-schema.d.ts +69 -53
  28. package/dist/types/schema/ids-schema.d.ts +4 -0
  29. package/dist/types/schema/tool-schema.d.ts +29 -0
  30. package/dist/types/store-sql/envelope/envelope-repository.d.ts +6 -0
  31. package/dist/types/store-sql/execution/execution-event-repository.d.ts +6 -0
  32. package/dist/types/store-sql/schema/relay-schema.d.ts +386 -7
  33. package/dist/types/store-sql/tool/tool-call-repository.d.ts +160 -1
  34. package/package.json +3 -3
@@ -0,0 +1,71 @@
1
+ CREATE TABLE "relay_tool_attempts" (
2
+ "tenant_id" TEXT NOT NULL DEFAULT 'system',
3
+ "id" TEXT NOT NULL,
4
+ "tool_call_id" TEXT NOT NULL,
5
+ "attempt_number" INTEGER NOT NULL,
6
+ "state" TEXT NOT NULL,
7
+ "worker_id" TEXT,
8
+ "claim_expires_at" INTEGER,
9
+ "error" TEXT,
10
+ "created_at" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER)),
11
+ "completed_at" INTEGER,
12
+ CONSTRAINT "pk_relay_tool_attempts" PRIMARY KEY ("tenant_id", "tool_call_id", "id")
13
+ );
14
+ --> statement-breakpoint
15
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "definition_json" TEXT;
16
+ --> statement-breakpoint
17
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "placement_kind" TEXT NOT NULL DEFAULT 'local';
18
+ --> statement-breakpoint
19
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "placement_key" TEXT;
20
+ --> statement-breakpoint
21
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "state" TEXT NOT NULL DEFAULT 'requested';
22
+ --> statement-breakpoint
23
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "wait_id" TEXT;
24
+ --> statement-breakpoint
25
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "idempotency_key" TEXT NOT NULL DEFAULT '';
26
+ --> statement-breakpoint
27
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "available_at" INTEGER NOT NULL DEFAULT 0;
28
+ --> statement-breakpoint
29
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "active_attempt_id" TEXT;
30
+ --> statement-breakpoint
31
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "claim_owner" TEXT;
32
+ --> statement-breakpoint
33
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "claimed_at" INTEGER;
34
+ --> statement-breakpoint
35
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "claim_expires_at" INTEGER;
36
+ --> statement-breakpoint
37
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "external_outcome_json" TEXT;
38
+ --> statement-breakpoint
39
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "external_outcome_at" INTEGER;
40
+ --> statement-breakpoint
41
+ ALTER TABLE "relay_tool_calls" ADD COLUMN "updated_at" INTEGER NOT NULL DEFAULT 0;
42
+ --> statement-breakpoint
43
+ UPDATE "relay_tool_calls"
44
+ SET "idempotency_key" = 'tool:' || length("tenant_id") || ':' || "tenant_id" || ':' ||
45
+ length("execution_id") || ':' || "execution_id" || ':' || length("id") || ':' || "id",
46
+ "available_at" = "created_at",
47
+ "updated_at" = "created_at",
48
+ "state" = CASE
49
+ WHEN EXISTS (
50
+ SELECT 1 FROM "relay_tool_results" result
51
+ WHERE result."tenant_id" = "relay_tool_calls"."tenant_id"
52
+ AND result."tool_call_id" = "relay_tool_calls"."id"
53
+ AND result."error" IS NULL
54
+ ) THEN 'completed'
55
+ WHEN EXISTS (
56
+ SELECT 1 FROM "relay_tool_results" result
57
+ WHERE result."tenant_id" = "relay_tool_calls"."tenant_id"
58
+ AND result."tool_call_id" = "relay_tool_calls"."id"
59
+ ) THEN 'failed'
60
+ ELSE 'requested'
61
+ END;
62
+ --> statement-breakpoint
63
+ CREATE UNIQUE INDEX "uq_relay_tool_attempts_number" ON "relay_tool_attempts" ("tenant_id", "tool_call_id", "attempt_number");
64
+ --> statement-breakpoint
65
+ CREATE INDEX "idx_relay_tool_attempts_call" ON "relay_tool_attempts" ("tenant_id", "tool_call_id", "attempt_number");
66
+ --> statement-breakpoint
67
+ CREATE INDEX "idx_relay_tool_calls_remote_claim" ON "relay_tool_calls" ("tenant_id", "placement_kind", "placement_key", "state", "available_at", "created_at", "id");
68
+ --> statement-breakpoint
69
+ CREATE INDEX "idx_relay_tool_calls_stale_claim" ON "relay_tool_calls" ("tenant_id", "state", "claim_expires_at");
70
+ --> statement-breakpoint
71
+ CREATE INDEX "idx_relay_tool_calls_client_pending" ON "relay_tool_calls" ("tenant_id", "placement_kind", "state", "created_at", "id");
@@ -1,15 +1,22 @@
1
- import { AddressBook, AgentRegistry, EventLog, ExecutionService, SkillRegistry, WaitService } from "../runtime/index";
1
+ import { AddressBook, AgentRegistry, EventLog, ExecutionService, SkillRegistry, ToolTransitionCoordinator, WaitService } from "../runtime/index";
2
2
  import type { Agent as BatonAgent } from "@batonfx/core";
3
3
  import { Address, Agent, Content, Envelope, Execution, Ids, Shared, Skill, Tool } from "../schema/index";
4
- import { ClusterRegistryRepository, EnvelopeRepository, ExecutionRepository, ScheduleRepository, SessionRepository, SteeringRepository } from "../store-sql/index";
4
+ import { ChildExecutionRepository, ClusterRegistryRepository, EnvelopeRepository, ExecutionRepository, ScheduleRepository, SessionRepository, SteeringRepository, ToolCallRepository } from "../store-sql/index";
5
5
  import { Context, Effect, Layer, Schema, Stream } from "effect";
6
6
  import { Sharding, ShardingConfig } from "effect/unstable/cluster";
7
- import type { AckEnvelopeReadyInput, CancelExecutionAccepted, CancelExecutionInput, CancelScheduleInput, CancelScheduleResult, ClaimEnvelopeReadyInput, CreateScheduleInput, CreateScheduleResult, EnvelopeReadyAcked, EnvelopeReadyLease, EnvelopeReadyReleased, GetSessionInput, GetSessionResult, ListExecutionsInput, ListExecutionsResult, ListPendingApprovalsInput, ListRunnersResult, ListSchedulesInput, ListSchedulesResult, ListSessionsInput, ListSessionsResult, ListWaitsInput, PendingToolApprovalList, ReleaseEnvelopeReadyInput, ReplayExecutionInput, ReplayExecutionResult, ResolvePermissionInput, ResolveToolApprovalInput, RouteExecutionResult, StartExecutionInput, StartExecutionResult, SteerAccepted, SteerInput, StreamExecutionInput, SubmitInboundEnvelopeAccepted, SubmitInboundEnvelopeInput, WaitView, WakeAccepted, WakeInput } from "./operation";
7
+ import type { AckEnvelopeReadyInput, CancelExecutionAccepted, CancelExecutionInput, CancelScheduleInput, CancelScheduleResult, ClaimEnvelopeReadyInput, CreateScheduleInput, CreateScheduleResult, EnvelopeReadyAcked, EnvelopeReadyLease, EnvelopeReadyReleased, ExecutionInspection, GetSessionInput, GetSessionResult, ListExecutionsInput, ListExecutionsResult, ListPendingApprovalsInput, ListRunnersResult, ListSchedulesInput, ListSchedulesResult, ListSessionsInput, ListSessionsResult, ListWaitsInput, PendingToolApprovalList, PendingToolCallList, ListPendingToolCallsInput, FulfillToolCallInput, ClaimToolWorkInput, CompleteToolWorkInput, ReleaseToolWorkInput, ListToolAttemptsInput, ToolAttemptList, ToolOutcomeAccepted, ToolWorkLease, ToolWorkReleased, ReleaseEnvelopeReadyInput, ReplayExecutionInput, ReplayExecutionResult, ResolvePermissionInput, ResolveToolApprovalInput, RouteExecutionResult, StartExecutionInput, StartExecutionResult, SpawnChildRunInput, SteerAccepted, SteerInput, StreamExecutionInput, SubmitInboundEnvelopeAccepted, SubmitInboundEnvelopeInput, WaitView, WakeAccepted, WakeInput } from "./operation";
8
8
  declare const ClientError_base: Schema.Class<ClientError, Schema.TaggedStruct<"ClientError", {
9
9
  readonly message: Schema.String;
10
10
  }>, import("effect/Cause").YieldableError>;
11
11
  export declare class ClientError extends ClientError_base {
12
12
  }
13
+ declare const ExecutionNotFound_base: Schema.Class<ExecutionNotFound, Schema.TaggedStruct<"ExecutionNotFound", {
14
+ readonly execution_id: Schema.brand<Schema.String, "Relay.ExecutionId"> & {
15
+ make: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => string & import("effect/Brand").Brand<"Relay.ExecutionId">;
16
+ };
17
+ }>, import("effect/Cause").YieldableError>;
18
+ export declare class ExecutionNotFound extends ExecutionNotFound_base {
19
+ }
13
20
  export interface StartExecutionByAddressInput {
14
21
  readonly address_id: Ids.AddressId;
15
22
  readonly session_id?: Ids.SessionId;
@@ -73,6 +80,7 @@ export interface Interface {
73
80
  readonly cancelExecution: (input: CancelExecutionInput) => Effect.Effect<CancelExecutionAccepted, ClientError>;
74
81
  readonly steer: (input: SteerInput) => Effect.Effect<SteerAccepted, ClientError>;
75
82
  readonly getExecution: (id: Ids.ExecutionId) => Effect.Effect<Execution.Execution | undefined, ClientError>;
83
+ readonly inspectExecution: (executionId: Ids.ExecutionId) => Effect.Effect<ExecutionInspection, ExecutionNotFound | ClientError>;
76
84
  readonly listExecutions: (input: ListExecutionsInput) => Effect.Effect<ListExecutionsResult, ClientError>;
77
85
  readonly listSessions: (input: ListSessionsInput) => Effect.Effect<ListSessionsResult, ClientError>;
78
86
  readonly getSession: (input: GetSessionInput) => Effect.Effect<GetSessionResult, ClientError>;
@@ -86,8 +94,14 @@ export interface Interface {
86
94
  readonly listPendingApprovals: (input: ListPendingApprovalsInput) => Effect.Effect<PendingToolApprovalList, ClientError>;
87
95
  readonly resolveToolApproval: (input: ResolveToolApprovalInput) => Effect.Effect<WakeAccepted, ClientError>;
88
96
  readonly resolvePermission: (input: ResolvePermissionInput) => Effect.Effect<WakeAccepted, ClientError>;
97
+ readonly listPendingToolCalls: (input: ListPendingToolCallsInput) => Effect.Effect<PendingToolCallList, ClientError>;
98
+ readonly fulfillToolCall: (input: FulfillToolCallInput) => Effect.Effect<ToolOutcomeAccepted, ClientError>;
99
+ readonly claimToolWork: (input: ClaimToolWorkInput) => Effect.Effect<ToolWorkLease | null, ClientError>;
100
+ readonly completeToolWork: (input: CompleteToolWorkInput) => Effect.Effect<ToolOutcomeAccepted, ClientError>;
101
+ readonly releaseToolWork: (input: ReleaseToolWorkInput) => Effect.Effect<ToolWorkReleased, ClientError>;
102
+ readonly listToolAttempts: (input: ListToolAttemptsInput) => Effect.Effect<ToolAttemptList, ClientError>;
89
103
  readonly submitInboundEnvelope: (input: SubmitInboundEnvelopeInput) => Effect.Effect<SubmitInboundEnvelopeAccepted, ClientError>;
90
- readonly spawnChildRun: (input: Execution.SpawnChildRunInput) => Effect.Effect<Execution.ChildRunAccepted, ClientError>;
104
+ readonly spawnChildRun: (input: SpawnChildRunInput) => Effect.Effect<Execution.ChildRunAccepted, ClientError>;
91
105
  readonly claimEnvelopeReady: (input: ClaimEnvelopeReadyInput) => Effect.Effect<EnvelopeReadyLease | null, ClientError>;
92
106
  readonly ackEnvelopeReady: (input: AckEnvelopeReadyInput) => Effect.Effect<EnvelopeReadyAcked, ClientError>;
93
107
  readonly releaseEnvelopeReady: (input: ReleaseEnvelopeReadyInput) => Effect.Effect<EnvelopeReadyReleased, ClientError>;
@@ -98,7 +112,7 @@ export interface Interface {
98
112
  declare const Service_base: Context.ServiceClass<Service, "@relayfx/sdk/Client", Interface>;
99
113
  export declare class Service extends Service_base {
100
114
  }
101
- export declare const layerFromRuntime: Layer.Layer<Service, never, AgentRegistry.Service | AddressBook.Service | ExecutionService.Service | WaitService.Service | EventLog.Service | EnvelopeRepository.Service | ExecutionRepository.Service | SessionRepository.Service | SteeringRepository.Service | ClusterRegistryRepository.Service | ScheduleRepository.Service | SkillRegistry.Service | Sharding.Sharding | ShardingConfig.ShardingConfig>;
115
+ export declare const layerFromRuntime: Layer.Layer<Service, never, AgentRegistry.Service | AddressBook.Service | ExecutionService.Service | WaitService.Service | EventLog.Service | EnvelopeRepository.Service | ExecutionRepository.Service | ToolCallRepository.Service | ChildExecutionRepository.Service | SessionRepository.Service | SteeringRepository.Service | ClusterRegistryRepository.Service | ScheduleRepository.Service | SkillRegistry.Service | ToolTransitionCoordinator.Service | Sharding.Sharding | ShardingConfig.ShardingConfig>;
102
116
  export declare const testLayer: (implementation: Interface) => Layer.Layer<Service, never, never>;
103
117
  export declare const registerAgentDefinition: (input: Agent.RegisterDefinitionPayload) => Effect.Effect<Agent.DefinitionRegistered, ClientError, Service>;
104
118
  export declare const registerAgent: (input: RegisterAgentInput) => Effect.Effect<Agent.DefinitionRegistered, ClientError, Service>;
@@ -124,14 +138,21 @@ export declare const listWaits: (input: ListWaitsInput) => Effect.Effect<readonl
124
138
  export declare const replayExecution: (input: ReplayExecutionInput) => Effect.Effect<ReplayExecutionResult, ClientError, Service>;
125
139
  export declare const listRunners: () => Effect.Effect<ListRunnersResult, ClientError, Service>;
126
140
  export declare const routeExecution: (executionId: string & import("effect/Brand").Brand<"Relay.ExecutionId">) => Effect.Effect<RouteExecutionResult, ClientError, Service>;
141
+ export declare const inspectExecution: (executionId: string & import("effect/Brand").Brand<"Relay.ExecutionId">) => Effect.Effect<ExecutionInspection, ClientError | ExecutionNotFound, Service>;
127
142
  export declare const send: (input: Envelope.SendInput) => Effect.Effect<Envelope.EnvelopeAccepted, ClientError, Service>;
128
143
  export declare const streamExecution: (input: StreamExecutionInput) => Stream.Stream<Execution.ExecutionEvent, ClientError, Service>;
129
144
  export declare const wake: (input: WakeInput) => Effect.Effect<WakeAccepted, ClientError, Service>;
130
145
  export declare const listPendingApprovals: (input: ListPendingApprovalsInput) => Effect.Effect<PendingToolApprovalList, ClientError, Service>;
131
146
  export declare const resolveToolApproval: (input: ResolveToolApprovalInput) => Effect.Effect<WakeAccepted, ClientError, Service>;
132
147
  export declare const resolvePermission: (input: ResolvePermissionInput) => Effect.Effect<WakeAccepted, ClientError, Service>;
148
+ export declare const listPendingToolCalls: (input: ListPendingToolCallsInput) => Effect.Effect<PendingToolCallList, ClientError, Service>;
149
+ export declare const fulfillToolCall: (input: FulfillToolCallInput) => Effect.Effect<ToolOutcomeAccepted, ClientError, Service>;
150
+ export declare const claimToolWork: (input: ClaimToolWorkInput) => Effect.Effect<ToolWorkLease | null, ClientError, Service>;
151
+ export declare const completeToolWork: (input: CompleteToolWorkInput) => Effect.Effect<ToolOutcomeAccepted, ClientError, Service>;
152
+ export declare const releaseToolWork: (input: ReleaseToolWorkInput) => Effect.Effect<ToolWorkReleased, ClientError, Service>;
153
+ export declare const listToolAttempts: (input: ListToolAttemptsInput) => Effect.Effect<ToolAttemptList, ClientError, Service>;
133
154
  export declare const submitInboundEnvelope: (input: SubmitInboundEnvelopeInput) => Effect.Effect<SubmitInboundEnvelopeAccepted, ClientError, Service>;
134
- export declare const spawnChildRun: (input: Execution.SpawnChildRunInput) => Effect.Effect<Execution.ChildRunAccepted, ClientError, Service>;
155
+ export declare const spawnChildRun: (input: SpawnChildRunInput) => Effect.Effect<Execution.ChildRunAccepted, ClientError, Service>;
135
156
  export declare const claimEnvelopeReady: (input: ClaimEnvelopeReadyInput) => Effect.Effect<EnvelopeReadyLease | null, ClientError, Service>;
136
157
  export declare const ackEnvelopeReady: (input: AckEnvelopeReadyInput) => Effect.Effect<EnvelopeReadyAcked, ClientError, Service>;
137
158
  export declare const releaseEnvelopeReady: (input: ReleaseEnvelopeReadyInput) => Effect.Effect<EnvelopeReadyReleased, ClientError, Service>;
@@ -2,6 +2,7 @@ export * as AdapterOutbox from "./adapter-outbox";
2
2
  export * as Client from "./client";
3
3
  export * as Database from "./database";
4
4
  export * as Operation from "./operation";
5
+ export * as ToolWorker from "./tool-worker";
5
6
  export { Address, Agent, Content, Envelope, Execution, Ids, Schedule, Shared, Skill, Tool } from "../schema/index";
6
7
  export { AddressBook, AddressResolution, AgentLoop, AgentRegistry, ActivityVersionRegistry, ArtifactStore, BlobStore, ChildRunService, EnvelopeService, EventLog, ExecutionEntity, ExecutionService, ExecutionWorkflow, LanguageModelService, ModelCallPolicy, PromptAssembler, SchedulerService, SchemaRegistry, SkillRegistry, ToolRuntime, WaitService, } from "../runtime/index";
7
8
  export { RunnerRuntime } from "../runtime/index";