@laserdata/laser-sdk 0.0.1-rc.2 → 0.0.1-rc.3
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/README.md +2 -2
- package/dist/agent/agdx.d.ts +55 -0
- package/dist/agent/agdx.d.ts.map +1 -0
- package/dist/agent/agdx.js +447 -0
- package/dist/agent/agdx.js.map +1 -0
- package/dist/agent/assembler.d.ts +29 -0
- package/dist/agent/assembler.d.ts.map +1 -0
- package/dist/agent/assembler.js +69 -0
- package/dist/agent/assembler.js.map +1 -0
- package/dist/agent/builder.d.ts +114 -0
- package/dist/agent/builder.d.ts.map +1 -0
- package/dist/agent/builder.js +334 -0
- package/dist/agent/builder.js.map +1 -0
- package/dist/agent/context.d.ts +68 -0
- package/dist/agent/context.d.ts.map +1 -0
- package/dist/agent/context.js +212 -0
- package/dist/agent/context.js.map +1 -0
- package/dist/agent/contract.d.ts +70 -0
- package/dist/agent/contract.d.ts.map +1 -0
- package/dist/agent/contract.js +268 -0
- package/dist/agent/contract.js.map +1 -0
- package/dist/agent/registry.d.ts +76 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +286 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/reliable-consumer.d.ts +126 -0
- package/dist/agent/reliable-consumer.d.ts.map +1 -0
- package/dist/agent/reliable-consumer.js +551 -0
- package/dist/agent/reliable-consumer.js.map +1 -0
- package/dist/agent/replies.d.ts +28 -0
- package/dist/agent/replies.d.ts.map +1 -0
- package/dist/agent/replies.js +175 -0
- package/dist/agent/replies.js.map +1 -0
- package/dist/agent/router.d.ts +72 -0
- package/dist/agent/router.d.ts.map +1 -0
- package/dist/agent/router.js +172 -0
- package/dist/agent/router.js.map +1 -0
- package/dist/agent/scope.d.ts +16 -0
- package/dist/agent/scope.d.ts.map +1 -0
- package/dist/agent/scope.js +34 -0
- package/dist/agent/scope.js.map +1 -0
- package/dist/agent/workflow.d.ts +85 -0
- package/dist/agent/workflow.d.ts.map +1 -0
- package/dist/agent/workflow.js +416 -0
- package/dist/agent/workflow.js.map +1 -0
- package/dist/blob.d.ts +12 -0
- package/dist/blob.d.ts.map +1 -0
- package/dist/blob.js +34 -0
- package/dist/blob.js.map +1 -0
- package/dist/bridges/a2a.d.ts +89 -0
- package/dist/bridges/a2a.d.ts.map +1 -0
- package/dist/bridges/a2a.js +244 -0
- package/dist/bridges/a2a.js.map +1 -0
- package/dist/bridges/agui.d.ts +66 -0
- package/dist/bridges/agui.d.ts.map +1 -0
- package/dist/bridges/agui.js +335 -0
- package/dist/bridges/agui.js.map +1 -0
- package/dist/bridges/edge-auth.d.ts +16 -0
- package/dist/bridges/edge-auth.d.ts.map +1 -0
- package/dist/bridges/edge-auth.js +19 -0
- package/dist/bridges/edge-auth.js.map +1 -0
- package/dist/bridges/hops.d.ts +9 -0
- package/dist/bridges/hops.d.ts.map +1 -0
- package/dist/bridges/hops.js +16 -0
- package/dist/bridges/hops.js.map +1 -0
- package/dist/bridges/mcp.d.ts +79 -0
- package/dist/bridges/mcp.d.ts.map +1 -0
- package/dist/bridges/mcp.js +248 -0
- package/dist/bridges/mcp.js.map +1 -0
- package/dist/client/bytes.d.ts +3 -0
- package/dist/client/bytes.d.ts.map +1 -0
- package/dist/client/bytes.js +9 -0
- package/dist/client/bytes.js.map +1 -0
- package/dist/client/capabilities.d.ts +36 -0
- package/dist/client/capabilities.d.ts.map +1 -0
- package/dist/client/capabilities.js +91 -0
- package/dist/client/capabilities.js.map +1 -0
- package/dist/client/errors.d.ts +178 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +192 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/internals.d.ts +5 -0
- package/dist/client/internals.d.ts.map +1 -0
- package/dist/client/internals.js +5 -0
- package/dist/client/internals.js.map +1 -0
- package/dist/client/laser.d.ts +238 -0
- package/dist/client/laser.d.ts.map +1 -0
- package/dist/client/laser.js +831 -0
- package/dist/client/laser.js.map +1 -0
- package/dist/client/laserdata-ca.d.ts +2 -0
- package/dist/client/laserdata-ca.d.ts.map +1 -0
- package/dist/client/laserdata-ca.js +35 -0
- package/dist/client/laserdata-ca.js.map +1 -0
- package/dist/client/managed.d.ts +6 -0
- package/dist/client/managed.d.ts.map +1 -0
- package/dist/client/managed.js +19 -0
- package/dist/client/managed.js.map +1 -0
- package/dist/context-scope.d.ts +40 -0
- package/dist/context-scope.d.ts.map +1 -0
- package/dist/context-scope.js +73 -0
- package/dist/context-scope.js.map +1 -0
- package/dist/context.d.ts +64 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +149 -0
- package/dist/context.js.map +1 -0
- package/dist/conversation-state.d.ts +24 -0
- package/dist/conversation-state.d.ts.map +1 -0
- package/dist/conversation-state.js +29 -0
- package/dist/conversation-state.js.map +1 -0
- package/dist/crash-context.d.ts +11 -0
- package/dist/crash-context.d.ts.map +1 -0
- package/dist/crash-context.js +62 -0
- package/dist/crash-context.js.map +1 -0
- package/dist/full.d.ts +3 -0
- package/dist/full.d.ts.map +1 -0
- package/dist/full.js +3 -0
- package/dist/full.js.map +1 -0
- package/dist/govern.d.ts +133 -0
- package/dist/govern.d.ts.map +1 -0
- package/dist/govern.js +347 -0
- package/dist/govern.js.map +1 -0
- package/dist/iggy/apache-iggy.d.ts +168 -0
- package/dist/iggy/apache-iggy.d.ts.map +1 -0
- package/dist/iggy/apache-iggy.js +528 -0
- package/dist/iggy/apache-iggy.js.map +1 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/intent.d.ts +75 -0
- package/dist/intent.d.ts.map +1 -0
- package/dist/intent.js +195 -0
- package/dist/intent.js.map +1 -0
- package/dist/managed/batch.d.ts +5 -0
- package/dist/managed/batch.d.ts.map +1 -0
- package/dist/managed/batch.js +32 -0
- package/dist/managed/batch.js.map +1 -0
- package/dist/managed/forks.d.ts +72 -0
- package/dist/managed/forks.d.ts.map +1 -0
- package/dist/managed/forks.js +188 -0
- package/dist/managed/forks.js.map +1 -0
- package/dist/managed/graph.d.ts +58 -0
- package/dist/managed/graph.d.ts.map +1 -0
- package/dist/managed/graph.js +176 -0
- package/dist/managed/graph.js.map +1 -0
- package/dist/managed/kv.d.ts +144 -0
- package/dist/managed/kv.d.ts.map +1 -0
- package/dist/managed/kv.js +502 -0
- package/dist/managed/kv.js.map +1 -0
- package/dist/managed/projections.d.ts +61 -0
- package/dist/managed/projections.d.ts.map +1 -0
- package/dist/managed/projections.js +191 -0
- package/dist/managed/projections.js.map +1 -0
- package/dist/managed/query.d.ts +72 -0
- package/dist/managed/query.d.ts.map +1 -0
- package/dist/managed/query.js +287 -0
- package/dist/managed/query.js.map +1 -0
- package/dist/managed/rbac.d.ts +16 -0
- package/dist/managed/rbac.d.ts.map +1 -0
- package/dist/managed/rbac.js +74 -0
- package/dist/managed/rbac.js.map +1 -0
- package/dist/managed/runs.d.ts +40 -0
- package/dist/managed/runs.d.ts.map +1 -0
- package/dist/managed/runs.js +112 -0
- package/dist/managed/runs.js.map +1 -0
- package/dist/managed/watch.d.ts +21 -0
- package/dist/managed/watch.d.ts.map +1 -0
- package/dist/managed/watch.js +73 -0
- package/dist/managed/watch.js.map +1 -0
- package/dist/memory/handle.d.ts +77 -0
- package/dist/memory/handle.d.ts.map +1 -0
- package/dist/memory/handle.js +234 -0
- package/dist/memory/handle.js.map +1 -0
- package/dist/memory/log-memory.d.ts +38 -0
- package/dist/memory/log-memory.d.ts.map +1 -0
- package/dist/memory/log-memory.js +309 -0
- package/dist/memory/log-memory.js.map +1 -0
- package/dist/memory/topic.d.ts +22 -0
- package/dist/memory/topic.d.ts.map +1 -0
- package/dist/memory/topic.js +56 -0
- package/dist/memory/topic.js.map +1 -0
- package/dist/memory/types.d.ts +108 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +127 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory/vector-memory.d.ts +20 -0
- package/dist/memory/vector-memory.d.ts.map +1 -0
- package/dist/memory/vector-memory.js +193 -0
- package/dist/memory/vector-memory.js.map +1 -0
- package/dist/memory.d.ts +7 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +6 -0
- package/dist/memory.js.map +1 -0
- package/dist/observe.d.ts +10 -0
- package/dist/observe.d.ts.map +1 -0
- package/dist/observe.js +5 -0
- package/dist/observe.js.map +1 -0
- package/dist/opentelemetry.d.ts +22 -0
- package/dist/opentelemetry.d.ts.map +1 -0
- package/dist/opentelemetry.js +38 -0
- package/dist/opentelemetry.js.map +1 -0
- package/dist/provenance/agent-topic.d.ts +14 -0
- package/dist/provenance/agent-topic.d.ts.map +1 -0
- package/dist/provenance/agent-topic.js +13 -0
- package/dist/provenance/agent-topic.js.map +1 -0
- package/dist/provenance/provenance.d.ts +24 -0
- package/dist/provenance/provenance.d.ts.map +1 -0
- package/dist/provenance/provenance.js +186 -0
- package/dist/provenance/provenance.js.map +1 -0
- package/dist/provenance/session-policy.d.ts +4 -0
- package/dist/provenance/session-policy.d.ts.map +1 -0
- package/dist/provenance/session-policy.js +5 -0
- package/dist/provenance/session-policy.js.map +1 -0
- package/dist/runtime/async-once.d.ts +6 -0
- package/dist/runtime/async-once.d.ts.map +1 -0
- package/dist/runtime/async-once.js +19 -0
- package/dist/runtime/async-once.js.map +1 -0
- package/dist/runtime/clock.d.ts +14 -0
- package/dist/runtime/clock.d.ts.map +1 -0
- package/dist/runtime/clock.js +21 -0
- package/dist/runtime/clock.js.map +1 -0
- package/dist/runtime/mutex.d.ts +5 -0
- package/dist/runtime/mutex.d.ts.map +1 -0
- package/dist/runtime/mutex.js +23 -0
- package/dist/runtime/mutex.js.map +1 -0
- package/dist/runtime/ulid.d.ts +7 -0
- package/dist/runtime/ulid.d.ts.map +1 -0
- package/dist/runtime/ulid.js +17 -0
- package/dist/runtime/ulid.js.map +1 -0
- package/dist/schema-codecs.d.ts +16 -0
- package/dist/schema-codecs.d.ts.map +1 -0
- package/dist/schema-codecs.js +174 -0
- package/dist/schema-codecs.js.map +1 -0
- package/dist/signing.d.ts +63 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +288 -0
- package/dist/signing.js.map +1 -0
- package/dist/snapshot.d.ts +24 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +80 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/state-store.d.ts +20 -0
- package/dist/state-store.d.ts.map +1 -0
- package/dist/state-store.js +70 -0
- package/dist/state-store.js.map +1 -0
- package/dist/stream/codecs.d.ts +9 -0
- package/dist/stream/codecs.d.ts.map +1 -0
- package/dist/stream/codecs.js +83 -0
- package/dist/stream/codecs.js.map +1 -0
- package/dist/stream/consumer.d.ts +50 -0
- package/dist/stream/consumer.d.ts.map +1 -0
- package/dist/stream/consumer.js +145 -0
- package/dist/stream/consumer.js.map +1 -0
- package/dist/stream/cursor.d.ts +26 -0
- package/dist/stream/cursor.d.ts.map +1 -0
- package/dist/stream/cursor.js +83 -0
- package/dist/stream/cursor.js.map +1 -0
- package/dist/stream/header-value.d.ts +18 -0
- package/dist/stream/header-value.d.ts.map +1 -0
- package/dist/stream/header-value.js +70 -0
- package/dist/stream/header-value.js.map +1 -0
- package/dist/stream/polling-strategy.d.ts +14 -0
- package/dist/stream/polling-strategy.d.ts.map +1 -0
- package/dist/stream/polling-strategy.js +2 -0
- package/dist/stream/polling-strategy.js.map +1 -0
- package/dist/stream/producer.d.ts +44 -0
- package/dist/stream/producer.d.ts.map +1 -0
- package/dist/stream/producer.js +125 -0
- package/dist/stream/producer.js.map +1 -0
- package/dist/stream/publish.d.ts +83 -0
- package/dist/stream/publish.d.ts.map +1 -0
- package/dist/stream/publish.js +287 -0
- package/dist/stream/publish.js.map +1 -0
- package/dist/stream/record.d.ts +29 -0
- package/dist/stream/record.d.ts.map +1 -0
- package/dist/stream/record.js +152 -0
- package/dist/stream/record.js.map +1 -0
- package/dist/stream/routing.d.ts +10 -0
- package/dist/stream/routing.d.ts.map +1 -0
- package/dist/stream/routing.js +2 -0
- package/dist/stream/routing.js.map +1 -0
- package/dist/stream/stream.d.ts +14 -0
- package/dist/stream/stream.d.ts.map +1 -0
- package/dist/stream/stream.js +26 -0
- package/dist/stream/stream.js.map +1 -0
- package/dist/stream/topic.d.ts +52 -0
- package/dist/stream/topic.d.ts.map +1 -0
- package/dist/stream/topic.js +181 -0
- package/dist/stream/topic.js.map +1 -0
- package/dist/stream/typed-topic.d.ts +59 -0
- package/dist/stream/typed-topic.d.ts.map +1 -0
- package/dist/stream/typed-topic.js +119 -0
- package/dist/stream/typed-topic.js.map +1 -0
- package/dist/swarm.d.ts +16 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +40 -0
- package/dist/swarm.js.map +1 -0
- package/dist/testing.d.ts +16 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +19 -0
- package/dist/testing.js.map +1 -0
- package/dist/types/ids.d.ts +48 -0
- package/dist/types/ids.d.ts.map +1 -0
- package/dist/types/ids.js +161 -0
- package/dist/types/ids.js.map +1 -0
- package/dist/wire/agent-record.d.ts +24 -0
- package/dist/wire/agent-record.d.ts.map +1 -0
- package/dist/wire/agent-record.js +99 -0
- package/dist/wire/agent-record.js.map +1 -0
- package/dist/wire/agent-workflow.d.ts +118 -0
- package/dist/wire/agent-workflow.d.ts.map +1 -0
- package/dist/wire/agent-workflow.js +290 -0
- package/dist/wire/agent-workflow.js.map +1 -0
- package/dist/wire/agent.d.ts +255 -0
- package/dist/wire/agent.d.ts.map +1 -0
- package/dist/wire/agent.js +792 -0
- package/dist/wire/agent.js.map +1 -0
- package/dist/wire/authz.d.ts +183 -0
- package/dist/wire/authz.d.ts.map +1 -0
- package/dist/wire/authz.js +527 -0
- package/dist/wire/authz.js.map +1 -0
- package/dist/wire/batch.d.ts +17 -0
- package/dist/wire/batch.d.ts.map +1 -0
- package/dist/wire/batch.js +41 -0
- package/dist/wire/batch.js.map +1 -0
- package/dist/wire/browse.d.ts +96 -0
- package/dist/wire/browse.d.ts.map +1 -0
- package/dist/wire/browse.js +201 -0
- package/dist/wire/browse.js.map +1 -0
- package/dist/wire/cbor.d.ts +35 -0
- package/dist/wire/cbor.d.ts.map +1 -0
- package/dist/wire/cbor.js +231 -0
- package/dist/wire/cbor.js.map +1 -0
- package/dist/wire/change.d.ts +12 -0
- package/dist/wire/change.d.ts.map +1 -0
- package/dist/wire/change.js +22 -0
- package/dist/wire/change.js.map +1 -0
- package/dist/wire/clients.d.ts +27 -0
- package/dist/wire/clients.d.ts.map +1 -0
- package/dist/wire/clients.js +64 -0
- package/dist/wire/clients.js.map +1 -0
- package/dist/wire/codes.d.ts +67 -0
- package/dist/wire/codes.d.ts.map +1 -0
- package/dist/wire/codes.js +67 -0
- package/dist/wire/codes.js.map +1 -0
- package/dist/wire/commands.d.ts +68 -0
- package/dist/wire/commands.d.ts.map +1 -0
- package/dist/wire/commands.js +140 -0
- package/dist/wire/commands.js.map +1 -0
- package/dist/wire/content.d.ts +17 -0
- package/dist/wire/content.d.ts.map +1 -0
- package/dist/wire/content.js +47 -0
- package/dist/wire/content.js.map +1 -0
- package/dist/wire/control.d.ts +170 -0
- package/dist/wire/control.d.ts.map +1 -0
- package/dist/wire/control.js +453 -0
- package/dist/wire/control.js.map +1 -0
- package/dist/wire/fork.d.ts +112 -0
- package/dist/wire/fork.d.ts.map +1 -0
- package/dist/wire/fork.js +280 -0
- package/dist/wire/fork.js.map +1 -0
- package/dist/wire/forward.d.ts +23 -0
- package/dist/wire/forward.d.ts.map +1 -0
- package/dist/wire/forward.js +72 -0
- package/dist/wire/forward.js.map +1 -0
- package/dist/wire/graph.d.ts +181 -0
- package/dist/wire/graph.d.ts.map +1 -0
- package/dist/wire/graph.js +554 -0
- package/dist/wire/graph.js.map +1 -0
- package/dist/wire/hashing.d.ts +2 -0
- package/dist/wire/hashing.d.ts.map +1 -0
- package/dist/wire/hashing.js +21 -0
- package/dist/wire/hashing.js.map +1 -0
- package/dist/wire/headers.d.ts +32 -0
- package/dist/wire/headers.d.ts.map +1 -0
- package/dist/wire/headers.js +32 -0
- package/dist/wire/headers.js.map +1 -0
- package/dist/wire/hello.d.ts +50 -0
- package/dist/wire/hello.d.ts.map +1 -0
- package/dist/wire/hello.js +122 -0
- package/dist/wire/hello.js.map +1 -0
- package/dist/wire/http.d.ts +95 -0
- package/dist/wire/http.d.ts.map +1 -0
- package/dist/wire/http.js +282 -0
- package/dist/wire/http.js.map +1 -0
- package/dist/wire/ids.d.ts +50 -0
- package/dist/wire/ids.d.ts.map +1 -0
- package/dist/wire/ids.js +198 -0
- package/dist/wire/ids.js.map +1 -0
- package/dist/wire/index.d.ts +32 -0
- package/dist/wire/index.d.ts.map +1 -0
- package/dist/wire/index.js +32 -0
- package/dist/wire/index.js.map +1 -0
- package/dist/wire/kv.d.ts +260 -0
- package/dist/wire/kv.d.ts.map +1 -0
- package/dist/wire/kv.js +650 -0
- package/dist/wire/kv.js.map +1 -0
- package/dist/wire/limits.d.ts +36 -0
- package/dist/wire/limits.d.ts.map +1 -0
- package/dist/wire/limits.js +36 -0
- package/dist/wire/limits.js.map +1 -0
- package/dist/wire/memory.d.ts +17 -0
- package/dist/wire/memory.d.ts.map +1 -0
- package/dist/wire/memory.js +65 -0
- package/dist/wire/memory.js.map +1 -0
- package/dist/wire/mutation.d.ts +10 -0
- package/dist/wire/mutation.d.ts.map +1 -0
- package/dist/wire/mutation.js +18 -0
- package/dist/wire/mutation.js.map +1 -0
- package/dist/wire/query.d.ts +210 -0
- package/dist/wire/query.d.ts.map +1 -0
- package/dist/wire/query.js +594 -0
- package/dist/wire/query.js.map +1 -0
- package/dist/wire/result.d.ts +25 -0
- package/dist/wire/result.d.ts.map +1 -0
- package/dist/wire/result.js +52 -0
- package/dist/wire/result.js.map +1 -0
- package/dist/wire/snapshot.d.ts +11 -0
- package/dist/wire/snapshot.d.ts.map +1 -0
- package/dist/wire/snapshot.js +50 -0
- package/dist/wire/snapshot.js.map +1 -0
- package/dist/wire/topics.d.ts +5 -0
- package/dist/wire/topics.d.ts.map +1 -0
- package/dist/wire/topics.js +5 -0
- package/dist/wire/topics.js.map +1 -0
- package/dist/wire/topology.d.ts +24 -0
- package/dist/wire/topology.d.ts.map +1 -0
- package/dist/wire/topology.js +56 -0
- package/dist/wire/topology.js.map +1 -0
- package/dist/wire/value.d.ts +21 -0
- package/dist/wire/value.d.ts.map +1 -0
- package/dist/wire/value.js +40 -0
- package/dist/wire/value.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { CodecError, HandlerConfigError } from "../client/errors.js";
|
|
2
|
+
import { AgentTopic } from "../provenance/agent-topic.js";
|
|
3
|
+
import { signCardValue } from "../signing.js";
|
|
4
|
+
import { ConversationId } from "../types/ids.js";
|
|
5
|
+
import { AgentKind, METADATA_BRIDGE_HOPS, OPERATION_CHAT, taskStateDisplay } from "../wire/agent.js";
|
|
6
|
+
import { ContentType } from "../wire/content.js";
|
|
7
|
+
import { CorrelationId } from "../wire/ids.js";
|
|
8
|
+
import { bridgeHopMetadata, enterBridge } from "./hops.js";
|
|
9
|
+
export const A2A_PROTOCOL_VERSION = "1.0";
|
|
10
|
+
export const A2A_JSONRPC_BINDING = "JSONRPC";
|
|
11
|
+
export const A2A_APP_ERROR_CODE = -32_000;
|
|
12
|
+
export const SDK_VERSION = "0.0.1-rc.3";
|
|
13
|
+
export const A2aMethod = {
|
|
14
|
+
MessageSend: "SendMessage",
|
|
15
|
+
MessageStream: "SendStreamingMessage",
|
|
16
|
+
TasksGet: "GetTask",
|
|
17
|
+
TasksCancel: "CancelTask"
|
|
18
|
+
};
|
|
19
|
+
function jsonObject(value, context) {
|
|
20
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
21
|
+
throw new HandlerConfigError(`${context} must be a JSON object`);
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function jsonBytes(value, context) {
|
|
26
|
+
try {
|
|
27
|
+
const encoded = JSON.stringify(value);
|
|
28
|
+
if (typeof encoded !== "string")
|
|
29
|
+
throw new Error("value is not JSON serializable");
|
|
30
|
+
return new TextEncoder().encode(encoded);
|
|
31
|
+
}
|
|
32
|
+
catch (cause) {
|
|
33
|
+
throw new CodecError(`${context} is not JSON serializable`, "a2a", "json", { cause });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function correlationOf(conversation) {
|
|
37
|
+
return CorrelationId.parse(conversation.toString());
|
|
38
|
+
}
|
|
39
|
+
export function contentRefMode(reference) {
|
|
40
|
+
if (reference.kind === "schemaId") {
|
|
41
|
+
return `application/x-agdx-schema;id=${reference.value}`;
|
|
42
|
+
}
|
|
43
|
+
const modes = {
|
|
44
|
+
[ContentType.Raw]: "application/octet-stream",
|
|
45
|
+
[ContentType.Json]: "application/json",
|
|
46
|
+
[ContentType.Msgpack]: "application/msgpack",
|
|
47
|
+
[ContentType.Cbor]: "application/cbor",
|
|
48
|
+
[ContentType.Bson]: "application/bson",
|
|
49
|
+
[ContentType.Avro]: "application/avro",
|
|
50
|
+
[ContentType.Protobuf]: "application/protobuf",
|
|
51
|
+
[ContentType.Arrow]: "application/vnd.apache.arrow.stream",
|
|
52
|
+
[ContentType.Ref]: "application/x-agdx-ref",
|
|
53
|
+
[ContentType.Any]: "*/*"
|
|
54
|
+
};
|
|
55
|
+
return modes[reference.value];
|
|
56
|
+
}
|
|
57
|
+
export function taskFromEnvelope(taskId, envelope) {
|
|
58
|
+
const state = envelope.taskState ??
|
|
59
|
+
(envelope.kind === AgentKind.Error
|
|
60
|
+
? { kind: "known", name: "Failed" }
|
|
61
|
+
: { kind: "known", name: "Completed" });
|
|
62
|
+
return {
|
|
63
|
+
id: taskId,
|
|
64
|
+
status: { state },
|
|
65
|
+
artifacts: envelope.body.byteLength === 0 ? [] : [{ text: new TextDecoder().decode(envelope.body) }]
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function taskToJson(task) {
|
|
69
|
+
return {
|
|
70
|
+
id: task.id,
|
|
71
|
+
status: { state: taskStateDisplay(task.status.state) },
|
|
72
|
+
...(task.artifacts.length > 0 ? { artifacts: task.artifacts } : {})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export class A2aBridge {
|
|
76
|
+
laser;
|
|
77
|
+
source;
|
|
78
|
+
requestTopic;
|
|
79
|
+
replyTopic;
|
|
80
|
+
capabilities = [];
|
|
81
|
+
signingKey;
|
|
82
|
+
hops;
|
|
83
|
+
constructor(laser, source, requestTopic, replyTopic) {
|
|
84
|
+
this.laser = laser;
|
|
85
|
+
this.source = source;
|
|
86
|
+
this.requestTopic = requestTopic;
|
|
87
|
+
this.replyTopic = replyTopic;
|
|
88
|
+
this.hops = enterBridge(source.asString());
|
|
89
|
+
}
|
|
90
|
+
withBridgeHops(previous) {
|
|
91
|
+
this.hops = enterBridge(this.source.asString(), previous);
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
withSigningKey(key) {
|
|
95
|
+
this.signingKey = key;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
withCapabilities(capabilities) {
|
|
99
|
+
this.capabilities = [...capabilities];
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
async submit(params) {
|
|
103
|
+
return this.submitJson(jsonBytes(params, "A2A message params"));
|
|
104
|
+
}
|
|
105
|
+
async submitJson(paramsJson) {
|
|
106
|
+
const task = ConversationId.new();
|
|
107
|
+
await this.laser
|
|
108
|
+
.agdx(this.requestTopic, this.source, task)
|
|
109
|
+
.command(correlationOf(task), paramsJson)
|
|
110
|
+
.withOperation(OPERATION_CHAT)
|
|
111
|
+
.withMetadata(METADATA_BRIDGE_HOPS, bridgeHopMetadata(this.hops))
|
|
112
|
+
.contentType(ContentType.Json)
|
|
113
|
+
.send();
|
|
114
|
+
return {
|
|
115
|
+
id: task.toString(),
|
|
116
|
+
status: { state: { kind: "known", name: "Submitted" } },
|
|
117
|
+
artifacts: []
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async task(id) {
|
|
121
|
+
let conversation;
|
|
122
|
+
try {
|
|
123
|
+
conversation = ConversationId.parse(id);
|
|
124
|
+
}
|
|
125
|
+
catch (cause) {
|
|
126
|
+
throw new HandlerConfigError(`invalid task id \`${id}\``, { cause });
|
|
127
|
+
}
|
|
128
|
+
const correlation = correlationOf(conversation);
|
|
129
|
+
const messages = await this.laser
|
|
130
|
+
.context(conversation)
|
|
131
|
+
.fetch([this.replyTopic], Number.MAX_SAFE_INTEGER);
|
|
132
|
+
const answer = messages.findLast((message) => message.envelope?.correlation?.equals(correlation) === true &&
|
|
133
|
+
(message.envelope.kind === AgentKind.Response || message.envelope.kind === AgentKind.Error))?.envelope;
|
|
134
|
+
return answer === undefined
|
|
135
|
+
? {
|
|
136
|
+
id,
|
|
137
|
+
status: { state: { kind: "known", name: "Working" } },
|
|
138
|
+
artifacts: []
|
|
139
|
+
}
|
|
140
|
+
: taskFromEnvelope(id, answer);
|
|
141
|
+
}
|
|
142
|
+
async cancel(id) {
|
|
143
|
+
let conversation;
|
|
144
|
+
try {
|
|
145
|
+
conversation = ConversationId.parse(id);
|
|
146
|
+
}
|
|
147
|
+
catch (cause) {
|
|
148
|
+
throw new HandlerConfigError(`invalid task id \`${id}\``, { cause });
|
|
149
|
+
}
|
|
150
|
+
let send = this.laser
|
|
151
|
+
.agdx(this.replyTopic, this.source, conversation)
|
|
152
|
+
.fail(correlationOf(conversation), {
|
|
153
|
+
code: { kind: "known", name: "Cancelled" },
|
|
154
|
+
message: "canceled by the A2A client",
|
|
155
|
+
retryable: false
|
|
156
|
+
})
|
|
157
|
+
.withTaskState({ kind: "known", name: "Canceled" })
|
|
158
|
+
.withMetadata(METADATA_BRIDGE_HOPS, bridgeHopMetadata(this.hops));
|
|
159
|
+
if (this.signingKey !== undefined)
|
|
160
|
+
send = send.signedBy(this.signingKey);
|
|
161
|
+
await send.send();
|
|
162
|
+
return {
|
|
163
|
+
id,
|
|
164
|
+
status: { state: { kind: "known", name: "Canceled" } },
|
|
165
|
+
artifacts: []
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
card() {
|
|
169
|
+
return {
|
|
170
|
+
name: this.source.asString(),
|
|
171
|
+
description: "LaserData AGDX bridge over the durable log",
|
|
172
|
+
version: SDK_VERSION,
|
|
173
|
+
supportedInterfaces: [
|
|
174
|
+
{ url: "/", protocolBinding: A2A_JSONRPC_BINDING, protocolVersion: A2A_PROTOCOL_VERSION }
|
|
175
|
+
],
|
|
176
|
+
capabilities: {
|
|
177
|
+
streaming: true,
|
|
178
|
+
pushNotifications: false,
|
|
179
|
+
stateTransitionHistory: false,
|
|
180
|
+
extendedAgentCard: false
|
|
181
|
+
},
|
|
182
|
+
defaultInputModes: ["text/plain"],
|
|
183
|
+
defaultOutputModes: ["text/plain"],
|
|
184
|
+
skills: this.capabilities.map((capability) => ({
|
|
185
|
+
id: capability.skillId,
|
|
186
|
+
name: capability.skillId,
|
|
187
|
+
description: "",
|
|
188
|
+
tags: [],
|
|
189
|
+
...(capability.input !== undefined
|
|
190
|
+
? { inputModes: [contentRefMode(capability.input)] }
|
|
191
|
+
: {}),
|
|
192
|
+
...(capability.output !== undefined
|
|
193
|
+
? { outputModes: [contentRefMode(capability.output)] }
|
|
194
|
+
: {})
|
|
195
|
+
}))
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
signedCard(key) {
|
|
199
|
+
const card = this.card();
|
|
200
|
+
return { ...card, signatures: [signCardValue(key, card)] };
|
|
201
|
+
}
|
|
202
|
+
async handleRpc(input) {
|
|
203
|
+
let id = null;
|
|
204
|
+
try {
|
|
205
|
+
const request = jsonObject(input, "A2A JSON-RPC request");
|
|
206
|
+
id = request["id"] ?? null;
|
|
207
|
+
const method = request["method"];
|
|
208
|
+
if (typeof method !== "string")
|
|
209
|
+
throw new HandlerConfigError("A2A method must be a string");
|
|
210
|
+
const params = request["params"] ?? {};
|
|
211
|
+
let task;
|
|
212
|
+
switch (method) {
|
|
213
|
+
case A2aMethod.MessageSend:
|
|
214
|
+
case A2aMethod.MessageStream:
|
|
215
|
+
task = await this.submit(params);
|
|
216
|
+
break;
|
|
217
|
+
case A2aMethod.TasksGet:
|
|
218
|
+
case A2aMethod.TasksCancel: {
|
|
219
|
+
const object = jsonObject(params, "A2A task params");
|
|
220
|
+
const taskId = object["id"];
|
|
221
|
+
if (typeof taskId !== "string")
|
|
222
|
+
throw new HandlerConfigError("A2A task id must be a string");
|
|
223
|
+
task = method === A2aMethod.TasksGet ? await this.task(taskId) : await this.cancel(taskId);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
default:
|
|
227
|
+
throw new HandlerConfigError(`unknown A2A method \`${method}\``);
|
|
228
|
+
}
|
|
229
|
+
return { jsonrpc: "2.0", id, result: taskToJson(task) };
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
return {
|
|
233
|
+
jsonrpc: "2.0",
|
|
234
|
+
id,
|
|
235
|
+
error: {
|
|
236
|
+
code: A2A_APP_ERROR_CODE,
|
|
237
|
+
message: error instanceof Error ? error.message : String(error)
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export { AgentTopic };
|
|
244
|
+
//# sourceMappingURL=a2a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a.js","sourceRoot":"","sources":["../../src/bridges/a2a.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,aAAa,EAA4C,MAAM,eAAe,CAAA;AACvF,OAAO,EAAE,cAAc,EAAgB,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAKjB,MAAM,kBAAkB,CAAA;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AAQ,CAAC;gBACxB,KAAK,SAAS,CAAC,WAAW,EAAE,CAAC;oBAC3B,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;oBACpD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;oBAC3B,IAAI,OAAO,MAAM,KAAK,QAAQ;wBAC5B,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAA;oBAC9D,IAAI,GAAG,MAAM,KAAK,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;oBAC1F,MAAK;gBACP,CAAC;gBACD;oBACE,MAAM,IAAI,kBAAkB,CAAC,wBAAwB,MAAM,IAAI,CAAC,CAAA;YACpE,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAA;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,EAAE;gBACF,KAAK,EAAE;oBACL,IAAI,EAAE,kBAAkB;oBACxB,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;iBAChE;aACF,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAED,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Laser } from "../client/laser.js";
|
|
2
|
+
import type { AgentId, ConversationId } from "../types/ids.js";
|
|
3
|
+
import { type AgentEnvelope } from "../wire/agent.js";
|
|
4
|
+
export type AgUiEvent = {
|
|
5
|
+
readonly type: "RUN_STARTED";
|
|
6
|
+
readonly threadId: string;
|
|
7
|
+
readonly runId: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: "RUN_FINISHED";
|
|
10
|
+
readonly threadId: string;
|
|
11
|
+
readonly runId: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "TEXT_MESSAGE_START";
|
|
14
|
+
readonly messageId: string;
|
|
15
|
+
readonly role: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "TEXT_MESSAGE_CONTENT";
|
|
18
|
+
readonly messageId: string;
|
|
19
|
+
readonly delta: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "TEXT_MESSAGE_END";
|
|
22
|
+
readonly messageId: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "REASONING_MESSAGE_START";
|
|
25
|
+
readonly messageId: string;
|
|
26
|
+
readonly role: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "REASONING_MESSAGE_CONTENT";
|
|
29
|
+
readonly messageId: string;
|
|
30
|
+
readonly delta: string;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "REASONING_MESSAGE_END";
|
|
33
|
+
readonly messageId: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "TOOL_CALL_START";
|
|
36
|
+
readonly toolCallId: string;
|
|
37
|
+
readonly toolCallName: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly type: "TOOL_CALL_ARGS";
|
|
40
|
+
readonly toolCallId: string;
|
|
41
|
+
readonly delta: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "TOOL_CALL_END";
|
|
44
|
+
readonly toolCallId: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly type: "TOOL_CALL_RESULT";
|
|
47
|
+
readonly toolCallId: string;
|
|
48
|
+
readonly content: string;
|
|
49
|
+
} | {
|
|
50
|
+
readonly type: "STATE_SNAPSHOT";
|
|
51
|
+
readonly snapshot: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "STATE_DELTA";
|
|
54
|
+
readonly delta: unknown;
|
|
55
|
+
} | {
|
|
56
|
+
readonly type: "RUN_ERROR";
|
|
57
|
+
readonly message: string;
|
|
58
|
+
};
|
|
59
|
+
export declare function applyJsonPatch(document: unknown, patch: unknown): unknown;
|
|
60
|
+
export declare function envelopeToAgUi(envelope: AgentEnvelope): readonly AgUiEvent[];
|
|
61
|
+
export declare function envelopesToAgUi(envelopes: readonly AgentEnvelope[]): readonly AgUiEvent[];
|
|
62
|
+
export declare function publishStateSnapshot(laser: Laser, topic: string, source: AgentId, conversation: ConversationId, state: unknown): Promise<void>;
|
|
63
|
+
export declare function publishStateDelta(laser: Laser, topic: string, source: AgentId, conversation: ConversationId, patch: unknown): Promise<void>;
|
|
64
|
+
export declare function reconstructState(laser: Laser, conversation: ConversationId, topic: string): Promise<unknown>;
|
|
65
|
+
export declare function aguiEvents(laser: Laser, conversation: ConversationId, topic: string): Promise<readonly AgUiEvent[]>;
|
|
66
|
+
//# sourceMappingURL=agui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agui.d.ts","sourceRoot":"","sources":["../../src/bridges/agui.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAQL,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAA;AAGzB,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnF;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpF;IAAE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;I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 -0,0 +1,335 @@
|
|
|
1
|
+
import { CodecError, InvalidError } from "../client/errors.js";
|
|
2
|
+
import { AgentKind, OPERATION_REASONING, OPERATION_STATE_DELTA, OPERATION_STATE_SNAPSHOT, OPERATION_TASK, OPERATION_TOOL_ARGS, taskStateIsTerminal } from "../wire/agent.js";
|
|
3
|
+
import { ContentType } from "../wire/content.js";
|
|
4
|
+
function jsonBytes(value, operation) {
|
|
5
|
+
try {
|
|
6
|
+
const encoded = JSON.stringify(value);
|
|
7
|
+
if (typeof encoded !== "string")
|
|
8
|
+
throw new Error("value is not JSON serializable");
|
|
9
|
+
return new TextEncoder().encode(encoded);
|
|
10
|
+
}
|
|
11
|
+
catch (cause) {
|
|
12
|
+
throw new CodecError(`cannot encode ${operation}`, "agui", operation, { cause });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function parseJson(bytes, operation) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
18
|
+
}
|
|
19
|
+
catch (cause) {
|
|
20
|
+
throw new CodecError(`cannot decode ${operation}`, "agui", operation, { cause });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function decodePointer(path) {
|
|
24
|
+
if (path === "")
|
|
25
|
+
return [];
|
|
26
|
+
if (!path.startsWith("/"))
|
|
27
|
+
throw new InvalidError(`invalid JSON Pointer \`${path}\``);
|
|
28
|
+
return path
|
|
29
|
+
.slice(1)
|
|
30
|
+
.split("/")
|
|
31
|
+
.map((part) => {
|
|
32
|
+
if (/~(?:[^01]|$)/.test(part))
|
|
33
|
+
throw new InvalidError(`invalid JSON Pointer \`${path}\``);
|
|
34
|
+
return part.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function arrayIndex(token, length, allowEnd) {
|
|
38
|
+
if (token === "-" && allowEnd)
|
|
39
|
+
return length;
|
|
40
|
+
if (!/^(?:0|[1-9][0-9]*)$/.test(token)) {
|
|
41
|
+
throw new InvalidError(`invalid JSON Patch array index \`${token}\``);
|
|
42
|
+
}
|
|
43
|
+
const index = Number(token);
|
|
44
|
+
const maximum = allowEnd ? length : length - 1;
|
|
45
|
+
if (!Number.isSafeInteger(index) || index < 0 || index > maximum) {
|
|
46
|
+
throw new InvalidError(`JSON Patch array index \`${token}\` is out of bounds`);
|
|
47
|
+
}
|
|
48
|
+
return index;
|
|
49
|
+
}
|
|
50
|
+
function objectOf(value, path) {
|
|
51
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
52
|
+
throw new InvalidError(`JSON Patch path \`${path}\` does not address a container`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function parentAt(document, tokens, path) {
|
|
57
|
+
if (tokens.length === 0)
|
|
58
|
+
throw new InvalidError("the document root has no parent");
|
|
59
|
+
let current = document;
|
|
60
|
+
for (const token of tokens.slice(0, -1)) {
|
|
61
|
+
if (Array.isArray(current)) {
|
|
62
|
+
current = current[arrayIndex(token, current.length, false)];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const object = objectOf(current, path);
|
|
66
|
+
if (!(token in object))
|
|
67
|
+
throw new InvalidError(`JSON Patch path \`${path}\` does not exist`);
|
|
68
|
+
current = object[token];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return [current, tokens.at(-1) ?? ""];
|
|
72
|
+
}
|
|
73
|
+
function valueAt(document, path) {
|
|
74
|
+
const tokens = decodePointer(path);
|
|
75
|
+
let current = document;
|
|
76
|
+
for (const token of tokens) {
|
|
77
|
+
if (Array.isArray(current))
|
|
78
|
+
current = current[arrayIndex(token, current.length, false)];
|
|
79
|
+
else {
|
|
80
|
+
const object = objectOf(current, path);
|
|
81
|
+
if (!(token in object))
|
|
82
|
+
throw new InvalidError(`JSON Patch path \`${path}\` does not exist`);
|
|
83
|
+
current = object[token];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return current;
|
|
87
|
+
}
|
|
88
|
+
function addValue(document, path, value) {
|
|
89
|
+
const tokens = decodePointer(path);
|
|
90
|
+
if (tokens.length === 0)
|
|
91
|
+
return value;
|
|
92
|
+
const [parent, token] = parentAt(document, tokens, path);
|
|
93
|
+
if (Array.isArray(parent))
|
|
94
|
+
parent.splice(arrayIndex(token, parent.length, true), 0, value);
|
|
95
|
+
else
|
|
96
|
+
objectOf(parent, path)[token] = value;
|
|
97
|
+
return document;
|
|
98
|
+
}
|
|
99
|
+
function removeValue(document, path) {
|
|
100
|
+
const tokens = decodePointer(path);
|
|
101
|
+
if (tokens.length === 0)
|
|
102
|
+
return { document: null, value: document };
|
|
103
|
+
const [parent, token] = parentAt(document, tokens, path);
|
|
104
|
+
if (Array.isArray(parent)) {
|
|
105
|
+
const index = arrayIndex(token, parent.length, false);
|
|
106
|
+
const value = parent[index];
|
|
107
|
+
parent.splice(index, 1);
|
|
108
|
+
return { document, value };
|
|
109
|
+
}
|
|
110
|
+
const object = objectOf(parent, path);
|
|
111
|
+
if (!(token in object))
|
|
112
|
+
throw new InvalidError(`JSON Patch path \`${path}\` does not exist`);
|
|
113
|
+
const value = object[token];
|
|
114
|
+
Reflect.deleteProperty(object, token);
|
|
115
|
+
return { document, value };
|
|
116
|
+
}
|
|
117
|
+
function equalJson(left, right) {
|
|
118
|
+
if (Object.is(left, right))
|
|
119
|
+
return true;
|
|
120
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
121
|
+
return (left.length === right.length && left.every((value, index) => equalJson(value, right[index])));
|
|
122
|
+
}
|
|
123
|
+
if (typeof left === "object" &&
|
|
124
|
+
left !== null &&
|
|
125
|
+
!Array.isArray(left) &&
|
|
126
|
+
typeof right === "object" &&
|
|
127
|
+
right !== null &&
|
|
128
|
+
!Array.isArray(right)) {
|
|
129
|
+
const a = left;
|
|
130
|
+
const b = right;
|
|
131
|
+
const keys = Object.keys(a);
|
|
132
|
+
return (keys.length === Object.keys(b).length &&
|
|
133
|
+
keys.every((key) => key in b && equalJson(a[key], b[key])));
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
function patchObject(value) {
|
|
138
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
139
|
+
throw new InvalidError("each JSON Patch operation must be an object");
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
export function applyJsonPatch(document, patch) {
|
|
144
|
+
if (!Array.isArray(patch))
|
|
145
|
+
throw new InvalidError("a JSON Patch document must be an array");
|
|
146
|
+
let result = structuredClone(document);
|
|
147
|
+
for (const raw of patch) {
|
|
148
|
+
const operation = patchObject(raw);
|
|
149
|
+
const op = operation["op"];
|
|
150
|
+
const path = operation["path"];
|
|
151
|
+
if (typeof op !== "string" || typeof path !== "string") {
|
|
152
|
+
throw new InvalidError("a JSON Patch operation requires string `op` and `path`");
|
|
153
|
+
}
|
|
154
|
+
switch (op) {
|
|
155
|
+
case "add":
|
|
156
|
+
if (!("value" in operation))
|
|
157
|
+
throw new InvalidError("JSON Patch add requires `value`");
|
|
158
|
+
result = addValue(result, path, structuredClone(operation["value"]));
|
|
159
|
+
break;
|
|
160
|
+
case "remove":
|
|
161
|
+
result = removeValue(result, path).document;
|
|
162
|
+
break;
|
|
163
|
+
case "replace":
|
|
164
|
+
if (!("value" in operation))
|
|
165
|
+
throw new InvalidError("JSON Patch replace requires `value`");
|
|
166
|
+
valueAt(result, path);
|
|
167
|
+
result = removeValue(result, path).document;
|
|
168
|
+
result = addValue(result, path, structuredClone(operation["value"]));
|
|
169
|
+
break;
|
|
170
|
+
case "move": {
|
|
171
|
+
const from = operation["from"];
|
|
172
|
+
if (typeof from !== "string")
|
|
173
|
+
throw new InvalidError("JSON Patch move requires `from`");
|
|
174
|
+
if (path.startsWith(`${from}/`))
|
|
175
|
+
throw new InvalidError("JSON Patch cannot move a value into its child");
|
|
176
|
+
const removed = removeValue(result, from);
|
|
177
|
+
result = addValue(removed.document, path, removed.value);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "copy": {
|
|
181
|
+
const from = operation["from"];
|
|
182
|
+
if (typeof from !== "string")
|
|
183
|
+
throw new InvalidError("JSON Patch copy requires `from`");
|
|
184
|
+
result = addValue(result, path, structuredClone(valueAt(result, from)));
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case "test":
|
|
188
|
+
if (!("value" in operation))
|
|
189
|
+
throw new InvalidError("JSON Patch test requires `value`");
|
|
190
|
+
if (!equalJson(valueAt(result, path), operation["value"])) {
|
|
191
|
+
throw new InvalidError(`JSON Patch test failed at \`${path}\``);
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
throw new InvalidError(`unknown JSON Patch operation \`${op}\``);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
function chunkKind(envelope) {
|
|
201
|
+
if (envelope.operation === OPERATION_REASONING)
|
|
202
|
+
return "reasoning";
|
|
203
|
+
if (envelope.operation === OPERATION_TOOL_ARGS)
|
|
204
|
+
return "toolArgs";
|
|
205
|
+
return "chat";
|
|
206
|
+
}
|
|
207
|
+
function chunkEvents(envelope, kind) {
|
|
208
|
+
const id = envelope.channel?.toString() ?? "";
|
|
209
|
+
const body = new TextDecoder().decode(envelope.body);
|
|
210
|
+
const opening = envelope.sequence === 0n;
|
|
211
|
+
const events = [];
|
|
212
|
+
if (kind === "chat") {
|
|
213
|
+
if (opening)
|
|
214
|
+
events.push({ type: "TEXT_MESSAGE_START", messageId: id, role: "assistant" });
|
|
215
|
+
if (body.length > 0)
|
|
216
|
+
events.push({ type: "TEXT_MESSAGE_CONTENT", messageId: id, delta: body });
|
|
217
|
+
if (envelope.last)
|
|
218
|
+
events.push({ type: "TEXT_MESSAGE_END", messageId: id });
|
|
219
|
+
}
|
|
220
|
+
else if (kind === "reasoning") {
|
|
221
|
+
if (opening)
|
|
222
|
+
events.push({ type: "REASONING_MESSAGE_START", messageId: id, role: "reasoning" });
|
|
223
|
+
if (body.length > 0)
|
|
224
|
+
events.push({ type: "REASONING_MESSAGE_CONTENT", messageId: id, delta: body });
|
|
225
|
+
if (envelope.last)
|
|
226
|
+
events.push({ type: "REASONING_MESSAGE_END", messageId: id });
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if (opening)
|
|
230
|
+
events.push({ type: "TOOL_CALL_START", toolCallId: id, toolCallName: envelope.tool ?? "" });
|
|
231
|
+
if (body.length > 0)
|
|
232
|
+
events.push({ type: "TOOL_CALL_ARGS", toolCallId: id, delta: body });
|
|
233
|
+
if (envelope.last)
|
|
234
|
+
events.push({ type: "TOOL_CALL_END", toolCallId: id });
|
|
235
|
+
}
|
|
236
|
+
return events;
|
|
237
|
+
}
|
|
238
|
+
export function envelopeToAgUi(envelope) {
|
|
239
|
+
if (envelope.kind === AgentKind.Status && envelope.operation === OPERATION_TASK) {
|
|
240
|
+
const threadId = envelope.conversation.toString();
|
|
241
|
+
const runId = envelope.correlation?.toString() ?? "";
|
|
242
|
+
if (envelope.taskState?.kind === "known" && envelope.taskState.name === "Submitted") {
|
|
243
|
+
return [{ type: "RUN_STARTED", threadId, runId }];
|
|
244
|
+
}
|
|
245
|
+
if (envelope.taskState !== undefined && taskStateIsTerminal(envelope.taskState)) {
|
|
246
|
+
return [{ type: "RUN_FINISHED", threadId, runId }];
|
|
247
|
+
}
|
|
248
|
+
return [];
|
|
249
|
+
}
|
|
250
|
+
if ((envelope.kind === AgentKind.Response || envelope.kind === AgentKind.Error) &&
|
|
251
|
+
envelope.tool !== undefined) {
|
|
252
|
+
return [
|
|
253
|
+
{
|
|
254
|
+
type: "TOOL_CALL_RESULT",
|
|
255
|
+
toolCallId: envelope.correlation?.toString() ?? "",
|
|
256
|
+
content: new TextDecoder().decode(envelope.body)
|
|
257
|
+
}
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
if (envelope.kind === AgentKind.Error) {
|
|
261
|
+
return [{ type: "RUN_ERROR", message: new TextDecoder().decode(envelope.body) }];
|
|
262
|
+
}
|
|
263
|
+
if (envelope.kind === AgentKind.Event && envelope.operation === OPERATION_STATE_SNAPSHOT) {
|
|
264
|
+
try {
|
|
265
|
+
return [{ type: "STATE_SNAPSHOT", snapshot: parseJson(envelope.body, "state snapshot") }];
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (envelope.kind === AgentKind.Event && envelope.operation === OPERATION_STATE_DELTA) {
|
|
272
|
+
try {
|
|
273
|
+
return [{ type: "STATE_DELTA", delta: parseJson(envelope.body, "state delta") }];
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return [];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
281
|
+
export function envelopesToAgUi(envelopes) {
|
|
282
|
+
const channels = new Map();
|
|
283
|
+
const events = [];
|
|
284
|
+
for (const envelope of envelopes) {
|
|
285
|
+
if (envelope.kind !== AgentKind.Chunk) {
|
|
286
|
+
events.push(...envelopeToAgUi(envelope));
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const id = envelope.channel?.toString() ?? "";
|
|
290
|
+
const kind = envelope.sequence === 0n ? chunkKind(envelope) : (channels.get(id) ?? "chat");
|
|
291
|
+
if (envelope.sequence === 0n)
|
|
292
|
+
channels.set(id, kind);
|
|
293
|
+
events.push(...chunkEvents(envelope, kind));
|
|
294
|
+
}
|
|
295
|
+
return events;
|
|
296
|
+
}
|
|
297
|
+
export async function publishStateSnapshot(laser, topic, source, conversation, state) {
|
|
298
|
+
await laser
|
|
299
|
+
.agdx(topic, source, conversation)
|
|
300
|
+
.emit(jsonBytes(state, "state snapshot"))
|
|
301
|
+
.withOperation(OPERATION_STATE_SNAPSHOT)
|
|
302
|
+
.contentType(ContentType.Json)
|
|
303
|
+
.send();
|
|
304
|
+
}
|
|
305
|
+
export async function publishStateDelta(laser, topic, source, conversation, patch) {
|
|
306
|
+
if (!Array.isArray(patch))
|
|
307
|
+
throw new InvalidError("an AG-UI state delta must be a JSON Patch array");
|
|
308
|
+
await laser
|
|
309
|
+
.agdx(topic, source, conversation)
|
|
310
|
+
.emit(jsonBytes(patch, "state delta"))
|
|
311
|
+
.withOperation(OPERATION_STATE_DELTA)
|
|
312
|
+
.contentType(ContentType.Json)
|
|
313
|
+
.send();
|
|
314
|
+
}
|
|
315
|
+
export async function reconstructState(laser, conversation, topic) {
|
|
316
|
+
const messages = await laser.context(conversation).fetch([topic], Number.MAX_SAFE_INTEGER);
|
|
317
|
+
let state = undefined;
|
|
318
|
+
for (const message of messages) {
|
|
319
|
+
const envelope = message.envelope;
|
|
320
|
+
if (envelope?.kind !== AgentKind.Event)
|
|
321
|
+
continue;
|
|
322
|
+
if (envelope.operation === OPERATION_STATE_SNAPSHOT) {
|
|
323
|
+
state = parseJson(envelope.body, "state snapshot");
|
|
324
|
+
}
|
|
325
|
+
else if (envelope.operation === OPERATION_STATE_DELTA && state !== undefined) {
|
|
326
|
+
state = applyJsonPatch(state, parseJson(envelope.body, "state delta"));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return state;
|
|
330
|
+
}
|
|
331
|
+
export async function aguiEvents(laser, conversation, topic) {
|
|
332
|
+
const messages = await laser.context(conversation).fetch([topic], Number.MAX_SAFE_INTEGER);
|
|
333
|
+
return envelopesToAgUi(messages.flatMap((message) => (message.envelope === undefined ? [] : [message.envelope])));
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=agui.js.map
|