@swirls/looms 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -2
- package/dist/actor/cell.d.ts +9 -4
- package/dist/actor/cell.js +7 -11
- package/dist/actor/host.d.ts +7 -3
- package/dist/actor/host.js +57 -33
- package/dist/actor/index.d.ts +1 -1
- package/dist/actor/index.js +1 -1
- package/dist/actor/routing.d.ts +12 -1
- package/dist/actor/routing.js +57 -51
- package/dist/agent/agent-session.d.ts +5 -0
- package/dist/agent/agent-session.js +270 -0
- package/dist/agent/debugger/agent-chat.d.ts +2 -0
- package/dist/agent/debugger/agent-chat.js +176 -0
- package/dist/agent/debugger/index.d.ts +5 -0
- package/dist/agent/debugger/index.js +19 -0
- package/dist/agent/debugger/summarize.d.ts +2 -0
- package/dist/agent/debugger/summarize.js +51 -0
- package/dist/agent/debugger/token-usage.d.ts +3 -0
- package/dist/agent/debugger/token-usage.js +11 -0
- package/dist/agent/definitions-store.d.ts +2 -3
- package/dist/agent/definitions-store.js +2 -4
- package/dist/agent/definitions.d.ts +47 -29
- package/dist/agent/definitions.js +39 -12
- package/dist/agent/effects.d.ts +359 -2
- package/dist/agent/effects.js +60 -34
- package/dist/agent/events.d.ts +175 -19
- package/dist/agent/events.js +45 -10
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +1 -0
- package/dist/agent/llm.d.ts +11 -2
- package/dist/agent/llm.js +13 -3
- package/dist/agent/module.d.ts +812 -78
- package/dist/agent/module.js +16 -4
- package/dist/agent/scope.d.ts +174 -18
- package/dist/agent/signals.d.ts +26 -1
- package/dist/agent/signals.js +79 -0
- package/dist/agent/threads.d.ts +3 -33
- package/dist/agent/threads.js +20 -25
- package/dist/agent/tool-schema.d.ts +1 -17
- package/dist/agent/tool-schema.js +3 -43
- package/dist/agent/types.d.ts +49 -4
- package/dist/agent/types.js +5 -5
- package/dist/ai-vercel/index.d.ts +1 -0
- package/dist/ai-vercel/index.js +1 -0
- package/dist/ai-vercel/messages.js +22 -7
- package/dist/ai-vercel/vercel-evaluator.d.ts +36 -0
- package/dist/ai-vercel/vercel-evaluator.js +73 -0
- package/dist/ai-vercel/vercel-llm.js +64 -44
- package/dist/approval/debugger/approvals-view.d.ts +3 -0
- package/dist/approval/debugger/approvals-view.js +16 -0
- package/dist/approval/debugger/index.d.ts +4 -0
- package/dist/approval/debugger/index.js +11 -0
- package/dist/approval/debugger/summarize.d.ts +2 -0
- package/dist/approval/debugger/summarize.js +17 -0
- package/dist/approval/effects.d.ts +89 -0
- package/dist/approval/module.d.ts +179 -29
- package/dist/approval/projections.d.ts +0 -14
- package/dist/approval/projections.js +20 -3
- package/dist/approval/signals.d.ts +2 -0
- package/dist/approval/signals.js +18 -2
- package/dist/cli/cli.js +2 -0
- package/dist/cli/commands.js +12 -16
- package/dist/client/client.d.ts +1213 -18
- package/dist/client/client.js +120 -120
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/sse.d.ts +13 -0
- package/dist/client/sse.js +38 -44
- package/dist/cloudflare/alarm-scheduler.d.ts +12 -2
- package/dist/cloudflare/alarm-scheduler.js +34 -7
- package/dist/cloudflare/durable-object.d.ts +10 -2
- package/dist/cloudflare/durable-object.js +59 -28
- package/dist/cloudflare/event-store.d.ts +7 -2
- package/dist/cloudflare/event-store.js +8 -7
- package/dist/cloudflare/index.d.ts +2 -2
- package/dist/cloudflare/index.js +2 -2
- package/dist/cloudflare/router.d.ts +1 -1
- package/dist/cloudflare/router.js +15 -16
- package/dist/core/catalog.d.ts +3 -3
- package/dist/core/catalog.js +2 -5
- package/dist/core/coalesce.js +5 -3
- package/dist/core/compose.d.ts +2 -1
- package/dist/core/compose.js +19 -2
- package/dist/core/debugger-host.d.ts +16 -0
- package/dist/core/debugger-host.js +1 -0
- package/dist/core/definition-store.d.ts +11 -0
- package/dist/core/definition-store.js +6 -0
- package/dist/core/effects.d.ts +127 -15
- package/dist/core/effects.js +89 -17
- package/dist/core/envelope.d.ts +27 -7
- package/dist/core/envelope.js +20 -6
- package/dist/core/event-codec.d.ts +4 -2
- package/dist/core/event-codec.js +10 -5
- package/dist/core/event-index.js +1 -3
- package/dist/core/fold.d.ts +3 -0
- package/dist/core/fold.js +171 -24
- package/dist/core/ids.d.ts +5 -0
- package/dist/core/ids.js +35 -2
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.js +6 -1
- package/dist/core/kind.d.ts +22 -0
- package/dist/core/kind.js +17 -0
- package/dist/core/limits.d.ts +34 -0
- package/dist/core/limits.js +46 -0
- package/dist/core/match.d.ts +1 -0
- package/dist/core/match.js +10 -1
- package/dist/core/module-scope.d.ts +22 -20
- package/dist/core/module-scope.js +38 -28
- package/dist/core/module.d.ts +18 -5
- package/dist/core/module.js +4 -0
- package/dist/core/projection.d.ts +13 -13
- package/dist/core/projection.js +9 -5
- package/dist/core/protocol.d.ts +68 -11
- package/dist/core/protocol.js +82 -11
- package/dist/core/published.d.ts +43 -0
- package/dist/core/published.js +44 -0
- package/dist/core/replay.d.ts +312 -3
- package/dist/core/replay.js +11 -1
- package/dist/core/schema.d.ts +11 -20
- package/dist/core/schema.js +63 -80
- package/dist/core/serialize.js +2 -4
- package/dist/core/snapshot-store.d.ts +6 -1
- package/dist/core/snapshot-store.js +15 -2
- package/dist/core/snapshots.d.ts +5 -1
- package/dist/core/snapshots.js +10 -15
- package/dist/core/sqlite-store.js +95 -11
- package/dist/core/state.d.ts +142 -4
- package/dist/core/state.js +78 -0
- package/dist/core/store.d.ts +38 -3
- package/dist/core/store.js +77 -22
- package/dist/core/thread.d.ts +10 -9
- package/dist/core/types.d.ts +5 -8
- package/dist/core/types.js +28 -24
- package/dist/core/validate-event.js +14 -4
- package/dist/core/worker-callback.d.ts +17 -0
- package/dist/core/worker-callback.js +1 -0
- package/dist/debugger/app/assets/index-B3Ah8WAE.css +2 -0
- package/dist/debugger/app/assets/index-Qb371t_O.js +22 -0
- package/dist/debugger/app/assets/rolldown-runtime-CbXtAM7H.js +1 -0
- package/dist/debugger/app/assets/routes-CjtEHgPQ.js +47 -0
- package/dist/debugger/app/index.html +14 -0
- package/dist/debugger/components/composer.d.ts +17 -0
- package/dist/debugger/components/composer.js +25 -0
- package/dist/debugger/components/debugger-split.d.ts +2 -1
- package/dist/debugger/components/debugger-split.js +2 -2
- package/dist/debugger/components/event-inspector.d.ts +2 -1
- package/dist/debugger/components/event-inspector.js +25 -16
- package/dist/debugger/components/event-stream.d.ts +2 -1
- package/dist/debugger/components/event-stream.js +14 -74
- package/dist/debugger/components/follow-list.d.ts +19 -0
- package/dist/debugger/components/follow-list.js +96 -0
- package/dist/debugger/components/json-tree.d.ts +11 -0
- package/dist/debugger/components/json-tree.js +120 -0
- package/dist/debugger/components/json-view.js +2 -2
- package/dist/debugger/components/run-tree.js +53 -20
- package/dist/debugger/components/status-dot.d.ts +4 -0
- package/dist/debugger/components/status-dot.js +6 -2
- package/dist/debugger/context.d.ts +14 -0
- package/dist/debugger/context.js +17 -0
- package/dist/debugger/contracts.d.ts +7 -4
- package/dist/debugger/events/builtin-families.d.ts +3 -0
- package/dist/debugger/events/builtin-families.js +9 -0
- package/dist/debugger/events/catalog.d.ts +3 -4
- package/dist/debugger/events/catalog.js +27 -17
- package/dist/debugger/events/protocol-summarize.d.ts +1 -2
- package/dist/debugger/events/protocol-summarize.js +42 -24
- package/dist/debugger/index.d.ts +20 -6
- package/dist/debugger/index.js +19 -5
- package/dist/debugger/lib/cn.d.ts +1 -0
- package/dist/debugger/lib/cn.js +3 -0
- package/dist/debugger/lib/event-meta.d.ts +2 -3
- package/dist/debugger/lib/event-meta.js +6 -12
- package/dist/debugger/lib/json.d.ts +25 -0
- package/dist/debugger/lib/json.js +87 -0
- package/dist/debugger/lib/payload.d.ts +7 -0
- package/dist/debugger/lib/payload.js +11 -0
- package/dist/debugger/lib/time.d.ts +3 -0
- package/dist/debugger/lib/time.js +24 -0
- package/dist/debugger/plugin.d.ts +36 -0
- package/dist/debugger/plugin.js +14 -0
- package/dist/debugger/server/index.d.ts +14 -0
- package/dist/debugger/server/index.js +114 -0
- package/dist/debugger/shell/debugger-shell.d.ts +15 -0
- package/dist/debugger/shell/debugger-shell.js +43 -0
- package/dist/debugger/shell/definition-key.d.ts +3 -0
- package/dist/debugger/shell/definition-key.js +4 -0
- package/dist/debugger/shell/events-pane.d.ts +12 -0
- package/dist/debugger/shell/events-pane.js +25 -0
- package/dist/debugger/shell/projections-panel.d.ts +4 -0
- package/dist/debugger/shell/projections-panel.js +59 -0
- package/dist/debugger/shell/run-controls.d.ts +4 -0
- package/dist/debugger/shell/run-controls.js +72 -0
- package/dist/debugger/shell/run-search.d.ts +6 -0
- package/dist/debugger/shell/run-search.js +102 -0
- package/dist/debugger/shell/run-type-menu.d.ts +6 -0
- package/dist/debugger/shell/run-type-menu.js +11 -0
- package/dist/debugger/shell/schema-form.d.ts +31 -0
- package/dist/debugger/shell/schema-form.js +117 -0
- package/dist/debugger/shell/start-form.d.ts +3 -0
- package/dist/debugger/shell/start-form.js +75 -0
- package/dist/debugger/shell/use-start-run.d.ts +14 -0
- package/dist/debugger/shell/use-start-run.js +32 -0
- package/dist/debugger/shell/workspace.d.ts +6 -0
- package/dist/debugger/shell/workspace.js +15 -0
- package/dist/debugger/styles.css +111 -27
- package/dist/debugger/ui/button.d.ts +24 -0
- package/dist/debugger/ui/button.js +24 -0
- package/dist/debugger/ui/command.d.ts +9 -0
- package/dist/debugger/ui/command.js +24 -0
- package/dist/debugger/ui/dropdown-menu.d.ts +13 -0
- package/dist/debugger/ui/dropdown-menu.js +37 -0
- package/dist/debugger/ui/panel.d.ts +14 -0
- package/dist/debugger/ui/panel.js +16 -0
- package/dist/debugger/ui/popover.d.ts +7 -0
- package/dist/debugger/ui/popover.js +17 -0
- package/dist/debugger/ui/resizable.d.ts +7 -0
- package/dist/debugger/ui/resizable.js +14 -0
- package/dist/debugger/ui/scroll-area.d.ts +2 -1
- package/dist/debugger/ui/scroll-area.js +5 -3
- package/dist/debugger/ui/select.d.ts +10 -0
- package/dist/debugger/ui/select.js +21 -0
- package/dist/debugger/ui/tabs.js +2 -2
- package/dist/debugger/ui/textarea.d.ts +3 -0
- package/dist/debugger/ui/textarea.js +7 -0
- package/dist/evaluator/definitions-store.d.ts +11 -0
- package/dist/evaluator/definitions-store.js +8 -0
- package/dist/evaluator/definitions.d.ts +18 -0
- package/dist/evaluator/definitions.js +4 -0
- package/dist/evaluator/effects.d.ts +226 -0
- package/dist/evaluator/effects.js +132 -0
- package/dist/evaluator/evaluator.d.ts +24 -0
- package/dist/evaluator/evaluator.js +67 -0
- package/dist/evaluator/events.d.ts +59 -0
- package/dist/evaluator/events.js +21 -0
- package/dist/evaluator/index.d.ts +11 -0
- package/dist/evaluator/index.js +11 -0
- package/dist/evaluator/module.d.ts +606 -0
- package/dist/evaluator/module.js +25 -0
- package/dist/evaluator/projections.d.ts +50 -0
- package/dist/evaluator/projections.js +20 -0
- package/dist/evaluator/scope.d.ts +59 -0
- package/dist/evaluator/scope.js +7 -0
- package/dist/evaluator/signals.d.ts +3 -0
- package/dist/evaluator/signals.js +17 -0
- package/dist/evaluator/threads.d.ts +62 -0
- package/dist/evaluator/threads.js +117 -0
- package/dist/evaluator/types.d.ts +125 -0
- package/dist/evaluator/types.js +51 -0
- package/dist/projectors/delivery.d.ts +83 -0
- package/dist/projectors/delivery.js +182 -0
- package/dist/projectors/index-model.d.ts +1 -1
- package/dist/projectors/index-model.js +4 -6
- package/dist/projectors/index.d.ts +2 -0
- package/dist/projectors/index.js +2 -0
- package/dist/projectors/memory.d.ts +1 -1
- package/dist/projectors/memory.js +10 -8
- package/dist/projectors/postgres.js +44 -58
- package/dist/projectors/projector.d.ts +17 -0
- package/dist/projectors/projector.js +26 -1
- package/dist/projectors/sqlite-delivery.d.ts +4 -0
- package/dist/projectors/sqlite-delivery.js +147 -0
- package/dist/projectors/sqlite.js +23 -23
- package/dist/projectors/with-projectors.d.ts +7 -2
- package/dist/projectors/with-projectors.js +27 -28
- package/dist/react/notify.js +11 -8
- package/dist/react/react.d.ts +2 -3
- package/dist/react/react.js +14 -30
- package/dist/react/sse.d.ts +1 -1
- package/dist/react/sse.js +1 -1
- package/dist/react/store.d.ts +3 -3
- package/dist/react/store.js +109 -119
- package/dist/runtime/cancellation.d.ts +16 -0
- package/dist/runtime/cancellation.js +129 -0
- package/dist/runtime/deadline-transition-planner.d.ts +31 -0
- package/dist/runtime/deadline-transition-planner.js +139 -0
- package/dist/runtime/dispatch-effect.d.ts +3 -2
- package/dist/runtime/dispatch-effect.js +7 -13
- package/dist/runtime/errors.d.ts +51 -0
- package/dist/runtime/errors.js +39 -0
- package/dist/runtime/{runtime-helpers.d.ts → helpers.d.ts} +24 -4
- package/dist/runtime/{runtime-helpers.js → helpers.js} +56 -19
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.js +3 -3
- package/dist/runtime/ingress.d.ts +15 -0
- package/dist/runtime/ingress.js +42 -0
- package/dist/runtime/local-effect-executor.d.ts +21 -0
- package/dist/runtime/local-effect-executor.js +137 -0
- package/dist/runtime/looms.d.ts +30 -4
- package/dist/runtime/looms.js +57 -37
- package/dist/runtime/observer.d.ts +45 -0
- package/dist/runtime/observer.js +11 -0
- package/dist/runtime/repository.d.ts +55 -0
- package/dist/runtime/repository.js +293 -0
- package/dist/runtime/retry-policy.d.ts +16 -0
- package/dist/runtime/retry-policy.js +29 -0
- package/dist/runtime/run-execution-context.d.ts +30 -0
- package/dist/runtime/run-execution-context.js +56 -0
- package/dist/runtime/run-start.d.ts +4 -0
- package/dist/runtime/run-start.js +44 -0
- package/dist/runtime/runtime.d.ts +6 -87
- package/dist/runtime/runtime.js +248 -470
- package/dist/runtime/server/auth.d.ts +41 -0
- package/dist/runtime/server/auth.js +45 -0
- package/dist/runtime/server/debugger-host.d.ts +11 -0
- package/dist/runtime/server/debugger-host.js +32 -0
- package/dist/runtime/server/fetch-handler.d.ts +18 -0
- package/dist/runtime/server/fetch-handler.js +62 -0
- package/dist/runtime/server/http.d.ts +38 -0
- package/dist/runtime/server/http.js +66 -0
- package/dist/runtime/server/route-table.d.ts +55 -0
- package/dist/runtime/server/route-table.js +74 -0
- package/dist/runtime/server/routes/definitions.d.ts +3 -0
- package/dist/runtime/server/routes/definitions.js +20 -0
- package/dist/runtime/server/routes/effects.d.ts +3 -0
- package/dist/runtime/server/routes/effects.js +59 -0
- package/dist/runtime/server/routes/operations.d.ts +3 -0
- package/dist/runtime/server/routes/operations.js +14 -0
- package/dist/runtime/server/routes/runs.d.ts +3 -0
- package/dist/runtime/server/routes/runs.js +199 -0
- package/dist/runtime/server.d.ts +4 -8
- package/dist/runtime/server.js +6 -211
- package/dist/runtime/sse.d.ts +2 -1
- package/dist/runtime/sse.js +24 -17
- package/dist/runtime/types.d.ts +117 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/wake-engine.d.ts +20 -0
- package/dist/runtime/wake-engine.js +311 -0
- package/dist/runtime/wake-scheduler.d.ts +3 -4
- package/dist/runtime/wake-scheduler.js +25 -31
- package/dist/runtime/worker-callbacks.d.ts +16 -0
- package/dist/runtime/worker-callbacks.js +167 -0
- package/dist/runtime/worker-effect-dispatch.d.ts +36 -0
- package/dist/runtime/worker-effect-dispatch.js +126 -0
- package/dist/s2/config.d.ts +1 -1
- package/dist/s2/config.js +1 -1
- package/dist/s2/lite.js +70 -82
- package/dist/s2/pagination.d.ts +15 -0
- package/dist/s2/pagination.js +36 -0
- package/dist/s2/projector.js +6 -5
- package/dist/s2/snapshot-store.js +188 -161
- package/dist/s2/store.d.ts +3 -21
- package/dist/s2/store.js +71 -165
- package/dist/testing/index.d.ts +15 -0
- package/dist/testing/index.js +53 -16
- package/dist/workflow/debugger/index.d.ts +4 -0
- package/dist/workflow/debugger/index.js +11 -0
- package/dist/workflow/debugger/nodes-view.d.ts +3 -0
- package/dist/workflow/debugger/nodes-view.js +13 -0
- package/dist/workflow/debugger/summarize.d.ts +2 -0
- package/dist/workflow/debugger/summarize.js +30 -0
- package/dist/workflow/definitions-store.d.ts +2 -3
- package/dist/workflow/definitions-store.js +2 -2
- package/dist/workflow/definitions.d.ts +78 -22
- package/dist/workflow/definitions.js +80 -14
- package/dist/workflow/effects.d.ts +453 -107
- package/dist/workflow/effects.js +214 -115
- package/dist/workflow/events.d.ts +149 -5
- package/dist/workflow/events.js +27 -5
- package/dist/workflow/graph.d.ts +56 -0
- package/dist/workflow/graph.js +207 -0
- package/dist/workflow/index.d.ts +1 -0
- package/dist/workflow/index.js +1 -0
- package/dist/workflow/module.d.ts +1047 -266
- package/dist/workflow/projections.d.ts +14 -12
- package/dist/workflow/projections.js +30 -8
- package/dist/workflow/scope.d.ts +146 -4
- package/dist/workflow/threads.d.ts +383 -155
- package/dist/workflow/threads.js +308 -110
- package/package.json +26 -2
- package/dist/debugger/events/domain-summarize.d.ts +0 -3
- package/dist/debugger/events/domain-summarize.js +0 -107
- package/dist/debugger/events/family.d.ts +0 -8
- package/dist/debugger/events/family.js +0 -44
- package/dist/runtime/events-api.d.ts +0 -4
- package/dist/runtime/events-api.js +0 -84
package/dist/agent/effects.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Effect, Predicate, Schema } from 'effect';
|
|
2
|
-
import { createThreadId,
|
|
1
|
+
import { Data, Effect, Predicate, Schema } from 'effect';
|
|
2
|
+
import { createThreadId, DEFAULT_DEFINITION_VERSION, validateInputEffect, } from '@swirls/looms/core';
|
|
3
3
|
import { normalizeTools } from './definitions.js';
|
|
4
4
|
import { AgentDefinitionsTag } from './definitions-store.js';
|
|
5
5
|
import { LlmTag } from './llm.js';
|
|
@@ -7,16 +7,29 @@ import { agentModule } from './scope.js';
|
|
|
7
7
|
import { toolSpecs } from './tool-schema.js';
|
|
8
8
|
import { MessageSchema, ToolCallSchema } from './types.js';
|
|
9
9
|
const CallLlmInput = Schema.Struct({
|
|
10
|
-
turn: Schema.
|
|
10
|
+
turn: Schema.Finite,
|
|
11
11
|
definitionName: Schema.optional(Schema.String),
|
|
12
|
+
definitionVersion: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(DEFAULT_DEFINITION_VERSION))),
|
|
12
13
|
messages: Schema.optional(Schema.Array(MessageSchema)),
|
|
13
14
|
input: Schema.optional(Schema.Json),
|
|
15
|
+
consumedSteerMessageIds: Schema.optional(Schema.Array(Schema.String)),
|
|
14
16
|
});
|
|
15
17
|
const ExecuteToolInput = Schema.Struct({
|
|
16
|
-
turn: Schema.
|
|
18
|
+
turn: Schema.Finite,
|
|
17
19
|
definitionName: Schema.optional(Schema.String),
|
|
20
|
+
definitionVersion: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(DEFAULT_DEFINITION_VERSION))),
|
|
18
21
|
toolCall: ToolCallSchema,
|
|
19
22
|
});
|
|
23
|
+
class AgentExecutionError extends Data.TaggedError('AgentExecutionError') {
|
|
24
|
+
constructor(operation, cause) {
|
|
25
|
+
super({
|
|
26
|
+
operation,
|
|
27
|
+
cause,
|
|
28
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
29
|
+
});
|
|
30
|
+
this.name = 'AgentExecutionError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
20
33
|
function findTool(tools, name) {
|
|
21
34
|
return tools.find((tool) => tool.name === name);
|
|
22
35
|
}
|
|
@@ -26,20 +39,22 @@ export const callLlmEffect = agentModule.effect({
|
|
|
26
39
|
execute: (input, ctx) => runCallLlm({
|
|
27
40
|
turn: input.turn,
|
|
28
41
|
definitionName: input.definitionName,
|
|
29
|
-
|
|
30
|
-
messages: input.messages ?? [],
|
|
42
|
+
definitionVersion: input.definitionVersion,
|
|
43
|
+
messages: [...(input.messages ?? [])],
|
|
31
44
|
input: input.input ?? null,
|
|
45
|
+
consumedSteerMessageIds: [...(input.consumedSteerMessageIds ?? [])],
|
|
32
46
|
runId: ctx.runId,
|
|
33
47
|
threadId: ctx.threadId,
|
|
48
|
+
signal: ctx.signal,
|
|
34
49
|
emit: (event) => ctx.emit(event),
|
|
35
50
|
}),
|
|
36
51
|
});
|
|
37
52
|
function runCallLlm(args) {
|
|
38
53
|
return Effect.gen(function* () {
|
|
39
|
-
const { turn, threadId, emit, definitionName, messages, input } = args;
|
|
54
|
+
const { turn, threadId, emit, definitionName, definitionVersion, messages, input, consumedSteerMessageIds, signal, } = args;
|
|
40
55
|
const agents = yield* AgentDefinitionsTag;
|
|
41
56
|
const llm = yield* LlmTag;
|
|
42
|
-
const definition = definitionName ? agents.get(definitionName) : undefined;
|
|
57
|
+
const definition = definitionName ? agents.get(definitionName, definitionVersion) : undefined;
|
|
43
58
|
if (!definition) {
|
|
44
59
|
return [
|
|
45
60
|
{
|
|
@@ -73,11 +88,12 @@ function runCallLlm(args) {
|
|
|
73
88
|
input,
|
|
74
89
|
tools,
|
|
75
90
|
instructions: definition.instructions,
|
|
91
|
+
signal,
|
|
76
92
|
};
|
|
77
93
|
const result = definition.runTurn
|
|
78
94
|
? yield* Effect.tryPromise({
|
|
79
95
|
try: () => Promise.resolve(definition.runTurn(turnCtx)),
|
|
80
|
-
catch: (cause) => (
|
|
96
|
+
catch: (cause) => new AgentExecutionError('run agent turn', cause),
|
|
81
97
|
})
|
|
82
98
|
: yield* llm.complete({
|
|
83
99
|
model: definition.model,
|
|
@@ -85,14 +101,13 @@ function runCallLlm(args) {
|
|
|
85
101
|
messages: [{ role: 'system', content: definition.instructions }, ...turnCtx.messages],
|
|
86
102
|
tools,
|
|
87
103
|
toolSpecs: toolSpecs(tools),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
104
|
+
signal,
|
|
105
|
+
onTextDelta: (delta) => emit({
|
|
106
|
+
type: 'agent.turn.text_delta',
|
|
107
|
+
payload: { turn, delta },
|
|
108
|
+
threadId,
|
|
109
|
+
ephemeral: true,
|
|
110
|
+
}),
|
|
96
111
|
});
|
|
97
112
|
const toolCalls = result.toolCalls ?? result.message.toolCalls ?? [];
|
|
98
113
|
const shouldStop = definition.stopWhen?.({
|
|
@@ -113,9 +128,13 @@ function runCallLlm(args) {
|
|
|
113
128
|
});
|
|
114
129
|
if (shouldStop) {
|
|
115
130
|
if (!definition.conversational) {
|
|
131
|
+
const output = result.output ?? { text: result.message.content };
|
|
116
132
|
events.push({
|
|
117
133
|
type: 'runtime.thread.completed',
|
|
118
|
-
payload: {
|
|
134
|
+
payload: {
|
|
135
|
+
threadId,
|
|
136
|
+
output: consumedSteerMessageIds.length === 0 ? output : { output, consumedSteerMessageIds },
|
|
137
|
+
},
|
|
119
138
|
threadId,
|
|
120
139
|
});
|
|
121
140
|
}
|
|
@@ -129,11 +148,12 @@ function runCallLlm(args) {
|
|
|
129
148
|
});
|
|
130
149
|
}
|
|
131
150
|
if (toolCalls.length === 0 && !definition.conversational) {
|
|
151
|
+
const output = result.output ?? { text: result.message.content };
|
|
132
152
|
events.push({
|
|
133
153
|
type: 'runtime.thread.completed',
|
|
134
154
|
payload: {
|
|
135
155
|
threadId,
|
|
136
|
-
output:
|
|
156
|
+
output: consumedSteerMessageIds.length === 0 ? output : { output, consumedSteerMessageIds },
|
|
137
157
|
},
|
|
138
158
|
threadId,
|
|
139
159
|
});
|
|
@@ -147,7 +167,9 @@ export const executeToolEffect = agentModule.effect({
|
|
|
147
167
|
execute: (input, ctx) => Effect.gen(function* () {
|
|
148
168
|
const threadId = ctx.threadId;
|
|
149
169
|
const agents = yield* AgentDefinitionsTag;
|
|
150
|
-
const definition = input.definitionName
|
|
170
|
+
const definition = input.definitionName
|
|
171
|
+
? agents.get(input.definitionName, input.definitionVersion)
|
|
172
|
+
: undefined;
|
|
151
173
|
if (!definition) {
|
|
152
174
|
return [
|
|
153
175
|
{
|
|
@@ -182,10 +204,10 @@ export const executeToolEffect = agentModule.effect({
|
|
|
182
204
|
}
|
|
183
205
|
switch (tool.kind) {
|
|
184
206
|
case 'function': {
|
|
185
|
-
const validated = yield* Effect.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
})
|
|
207
|
+
const validated = yield* validateInputEffect(tool.input, input.toolCall.arguments).pipe(Effect.match({
|
|
208
|
+
onFailure: (error) => ({ ok: false, error: error.message }),
|
|
209
|
+
onSuccess: (value) => ({ ok: true, value }),
|
|
210
|
+
}));
|
|
189
211
|
if (!validated.ok) {
|
|
190
212
|
return [
|
|
191
213
|
{
|
|
@@ -206,8 +228,11 @@ export const executeToolEffect = agentModule.effect({
|
|
|
206
228
|
threadId,
|
|
207
229
|
turn: input.turn,
|
|
208
230
|
})),
|
|
209
|
-
catch: (cause) => (
|
|
210
|
-
}).pipe(Effect.
|
|
231
|
+
catch: (cause) => new AgentExecutionError(`run tool ${tool.name}`, cause),
|
|
232
|
+
}).pipe(Effect.match({
|
|
233
|
+
onFailure: (error) => ({ ok: false, error: error.message }),
|
|
234
|
+
onSuccess: (value) => ({ ok: true, value }),
|
|
235
|
+
}));
|
|
211
236
|
return [
|
|
212
237
|
{
|
|
213
238
|
type: 'agent.tool.result',
|
|
@@ -224,10 +249,10 @@ export const executeToolEffect = agentModule.effect({
|
|
|
224
249
|
}
|
|
225
250
|
case 'thread': {
|
|
226
251
|
const validated = tool.input
|
|
227
|
-
? yield* Effect.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
})
|
|
252
|
+
? yield* validateInputEffect(tool.input, input.toolCall.arguments).pipe(Effect.match({
|
|
253
|
+
onFailure: (error) => ({ ok: false, error: error.message }),
|
|
254
|
+
onSuccess: (value) => ({ ok: true, value }),
|
|
255
|
+
}))
|
|
231
256
|
: { ok: true, value: input.toolCall.arguments };
|
|
232
257
|
if (!validated.ok) {
|
|
233
258
|
return [
|
|
@@ -253,6 +278,7 @@ export const executeToolEffect = agentModule.effect({
|
|
|
253
278
|
childThreadId,
|
|
254
279
|
kind: tool.childKind,
|
|
255
280
|
definitionName: tool.childName,
|
|
281
|
+
definitionVersion: tool.childVersion,
|
|
256
282
|
input: childInput,
|
|
257
283
|
toolCallId: input.toolCall.id,
|
|
258
284
|
},
|
|
@@ -262,10 +288,10 @@ export const executeToolEffect = agentModule.effect({
|
|
|
262
288
|
}
|
|
263
289
|
case 'effects': {
|
|
264
290
|
const validated = tool.input
|
|
265
|
-
? yield* Effect.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
})
|
|
291
|
+
? yield* validateInputEffect(tool.input, input.toolCall.arguments).pipe(Effect.match({
|
|
292
|
+
onFailure: (error) => ({ ok: false, error: error.message }),
|
|
293
|
+
onSuccess: (value) => ({ ok: true, value }),
|
|
294
|
+
}))
|
|
269
295
|
: { ok: true, value: input.toolCall.arguments };
|
|
270
296
|
if (!validated.ok) {
|
|
271
297
|
return [
|
package/dist/agent/events.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
-
import { type RuntimeEffect } from '@swirls/looms/core';
|
|
3
2
|
export declare const AgentMessageReceivedPayloadSchema: Schema.Struct<{
|
|
4
3
|
readonly message: Schema.Struct<{
|
|
5
4
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
@@ -14,14 +13,14 @@ export declare const AgentMessageReceivedPayloadSchema: Schema.Struct<{
|
|
|
14
13
|
}>;
|
|
15
14
|
}>;
|
|
16
15
|
export declare const AgentTurnStartedPayloadSchema: Schema.Struct<{
|
|
17
|
-
readonly turn: Schema.
|
|
16
|
+
readonly turn: Schema.Finite;
|
|
18
17
|
}>;
|
|
19
18
|
export declare const AgentTurnTextDeltaPayloadSchema: Schema.Struct<{
|
|
20
|
-
readonly turn: Schema.
|
|
19
|
+
readonly turn: Schema.Finite;
|
|
21
20
|
readonly delta: Schema.String;
|
|
22
21
|
}>;
|
|
23
22
|
export declare const AgentMessageEventPayloadSchema: Schema.Struct<{
|
|
24
|
-
readonly turn: Schema.
|
|
23
|
+
readonly turn: Schema.Finite;
|
|
25
24
|
readonly message: Schema.Struct<{
|
|
26
25
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
27
26
|
readonly content: Schema.String;
|
|
@@ -34,12 +33,12 @@ export declare const AgentMessageEventPayloadSchema: Schema.Struct<{
|
|
|
34
33
|
}>>>>;
|
|
35
34
|
}>;
|
|
36
35
|
readonly usage: Schema.optional<Schema.Struct<{
|
|
37
|
-
readonly input: Schema.
|
|
38
|
-
readonly output: Schema.
|
|
36
|
+
readonly input: Schema.Finite;
|
|
37
|
+
readonly output: Schema.Finite;
|
|
39
38
|
}>>;
|
|
40
39
|
}>;
|
|
41
40
|
export declare const AgentToolCallRequestedPayloadSchema: Schema.Struct<{
|
|
42
|
-
readonly turn: Schema.
|
|
41
|
+
readonly turn: Schema.Finite;
|
|
43
42
|
readonly toolCall: Schema.Struct<{
|
|
44
43
|
readonly id: Schema.String;
|
|
45
44
|
readonly name: Schema.String;
|
|
@@ -47,14 +46,15 @@ export declare const AgentToolCallRequestedPayloadSchema: Schema.Struct<{
|
|
|
47
46
|
}>;
|
|
48
47
|
}>;
|
|
49
48
|
export declare const AgentToolResultPayloadSchema: Schema.Struct<{
|
|
50
|
-
readonly turn: Schema.
|
|
49
|
+
readonly turn: Schema.Finite;
|
|
51
50
|
readonly toolCallId: Schema.String;
|
|
52
51
|
readonly name: Schema.String;
|
|
53
52
|
readonly result: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
54
53
|
readonly error: Schema.NullOr<Schema.String>;
|
|
55
54
|
}>;
|
|
56
55
|
export declare const AgentSteeredPayloadSchema: Schema.Struct<{
|
|
57
|
-
readonly turn: Schema.
|
|
56
|
+
readonly turn: Schema.Finite;
|
|
57
|
+
readonly messageId: Schema.optional<Schema.String>;
|
|
58
58
|
readonly message: Schema.Struct<{
|
|
59
59
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
60
60
|
readonly content: Schema.String;
|
|
@@ -68,16 +68,94 @@ export declare const AgentSteeredPayloadSchema: Schema.Struct<{
|
|
|
68
68
|
}>;
|
|
69
69
|
readonly interrupt: Schema.optional<Schema.Boolean>;
|
|
70
70
|
}>;
|
|
71
|
+
export declare const AgentSessionDeliverySchema: Schema.Union<readonly [Schema.Literal<"steer">, Schema.Literal<"followUp">, Schema.Literal<"nextTurn">]>;
|
|
72
|
+
export declare const AgentSessionMessageSubmittedPayloadSchema: Schema.Struct<{
|
|
73
|
+
readonly messageId: Schema.String;
|
|
74
|
+
readonly text: Schema.String;
|
|
75
|
+
readonly delivery: Schema.optional<Schema.Union<readonly [Schema.Literal<"steer">, Schema.Literal<"followUp">, Schema.Literal<"nextTurn">]>>;
|
|
76
|
+
readonly activeChildThreadId: Schema.optional<Schema.String>;
|
|
77
|
+
}>;
|
|
78
|
+
export declare const AgentSessionSteerDeliveredPayloadSchema: Schema.Struct<{
|
|
79
|
+
readonly messageId: Schema.String;
|
|
80
|
+
readonly activeMessageId: Schema.String;
|
|
81
|
+
}>;
|
|
82
|
+
export declare const AgentSessionTurnStartedPayloadSchema: Schema.Struct<{
|
|
83
|
+
readonly messageId: Schema.String;
|
|
84
|
+
readonly childThreadId: Schema.String;
|
|
85
|
+
}>;
|
|
86
|
+
export declare const AgentSessionTurnClosedPayloadSchema: Schema.Struct<{
|
|
87
|
+
readonly messageId: Schema.String;
|
|
88
|
+
readonly status: Schema.Union<readonly [Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"cancelled">]>;
|
|
89
|
+
readonly error: Schema.optional<Schema.String>;
|
|
90
|
+
}>;
|
|
91
|
+
export declare const AgentSessionCancelRequestedPayloadSchema: Schema.Struct<{}>;
|
|
71
92
|
export declare const AgentSpawnRequestedPayloadSchema: Schema.Struct<{
|
|
72
93
|
readonly childThreadId: Schema.String;
|
|
73
94
|
readonly kind: Schema.String;
|
|
74
95
|
readonly definitionName: Schema.String;
|
|
96
|
+
readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
75
97
|
readonly toolCallId: Schema.String;
|
|
76
98
|
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
77
99
|
}>;
|
|
78
100
|
export declare const AgentEffectsRequestedPayloadSchema: Schema.Struct<{
|
|
79
101
|
readonly toolCallId: Schema.String;
|
|
80
|
-
readonly effects: Schema.$Array<Schema.Schema<
|
|
102
|
+
readonly effects: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
103
|
+
readonly type: Schema.Literal<"runtime.spawn">;
|
|
104
|
+
readonly childThreadId: Schema.String;
|
|
105
|
+
readonly kind: Schema.String;
|
|
106
|
+
readonly definitionName: Schema.String;
|
|
107
|
+
readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
108
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
109
|
+
}>, Schema.Struct<{
|
|
110
|
+
readonly type: Schema.Literal<"runtime.wait">;
|
|
111
|
+
readonly waitId: Schema.String;
|
|
112
|
+
readonly on: Schema.Union<readonly [Schema.Struct<{
|
|
113
|
+
readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
|
|
114
|
+
readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
115
|
+
}>, Schema.Struct<{
|
|
116
|
+
readonly timerAt: Schema.Finite;
|
|
117
|
+
}>]>;
|
|
118
|
+
readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
119
|
+
}>, Schema.Struct<{
|
|
120
|
+
readonly type: Schema.Literal<"runtime.emit">;
|
|
121
|
+
readonly event: Schema.Struct<{
|
|
122
|
+
readonly type: Schema.String;
|
|
123
|
+
readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
124
|
+
readonly threadId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
125
|
+
readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
126
|
+
readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
127
|
+
readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
128
|
+
readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
129
|
+
readonly origin: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
130
|
+
readonly type: Schema.Literal<"thread">;
|
|
131
|
+
readonly threadId: Schema.String;
|
|
132
|
+
}>, Schema.Struct<{
|
|
133
|
+
readonly type: Schema.Literal<"external">;
|
|
134
|
+
readonly actorId: Schema.optional<Schema.String>;
|
|
135
|
+
}>, Schema.Struct<{
|
|
136
|
+
readonly type: Schema.Literal<"system">;
|
|
137
|
+
}>]>>;
|
|
138
|
+
readonly ephemeral: Schema.optional<Schema.Boolean>;
|
|
139
|
+
readonly id: Schema.optional<Schema.String>;
|
|
140
|
+
readonly ts: Schema.optional<Schema.Finite>;
|
|
141
|
+
readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
142
|
+
}>;
|
|
143
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
144
|
+
}>, Schema.Struct<{
|
|
145
|
+
readonly type: Schema.Literal<"runtime.complete">;
|
|
146
|
+
readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
147
|
+
}>, Schema.Struct<{
|
|
148
|
+
readonly type: Schema.Literal<"runtime.fail">;
|
|
149
|
+
readonly error: Schema.String;
|
|
150
|
+
}>, Schema.Struct<{
|
|
151
|
+
readonly type: Schema.Literal<"runtime.cancel">;
|
|
152
|
+
readonly threadId: Schema.String;
|
|
153
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
154
|
+
}>, Schema.Struct<{
|
|
155
|
+
readonly type: Schema.String;
|
|
156
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
157
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
158
|
+
}>]>>;
|
|
81
159
|
readonly waitOn: Schema.optional<Schema.Struct<{
|
|
82
160
|
readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
|
|
83
161
|
readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
@@ -98,14 +176,14 @@ export declare const agentCatalog: import("@swirls/looms/core").EventCatalog<"ag
|
|
|
98
176
|
}>;
|
|
99
177
|
}>;
|
|
100
178
|
'turn.started': Schema.Struct<{
|
|
101
|
-
readonly turn: Schema.
|
|
179
|
+
readonly turn: Schema.Finite;
|
|
102
180
|
}>;
|
|
103
181
|
'turn.text_delta': Schema.Struct<{
|
|
104
|
-
readonly turn: Schema.
|
|
182
|
+
readonly turn: Schema.Finite;
|
|
105
183
|
readonly delta: Schema.String;
|
|
106
184
|
}>;
|
|
107
185
|
message: Schema.Struct<{
|
|
108
|
-
readonly turn: Schema.
|
|
186
|
+
readonly turn: Schema.Finite;
|
|
109
187
|
readonly message: Schema.Struct<{
|
|
110
188
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
111
189
|
readonly content: Schema.String;
|
|
@@ -118,12 +196,12 @@ export declare const agentCatalog: import("@swirls/looms/core").EventCatalog<"ag
|
|
|
118
196
|
}>>>>;
|
|
119
197
|
}>;
|
|
120
198
|
readonly usage: Schema.optional<Schema.Struct<{
|
|
121
|
-
readonly input: Schema.
|
|
122
|
-
readonly output: Schema.
|
|
199
|
+
readonly input: Schema.Finite;
|
|
200
|
+
readonly output: Schema.Finite;
|
|
123
201
|
}>>;
|
|
124
202
|
}>;
|
|
125
203
|
'tool_call.requested': Schema.Struct<{
|
|
126
|
-
readonly turn: Schema.
|
|
204
|
+
readonly turn: Schema.Finite;
|
|
127
205
|
readonly toolCall: Schema.Struct<{
|
|
128
206
|
readonly id: Schema.String;
|
|
129
207
|
readonly name: Schema.String;
|
|
@@ -131,14 +209,15 @@ export declare const agentCatalog: import("@swirls/looms/core").EventCatalog<"ag
|
|
|
131
209
|
}>;
|
|
132
210
|
}>;
|
|
133
211
|
'tool.result': Schema.Struct<{
|
|
134
|
-
readonly turn: Schema.
|
|
212
|
+
readonly turn: Schema.Finite;
|
|
135
213
|
readonly toolCallId: Schema.String;
|
|
136
214
|
readonly name: Schema.String;
|
|
137
215
|
readonly result: Schema.NullOr<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
138
216
|
readonly error: Schema.NullOr<Schema.String>;
|
|
139
217
|
}>;
|
|
140
218
|
steered: Schema.Struct<{
|
|
141
|
-
readonly turn: Schema.
|
|
219
|
+
readonly turn: Schema.Finite;
|
|
220
|
+
readonly messageId: Schema.optional<Schema.String>;
|
|
142
221
|
readonly message: Schema.Struct<{
|
|
143
222
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
144
223
|
readonly content: Schema.String;
|
|
@@ -152,16 +231,93 @@ export declare const agentCatalog: import("@swirls/looms/core").EventCatalog<"ag
|
|
|
152
231
|
}>;
|
|
153
232
|
readonly interrupt: Schema.optional<Schema.Boolean>;
|
|
154
233
|
}>;
|
|
234
|
+
'session.message.submitted': Schema.Struct<{
|
|
235
|
+
readonly messageId: Schema.String;
|
|
236
|
+
readonly text: Schema.String;
|
|
237
|
+
readonly delivery: Schema.optional<Schema.Union<readonly [Schema.Literal<"steer">, Schema.Literal<"followUp">, Schema.Literal<"nextTurn">]>>;
|
|
238
|
+
readonly activeChildThreadId: Schema.optional<Schema.String>;
|
|
239
|
+
}>;
|
|
240
|
+
'session.steer.delivered': Schema.Struct<{
|
|
241
|
+
readonly messageId: Schema.String;
|
|
242
|
+
readonly activeMessageId: Schema.String;
|
|
243
|
+
}>;
|
|
244
|
+
'session.turn.started': Schema.Struct<{
|
|
245
|
+
readonly messageId: Schema.String;
|
|
246
|
+
readonly childThreadId: Schema.String;
|
|
247
|
+
}>;
|
|
248
|
+
'session.turn.closed': Schema.Struct<{
|
|
249
|
+
readonly messageId: Schema.String;
|
|
250
|
+
readonly status: Schema.Union<readonly [Schema.Literal<"completed">, Schema.Literal<"failed">, Schema.Literal<"cancelled">]>;
|
|
251
|
+
readonly error: Schema.optional<Schema.String>;
|
|
252
|
+
}>;
|
|
253
|
+
'session.cancel.requested': Schema.Struct<{}>;
|
|
155
254
|
'spawn.requested': Schema.Struct<{
|
|
156
255
|
readonly childThreadId: Schema.String;
|
|
157
256
|
readonly kind: Schema.String;
|
|
158
257
|
readonly definitionName: Schema.String;
|
|
258
|
+
readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
159
259
|
readonly toolCallId: Schema.String;
|
|
160
260
|
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
161
261
|
}>;
|
|
162
262
|
'effects.requested': Schema.Struct<{
|
|
163
263
|
readonly toolCallId: Schema.String;
|
|
164
|
-
readonly effects: Schema.$Array<Schema.Schema<
|
|
264
|
+
readonly effects: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
265
|
+
readonly type: Schema.Literal<"runtime.spawn">;
|
|
266
|
+
readonly childThreadId: Schema.String;
|
|
267
|
+
readonly kind: Schema.String;
|
|
268
|
+
readonly definitionName: Schema.String;
|
|
269
|
+
readonly definitionVersion: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
270
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
271
|
+
}>, Schema.Struct<{
|
|
272
|
+
readonly type: Schema.Literal<"runtime.wait">;
|
|
273
|
+
readonly waitId: Schema.String;
|
|
274
|
+
readonly on: Schema.Union<readonly [Schema.Struct<{
|
|
275
|
+
readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
|
|
276
|
+
readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
277
|
+
}>, Schema.Struct<{
|
|
278
|
+
readonly timerAt: Schema.Finite;
|
|
279
|
+
}>]>;
|
|
280
|
+
readonly tag: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
281
|
+
}>, Schema.Struct<{
|
|
282
|
+
readonly type: Schema.Literal<"runtime.emit">;
|
|
283
|
+
readonly event: Schema.Struct<{
|
|
284
|
+
readonly type: Schema.String;
|
|
285
|
+
readonly payload: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
286
|
+
readonly threadId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
287
|
+
readonly parentThreadId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
288
|
+
readonly causationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
289
|
+
readonly correlationId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
290
|
+
readonly effectId: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
291
|
+
readonly origin: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
292
|
+
readonly type: Schema.Literal<"thread">;
|
|
293
|
+
readonly threadId: Schema.String;
|
|
294
|
+
}>, Schema.Struct<{
|
|
295
|
+
readonly type: Schema.Literal<"external">;
|
|
296
|
+
readonly actorId: Schema.optional<Schema.String>;
|
|
297
|
+
}>, Schema.Struct<{
|
|
298
|
+
readonly type: Schema.Literal<"system">;
|
|
299
|
+
}>]>>;
|
|
300
|
+
readonly ephemeral: Schema.optional<Schema.Boolean>;
|
|
301
|
+
readonly id: Schema.optional<Schema.String>;
|
|
302
|
+
readonly ts: Schema.optional<Schema.Finite>;
|
|
303
|
+
readonly idempotencyKey: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
304
|
+
}>;
|
|
305
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
306
|
+
}>, Schema.Struct<{
|
|
307
|
+
readonly type: Schema.Literal<"runtime.complete">;
|
|
308
|
+
readonly output: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
309
|
+
}>, Schema.Struct<{
|
|
310
|
+
readonly type: Schema.Literal<"runtime.fail">;
|
|
311
|
+
readonly error: Schema.String;
|
|
312
|
+
}>, Schema.Struct<{
|
|
313
|
+
readonly type: Schema.Literal<"runtime.cancel">;
|
|
314
|
+
readonly threadId: Schema.String;
|
|
315
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
316
|
+
}>, Schema.Struct<{
|
|
317
|
+
readonly type: Schema.String;
|
|
318
|
+
readonly input: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
319
|
+
readonly tag: Schema.optional<Schema.String>;
|
|
320
|
+
}>]>>;
|
|
165
321
|
readonly waitOn: Schema.optional<Schema.Struct<{
|
|
166
322
|
readonly type: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.String>]>;
|
|
167
323
|
readonly match: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
package/dist/agent/events.js
CHANGED
|
@@ -1,48 +1,78 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
import { defineEventCatalog } from '@swirls/looms/core';
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import { DEFAULT_DEFINITION_VERSION, defineEventCatalog, RuntimeEffectSchema } from '@swirls/looms/core';
|
|
3
3
|
import { MessageSchema, TokenUsageSchema, ToolCallSchema } from './types.js';
|
|
4
4
|
export const AgentMessageReceivedPayloadSchema = Schema.Struct({
|
|
5
5
|
message: MessageSchema,
|
|
6
6
|
});
|
|
7
7
|
export const AgentTurnStartedPayloadSchema = Schema.Struct({
|
|
8
|
-
turn: Schema.
|
|
8
|
+
turn: Schema.Finite,
|
|
9
9
|
});
|
|
10
10
|
export const AgentTurnTextDeltaPayloadSchema = Schema.Struct({
|
|
11
|
-
turn: Schema.
|
|
11
|
+
turn: Schema.Finite,
|
|
12
12
|
delta: Schema.String,
|
|
13
13
|
});
|
|
14
14
|
export const AgentMessageEventPayloadSchema = Schema.Struct({
|
|
15
|
-
turn: Schema.
|
|
15
|
+
turn: Schema.Finite,
|
|
16
16
|
message: MessageSchema,
|
|
17
17
|
usage: Schema.optional(TokenUsageSchema),
|
|
18
18
|
});
|
|
19
19
|
export const AgentToolCallRequestedPayloadSchema = Schema.Struct({
|
|
20
|
-
turn: Schema.
|
|
20
|
+
turn: Schema.Finite,
|
|
21
21
|
toolCall: ToolCallSchema,
|
|
22
22
|
});
|
|
23
23
|
export const AgentToolResultPayloadSchema = Schema.Struct({
|
|
24
|
-
turn: Schema.
|
|
24
|
+
turn: Schema.Finite,
|
|
25
25
|
toolCallId: Schema.String,
|
|
26
26
|
name: Schema.String,
|
|
27
27
|
result: Schema.NullOr(Schema.Json),
|
|
28
28
|
error: Schema.NullOr(Schema.String),
|
|
29
29
|
});
|
|
30
30
|
export const AgentSteeredPayloadSchema = Schema.Struct({
|
|
31
|
-
turn: Schema.
|
|
31
|
+
turn: Schema.Finite,
|
|
32
|
+
messageId: Schema.optional(Schema.String),
|
|
32
33
|
message: MessageSchema,
|
|
33
34
|
interrupt: Schema.optional(Schema.Boolean),
|
|
34
35
|
});
|
|
36
|
+
export const AgentSessionDeliverySchema = Schema.Union([
|
|
37
|
+
Schema.Literal('steer'),
|
|
38
|
+
Schema.Literal('followUp'),
|
|
39
|
+
Schema.Literal('nextTurn'),
|
|
40
|
+
]);
|
|
41
|
+
export const AgentSessionMessageSubmittedPayloadSchema = Schema.Struct({
|
|
42
|
+
messageId: Schema.String,
|
|
43
|
+
text: Schema.String,
|
|
44
|
+
delivery: Schema.optional(AgentSessionDeliverySchema),
|
|
45
|
+
activeChildThreadId: Schema.optional(Schema.String),
|
|
46
|
+
});
|
|
47
|
+
export const AgentSessionSteerDeliveredPayloadSchema = Schema.Struct({
|
|
48
|
+
messageId: Schema.String,
|
|
49
|
+
activeMessageId: Schema.String,
|
|
50
|
+
});
|
|
51
|
+
export const AgentSessionTurnStartedPayloadSchema = Schema.Struct({
|
|
52
|
+
messageId: Schema.String,
|
|
53
|
+
childThreadId: Schema.String,
|
|
54
|
+
});
|
|
55
|
+
export const AgentSessionTurnClosedPayloadSchema = Schema.Struct({
|
|
56
|
+
messageId: Schema.String,
|
|
57
|
+
status: Schema.Union([
|
|
58
|
+
Schema.Literal('completed'),
|
|
59
|
+
Schema.Literal('failed'),
|
|
60
|
+
Schema.Literal('cancelled'),
|
|
61
|
+
]),
|
|
62
|
+
error: Schema.optional(Schema.String),
|
|
63
|
+
});
|
|
64
|
+
export const AgentSessionCancelRequestedPayloadSchema = Schema.Struct({});
|
|
35
65
|
export const AgentSpawnRequestedPayloadSchema = Schema.Struct({
|
|
36
66
|
childThreadId: Schema.String,
|
|
37
67
|
kind: Schema.String,
|
|
38
68
|
definitionName: Schema.String,
|
|
69
|
+
definitionVersion: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(DEFAULT_DEFINITION_VERSION))),
|
|
39
70
|
toolCallId: Schema.String,
|
|
40
71
|
input: Schema.Json,
|
|
41
72
|
});
|
|
42
73
|
export const AgentEffectsRequestedPayloadSchema = Schema.Struct({
|
|
43
74
|
toolCallId: Schema.String,
|
|
44
|
-
|
|
45
|
-
effects: Schema.Array(Schema.Unknown),
|
|
75
|
+
effects: Schema.Array(RuntimeEffectSchema),
|
|
46
76
|
waitOn: Schema.optional(Schema.Struct({
|
|
47
77
|
type: Schema.Union([Schema.String, Schema.Array(Schema.String)]),
|
|
48
78
|
match: Schema.optional(Schema.Json),
|
|
@@ -56,6 +86,11 @@ export const agentCatalog = defineEventCatalog('agent', {
|
|
|
56
86
|
'tool_call.requested': AgentToolCallRequestedPayloadSchema,
|
|
57
87
|
'tool.result': AgentToolResultPayloadSchema,
|
|
58
88
|
steered: AgentSteeredPayloadSchema,
|
|
89
|
+
'session.message.submitted': AgentSessionMessageSubmittedPayloadSchema,
|
|
90
|
+
'session.steer.delivered': AgentSessionSteerDeliveredPayloadSchema,
|
|
91
|
+
'session.turn.started': AgentSessionTurnStartedPayloadSchema,
|
|
92
|
+
'session.turn.closed': AgentSessionTurnClosedPayloadSchema,
|
|
93
|
+
'session.cancel.requested': AgentSessionCancelRequestedPayloadSchema,
|
|
59
94
|
'spawn.requested': AgentSpawnRequestedPayloadSchema,
|
|
60
95
|
'effects.requested': AgentEffectsRequestedPayloadSchema,
|
|
61
96
|
});
|
package/dist/agent/index.d.ts
CHANGED
package/dist/agent/index.js
CHANGED
package/dist/agent/llm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Effect, Layer } from 'effect';
|
|
2
|
-
import type
|
|
2
|
+
import { type JsonValue } from '@swirls/looms/core';
|
|
3
3
|
import type { AgentTurnContext, AgentTurnResult, ToolLike } from './definitions';
|
|
4
4
|
import type { Message, ToolCall } from './types';
|
|
5
5
|
export interface LlmToolSpec {
|
|
@@ -17,11 +17,20 @@ export interface LlmCompleteArgs {
|
|
|
17
17
|
signal?: AbortSignal;
|
|
18
18
|
}
|
|
19
19
|
export interface LlmService {
|
|
20
|
-
readonly complete: (args: LlmCompleteArgs) => Effect.Effect<AgentTurnResult,
|
|
20
|
+
readonly complete: (args: LlmCompleteArgs) => Effect.Effect<AgentTurnResult, LlmError>;
|
|
21
21
|
}
|
|
22
22
|
export interface LlmAdapter {
|
|
23
23
|
readonly complete: (args: LlmCompleteArgs) => Promise<AgentTurnResult>;
|
|
24
24
|
}
|
|
25
|
+
declare const LlmError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
26
|
+
readonly _tag: "LlmError";
|
|
27
|
+
} & Readonly<A>;
|
|
28
|
+
export declare class LlmError extends LlmError_base<{
|
|
29
|
+
readonly cause: unknown;
|
|
30
|
+
readonly message: string;
|
|
31
|
+
}> {
|
|
32
|
+
constructor(cause: unknown);
|
|
33
|
+
}
|
|
25
34
|
export declare function llmFromAdapter(adapter: LlmAdapter): LlmService;
|
|
26
35
|
declare const LlmTag_base: Context.ServiceClass<LlmTag, "looms/Llm", LlmService>;
|
|
27
36
|
export declare class LlmTag extends LlmTag_base {
|