@copilotkit/runtime 1.66.2 → 1.66.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/dist/agent/converters/aisdk.cjs +17 -9
- package/dist/agent/converters/aisdk.cjs.map +1 -1
- package/dist/agent/converters/aisdk.d.cts +1 -1
- package/dist/agent/converters/aisdk.d.cts.map +1 -1
- package/dist/agent/converters/aisdk.d.mts +1 -1
- package/dist/agent/converters/aisdk.d.mts.map +1 -1
- package/dist/agent/converters/aisdk.mjs +17 -9
- package/dist/agent/converters/aisdk.mjs.map +1 -1
- package/dist/agent/converters/tanstack.cjs +17 -9
- package/dist/agent/converters/tanstack.cjs.map +1 -1
- package/dist/agent/converters/tanstack.d.cts +1 -1
- package/dist/agent/converters/tanstack.d.cts.map +1 -1
- package/dist/agent/converters/tanstack.d.mts +1 -1
- package/dist/agent/converters/tanstack.d.mts.map +1 -1
- package/dist/agent/converters/tanstack.mjs +17 -9
- package/dist/agent/converters/tanstack.mjs.map +1 -1
- package/dist/agent/index.cjs +6 -4
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +6 -4
- package/dist/agent/index.mjs.map +1 -1
- package/dist/agent/state-delta.cjs +322 -0
- package/dist/agent/state-delta.cjs.map +1 -0
- package/dist/agent/state-delta.mjs +321 -0
- package/dist/agent/state-delta.mjs.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/runtime/package.mjs +1 -1
- package/dist/v2/index.cjs +6 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/runtime/core/channel-manager.cjs +110 -9
- package/dist/v2/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.cts +79 -8
- package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.d.mts +79 -8
- package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -1
- package/dist/v2/runtime/core/channel-manager.mjs +110 -9
- package/dist/v2/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +1 -0
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +1 -0
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +2 -5
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +2 -5
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.cjs +23 -0
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.mjs +22 -0
- package/dist/v2/runtime/handlers/shared/mcp-apps-servers.mjs.map +1 -0
- package/dist/v2/runtime/index.d.cts +1 -1
- package/dist/v2/runtime/index.d.mts +1 -1
- package/dist/v2/runtime/open-generative-ui-middleware.cjs +1 -0
- package/dist/v2/runtime/open-generative-ui-middleware.cjs.map +1 -1
- package/dist/v2/runtime/open-generative-ui-middleware.mjs +1 -0
- package/dist/v2/runtime/open-generative-ui-middleware.mjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.cjs +335 -101
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.cts +246 -6
- package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.mts +246 -6
- package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.mjs +331 -102
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
- package/dist/v2/runtime/runner/index.d.cts +1 -1
- package/dist/v2/runtime/runner/index.d.mts +1 -1
- package/dist/v2/runtime/runner/index.mjs +1 -1
- package/package.json +6 -6
- package/skills/runtime/references/agent-runners-in-memory.md +49 -34
- package/skills/runtime/references/agent-runners.md +47 -21
- package/skills/runtime/references/wiring-mcp-apps-middleware.md +5 -0
|
@@ -9,11 +9,21 @@ import { AbstractAgent, Message } from "@ag-ui/client";
|
|
|
9
9
|
* Lifecycle status of a single Channel activation, or of the manager overall.
|
|
10
10
|
*
|
|
11
11
|
* - `connecting`: activation in flight, not yet settled.
|
|
12
|
-
* - `online`: activation resolved
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* - `online`: activation resolved, the managed session can currently send, AND
|
|
13
|
+
* the gateway did not report the Channel as missing a managed provider. A drop
|
|
14
|
+
* moves the Channel to `reconnecting` (not `online`); a successful rejoin
|
|
15
|
+
* restores `online`.
|
|
15
16
|
* - `setup_required`: the Channel is declared but has no managed provider yet —
|
|
16
|
-
* a valid degraded state, not a failure.
|
|
17
|
+
* a valid degraded state, not a failure. Reached when the gateway reports the
|
|
18
|
+
* provider as unattached/disabled/undeclared on the control join reply (see
|
|
19
|
+
* {@link ChannelLegs}), or when the activation engine throws a
|
|
20
|
+
* `SETUP_REQUIRED` error.
|
|
21
|
+
*
|
|
22
|
+
* NOTE: between the 2026-07-29 realtime-boundary cutover and the introduction
|
|
23
|
+
* of {@link ChannelLegs}, this state had NO producer — the engine stopped
|
|
24
|
+
* classifying it and nothing else set it, so a Channel with no Slack app at
|
|
25
|
+
* all reported `online`. Do not reintroduce a code path that describes
|
|
26
|
+
* `setup_required` without one that can actually emit it.
|
|
17
27
|
* - `reconnecting`: the managed session dropped and Phoenix is retrying — not
|
|
18
28
|
* currently sendable. The manager does NOT re-activate (reconnection is
|
|
19
29
|
* delegated to the Phoenix connection layer); it only reflects the health the
|
|
@@ -28,23 +38,70 @@ import { AbstractAgent, Message } from "@ag-ui/client";
|
|
|
28
38
|
* provider output.
|
|
29
39
|
*/
|
|
30
40
|
type ChannelStatus = "connecting" | "online" | "setup_required" | "reconnecting" | "stopped" | "error";
|
|
41
|
+
/**
|
|
42
|
+
* Managed provider attachment state for one Channel, as reported by the gateway
|
|
43
|
+
* on the control join reply.
|
|
44
|
+
*
|
|
45
|
+
* `unknown` is this package's own value for "the gateway did not tell us" — a
|
|
46
|
+
* gateway predating the provider-state contract, one whose lookup failed, or a
|
|
47
|
+
* non-gateway handle. It must never be read as "no provider attached".
|
|
48
|
+
*/
|
|
49
|
+
type ChannelProviderLeg = "attached" | "unhealthy" | "not_attached" | "disabled" | "channel_not_declared" | "unknown";
|
|
50
|
+
/**
|
|
51
|
+
* The two independent things that have to be true for a managed Channel to
|
|
52
|
+
* work, reported separately so a caller can assert the one it cares about.
|
|
53
|
+
*
|
|
54
|
+
* `status` is the fold of the two and matches this Channel's entry in
|
|
55
|
+
* {@link ChannelsControl.status}'s `channels` map.
|
|
56
|
+
*
|
|
57
|
+
* The legs exist because they are genuinely separable: the control socket can be
|
|
58
|
+
* joined and sendable while no Slack/Teams app is bound to the Channel at all.
|
|
59
|
+
* Before they were split, `overall: "online"` proved only the socket, and
|
|
60
|
+
* onboarding guidance used it to certify end-to-end success.
|
|
61
|
+
*/
|
|
62
|
+
interface ChannelLegs {
|
|
63
|
+
/** Fold of {@link transport} and {@link provider}. */
|
|
64
|
+
status: ChannelStatus;
|
|
65
|
+
/** Runtime ⇄ Gateway control socket for this Channel. */
|
|
66
|
+
transport: ChannelStatus;
|
|
67
|
+
/** Whether a managed provider is bound to this Channel. */
|
|
68
|
+
provider: ChannelProviderLeg;
|
|
69
|
+
}
|
|
31
70
|
/**
|
|
32
71
|
* The lifecycle control surface a Channel host uses to drive and observe
|
|
33
72
|
* managed Channel activation.
|
|
34
73
|
*/
|
|
35
74
|
interface ChannelsControl {
|
|
36
75
|
/**
|
|
37
|
-
* Resolve once every declared Channel has settled
|
|
38
|
-
*
|
|
39
|
-
* or — when `timeoutMs` is given — if the whole set has not settled
|
|
76
|
+
* Resolve once every declared Channel has settled its ACTIVATION — that is,
|
|
77
|
+
* each Channel either activated or failed to. Rejects if any Channel failed to
|
|
78
|
+
* activate, or — when `timeoutMs` is given — if the whole set has not settled
|
|
79
|
+
* in time.
|
|
80
|
+
*
|
|
81
|
+
* Readiness is about activation, NOT about provider health: a Channel whose
|
|
82
|
+
* transport joined but whose provider leg is `unhealthy` folds to a status of
|
|
83
|
+
* `error` (see {@link foldChannelLegs}) while its activation settled normally.
|
|
84
|
+
* So `ready()` resolving and `status().overall === "error"` can both be true at
|
|
85
|
+
* once, by design — provider attachment is the Gateway's answer to a question
|
|
86
|
+
* asked after activation, and it can change at any later rejoin. Assert
|
|
87
|
+
* end-to-end reachability with {@link ChannelsControl.status}, not here.
|
|
40
88
|
*/
|
|
41
89
|
ready(opts?: {
|
|
42
90
|
timeoutMs?: number;
|
|
43
91
|
}): Promise<void>;
|
|
44
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Snapshot the overall status, the per-Channel status map, and the per-Channel
|
|
94
|
+
* transport/provider legs.
|
|
95
|
+
*
|
|
96
|
+
* `overall === "online"` does NOT by itself prove a Channel can receive
|
|
97
|
+
* provider traffic unless the provider leg is `attached`: read `detail` when
|
|
98
|
+
* you need to assert that a Channel is genuinely reachable from Slack/Teams,
|
|
99
|
+
* because a `provider` of `unknown` leaves `status` transport-derived.
|
|
100
|
+
*/
|
|
45
101
|
status(): {
|
|
46
102
|
overall: ChannelStatus;
|
|
47
103
|
channels: Record<string, ChannelStatus>;
|
|
104
|
+
detail: Record<string, ChannelLegs>;
|
|
48
105
|
};
|
|
49
106
|
/** Tear down every activated Channel. Idempotent. */
|
|
50
107
|
stop(): Promise<void>;
|
|
@@ -88,6 +145,20 @@ interface ChannelsHandle {
|
|
|
88
145
|
reason?: string;
|
|
89
146
|
code?: string;
|
|
90
147
|
}) => void): void;
|
|
148
|
+
/**
|
|
149
|
+
* Optional seam: managed provider attachment state per declared Channel, as
|
|
150
|
+
* reported on the newest gateway control join reply.
|
|
151
|
+
*
|
|
152
|
+
* A getter, so each read reflects the current join reply — the gateway's join
|
|
153
|
+
* hooks re-fire on every auto-rejoin, so a Channel provisioned while the
|
|
154
|
+
* runtime was disconnected is picked up without re-activating.
|
|
155
|
+
*
|
|
156
|
+
* `undefined` (or an absent method) means "not reported", NOT "no provider".
|
|
157
|
+
* A gateway predating this contract, a gateway whose database read failed, and
|
|
158
|
+
* a non-gateway/test handle all land here, and all must fall back to
|
|
159
|
+
* transport-only status rather than claim a Channel is unprovisioned.
|
|
160
|
+
*/
|
|
161
|
+
providerStates?(): Readonly<Record<string, string>> | undefined;
|
|
91
162
|
}
|
|
92
163
|
//#endregion
|
|
93
164
|
export { ActivateChannelEngine, ChannelStatus, ChannelsControl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-manager.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/channel-manager.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"channel-manager.d.mts","names":[],"sources":["../../../../src/v2/runtime/core/channel-manager.ts"],"mappings":";;;;;;;AA+DA;;;;;AAgBA;;;;;AAoBA;;;;;;;;;;;;;;;;AA6EA;;;;;;AAjHA,KAAY,aAAA;;;;;;;;;KAgBA,kBAAA;;;;;;;;;;;;;UAoBK,WAAA;EA6IL;EA3IV,MAAA,EAAQ,aAAA;;EAER,SAAA,EAAW,aAAA;EA2IF;EAzIT,QAAA,EAAU,kBAAA;AAAA;;;;;UAuEK,eAAA;EAmGb;;;;;;;;;;;;;;EApFF,KAAA,CAAM,IAAA;IAAS,SAAA;EAAA,IAAuB,OAAA;;;;;;;;;;EAUtC,MAAA;IACE,OAAA,EAAS,aAAA;IACT,QAAA,EAAU,MAAA,SAAe,aAAA;IACzB,MAAA,EAAQ,MAAA,SAAe,WAAA;EAAA;;EAGzB,IAAA,IAAQ,OAAA;AAAA;;;;;;KAiCE,qBAAA,IACV,MAAA,EAAQ,uBAAA,EACR,OAAA,EAAS,eAAA,CAAA,OAAA,KACN,OAAA,CAAQ,cAAA;;;;;;;;UASI,cAAA;;EAEf,QAAA;;EAEA,IAAA,IAAQ,OAAA;;;;;;;EAOR,OAAA,EAAS,EAAA;;;;;;;;;;;EAWT,aAAA,EACE,EAAA,GACE,KAAA,yCACA,MAAA;IAAW,MAAA;IAAiB,IAAA;EAAA;;;;;;;;;;;;;;EAgBhC,cAAA,KAAmB,QAAA,CAAS,MAAA;AAAA"}
|
|
@@ -8,6 +8,60 @@ import { MCPMiddleware } from "@ag-ui/mcp-middleware";
|
|
|
8
8
|
|
|
9
9
|
//#region src/v2/runtime/core/channel-manager.ts
|
|
10
10
|
/**
|
|
11
|
+
* Recognised provider states, used to validate what crosses the seam.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately duplicates `PROVIDER_STATES` in
|
|
14
|
+
* `@copilotkit/channels-intelligence`'s `realtime-gateway.ts` rather than
|
|
15
|
+
* importing it: this package must not take a static dependency on
|
|
16
|
+
* channels-intelligence (it is reached only through a dynamic import), so the
|
|
17
|
+
* `providerStates` seam is duck-typed as `Record<string, string>`.
|
|
18
|
+
*
|
|
19
|
+
* A state added there needs adding here too, plus a `case` in
|
|
20
|
+
* {@link foldChannelLegs}. Until both land it fails OPEN — an unrecognised state
|
|
21
|
+
* becomes `unknown` and the Channel keeps its transport-derived status, rather
|
|
22
|
+
* than being wrongly certified or condemned.
|
|
23
|
+
*/
|
|
24
|
+
const PROVIDER_LEGS = new Set([
|
|
25
|
+
"attached",
|
|
26
|
+
"unhealthy",
|
|
27
|
+
"not_attached",
|
|
28
|
+
"disabled",
|
|
29
|
+
"channel_not_declared"
|
|
30
|
+
]);
|
|
31
|
+
/**
|
|
32
|
+
* Fold a Channel's transport and provider legs into its single status.
|
|
33
|
+
*
|
|
34
|
+
* The transport leg dominates whenever it is not `online`: while the control
|
|
35
|
+
* socket is connecting, retrying, stopped, or failed, whatever the gateway last
|
|
36
|
+
* said about the provider is stale or irrelevant — the Channel cannot serve a
|
|
37
|
+
* turn either way, and reporting `setup_required` for a Channel that is actually
|
|
38
|
+
* mid-reconnect would hide the outage.
|
|
39
|
+
*
|
|
40
|
+
* Once the transport is `online` the provider leg decides, which is the whole
|
|
41
|
+
* point of the split: a joined socket with no provider bound is
|
|
42
|
+
* `setup_required`, not `online`.
|
|
43
|
+
*
|
|
44
|
+
* `unknown` keeps the transport-derived answer. That is what makes an older
|
|
45
|
+
* gateway (or a gateway whose lookup failed) behave exactly as it did before
|
|
46
|
+
* provider states existed, instead of turning every Channel into
|
|
47
|
+
* `setup_required`.
|
|
48
|
+
*
|
|
49
|
+
* @param transport - Control-socket status for the Channel.
|
|
50
|
+
* @param provider - Reported provider attachment state.
|
|
51
|
+
* @returns The folded Channel status.
|
|
52
|
+
*/
|
|
53
|
+
function foldChannelLegs(transport, provider) {
|
|
54
|
+
if (transport !== "online") return transport;
|
|
55
|
+
switch (provider) {
|
|
56
|
+
case "attached":
|
|
57
|
+
case "unknown": return "online";
|
|
58
|
+
case "unhealthy": return "error";
|
|
59
|
+
case "not_attached":
|
|
60
|
+
case "disabled":
|
|
61
|
+
case "channel_not_declared": return "setup_required";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
11
65
|
* Signals that a declared Channel cannot be activated because no managed
|
|
12
66
|
* provider exists for it yet. The engine throws this (or any error whose
|
|
13
67
|
* `code === "SETUP_REQUIRED"`) to move a Channel to `setup_required` rather
|
|
@@ -615,31 +669,78 @@ var ChannelManager = class {
|
|
|
615
669
|
* Snapshot status. Every declared Channel appears keyed by name in
|
|
616
670
|
* `channels` after its combined adapter lifecycle starts.
|
|
617
671
|
*
|
|
672
|
+
* Each Channel's entry is the fold of its transport and provider legs (see
|
|
673
|
+
* {@link foldChannelLegs}), and `detail` reports those legs separately so a
|
|
674
|
+
* caller can assert the one it cares about.
|
|
675
|
+
*
|
|
618
676
|
* `overall` is folded over ALL declared Channels (see {@link computeOverall}),
|
|
619
677
|
* by precedence `error` > `reconnecting` > `setup_required` > `connecting` >
|
|
620
|
-
* `online`. `online` means every Channel can currently send
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* is degraded); once every Channel has
|
|
678
|
+
* `online`. `online` means every Channel can currently send AND none was
|
|
679
|
+
* reported as missing its managed provider. `reconnecting` outranks
|
|
680
|
+
* `setup_required` because a dropped-but-retrying Channel is an active outage,
|
|
681
|
+
* louder than a steadily-degraded unprovisioned one. With no declared Channels
|
|
682
|
+
* at all, `overall` is `online` (nothing is degraded); once every Channel has
|
|
683
|
+
* been stopped, `overall` is `stopped`.
|
|
684
|
+
*
|
|
685
|
+
* `overall === "online"` is only end-to-end proof when every Channel's
|
|
686
|
+
* `provider` leg is `attached`. A gateway that reports no provider state leaves
|
|
687
|
+
* the legs `unknown` and `overall` transport-derived, exactly as before this
|
|
688
|
+
* contract existed — so a caller that must be certain checks `detail`.
|
|
625
689
|
*/
|
|
626
690
|
status() {
|
|
627
691
|
const channels = {};
|
|
628
|
-
|
|
692
|
+
const detail = {};
|
|
693
|
+
for (const [name, entry] of this.entries) {
|
|
694
|
+
const transport = entry.status;
|
|
695
|
+
const provider = this.providerLeg(name, entry);
|
|
696
|
+
const status = foldChannelLegs(transport, provider);
|
|
697
|
+
channels[name] = status;
|
|
698
|
+
detail[name] = {
|
|
699
|
+
status,
|
|
700
|
+
transport,
|
|
701
|
+
provider
|
|
702
|
+
};
|
|
703
|
+
}
|
|
629
704
|
if (this.stopped) return {
|
|
630
705
|
overall: "stopped",
|
|
631
|
-
channels
|
|
706
|
+
channels,
|
|
707
|
+
detail
|
|
632
708
|
};
|
|
633
709
|
if (!this.activated && this.channels.length > 0) return {
|
|
634
710
|
overall: "connecting",
|
|
635
|
-
channels
|
|
711
|
+
channels,
|
|
712
|
+
detail
|
|
636
713
|
};
|
|
637
714
|
return {
|
|
638
715
|
overall: this.computeOverall(Object.values(channels)),
|
|
639
|
-
channels
|
|
716
|
+
channels,
|
|
717
|
+
detail
|
|
640
718
|
};
|
|
641
719
|
}
|
|
642
720
|
/**
|
|
721
|
+
* Read one Channel's provider leg from its handle.
|
|
722
|
+
*
|
|
723
|
+
* Defensive on every axis, because a wrong answer here silently changes what
|
|
724
|
+
* `status()` certifies: a handle without the seam, a gateway that reported
|
|
725
|
+
* nothing, a name the gateway did not mention, an unrecognised value, or a
|
|
726
|
+
* throwing getter all yield `unknown` — which {@link foldChannelLegs} treats as
|
|
727
|
+
* "keep the transport-derived status", i.e. pre-provider-state behaviour.
|
|
728
|
+
*
|
|
729
|
+
* @param name - The Channel name (map key).
|
|
730
|
+
* @param entry - The Channel's activation entry.
|
|
731
|
+
* @returns The provider leg, or `"unknown"` when it cannot be established.
|
|
732
|
+
*/
|
|
733
|
+
providerLeg(name, entry) {
|
|
734
|
+
let states;
|
|
735
|
+
try {
|
|
736
|
+
states = entry.handle?.providerStates?.();
|
|
737
|
+
} catch {
|
|
738
|
+
return "unknown";
|
|
739
|
+
}
|
|
740
|
+
const reported = states?.[name];
|
|
741
|
+
return reported !== void 0 && PROVIDER_LEGS.has(reported) ? reported : "unknown";
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
643
744
|
* Fold per-Channel statuses into a single overall status (see {@link status}).
|
|
644
745
|
*
|
|
645
746
|
* Every declared Channel participates. Statuses are ranked
|