@copilotkit/core 1.80.0 → 1.82.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/dist/index.cjs +1411 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +422 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +422 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1403 -8
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1415 -7
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -1515,7 +1515,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1515
1515
|
__copilotkitMcpResourceReadOnly: true
|
|
1516
1516
|
}
|
|
1517
1517
|
};
|
|
1518
|
-
|
|
1518
|
+
if (this.runtimeMode !== _copilotkit_shared.RUNTIME_MODE_INTELLIGENCE) return this.runAgent(resourceParameters);
|
|
1519
|
+
const resourceAgent = this.clone();
|
|
1520
|
+
resourceAgent.pendingInterrupts = [];
|
|
1521
|
+
return resourceAgent.runAgent(resourceParameters);
|
|
1519
1522
|
}
|
|
1520
1523
|
/**
|
|
1521
1524
|
* Drop the delegate's cached `lastSeenEventId` for this thread so
|
|
@@ -3206,6 +3209,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3206
3209
|
}
|
|
3207
3210
|
};
|
|
3208
3211
|
|
|
3212
|
+
//#endregion
|
|
3213
|
+
//#region src/core/agent-scope.ts
|
|
3214
|
+
/**
|
|
3215
|
+
* True when an entry scoped to `agentIds` goes to a run of `agentId`. An
|
|
3216
|
+
* entry without `agentIds` goes to every agent; an entry with them does not
|
|
3217
|
+
* go to a run without an agent id. Internal, not exported.
|
|
3218
|
+
*/
|
|
3219
|
+
function isForAgent(agentIds, agentId) {
|
|
3220
|
+
return agentIds === void 0 || agentId !== void 0 && agentIds.includes(agentId);
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3209
3223
|
//#endregion
|
|
3210
3224
|
//#region src/core/context-store.ts
|
|
3211
3225
|
/**
|
|
@@ -3244,7 +3258,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3244
3258
|
* protocol-shaped `{ description, value }` entries go over the wire.
|
|
3245
3259
|
*/
|
|
3246
3260
|
getContextForAgent(agentId) {
|
|
3247
|
-
return Object.values(this._context).filter((entry) =>
|
|
3261
|
+
return Object.values(this._context).filter((entry) => isForAgent(entry.agentIds, agentId)).map(({ description, value }) => ({
|
|
3248
3262
|
description,
|
|
3249
3263
|
value
|
|
3250
3264
|
}));
|
|
@@ -3435,7 +3449,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3435
3449
|
await suggestionAgent.runAgent({
|
|
3436
3450
|
context: friends.getContextForAgent(consumerAgentId),
|
|
3437
3451
|
forwardedProps: {
|
|
3438
|
-
...friends.
|
|
3452
|
+
...friends.getPropertiesForAgent(consumerAgentId),
|
|
3439
3453
|
toolChoice: {
|
|
3440
3454
|
type: "function",
|
|
3441
3455
|
function: { name: "copilotkitSuggest" }
|
|
@@ -3885,6 +3899,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3885
3899
|
var _liveHITLStops$get;
|
|
3886
3900
|
return !!(discardOnAbort && (signal === null || signal === void 0 ? void 0 : signal.aborted) && !(((_liveHITLStops$get = liveHITLStops.get(signal)) === null || _liveHITLStops$get === void 0 ? void 0 : _liveHITLStops$get()) && errorMessage));
|
|
3887
3901
|
}
|
|
3902
|
+
/** How many recent runs keep their request ID for a later approval resume. */
|
|
3903
|
+
const MAX_REMEMBERED_REQUEST_IDS = 100;
|
|
3888
3904
|
/**
|
|
3889
3905
|
* Absolute safety cap on the depth of recursive follow-up runs triggered by
|
|
3890
3906
|
* `processAgentResult`. Without this, any scenario that keeps
|
|
@@ -3921,6 +3937,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3921
3937
|
_defineProperty(this, "_runAbortControllers", /* @__PURE__ */ new WeakMap());
|
|
3922
3938
|
_defineProperty(this, "_runDepths", /* @__PURE__ */ new WeakMap());
|
|
3923
3939
|
_defineProperty(this, "_originalAbortRuns", /* @__PURE__ */ new WeakMap());
|
|
3940
|
+
_defineProperty(this, "_activeRequestIds", /* @__PURE__ */ new WeakMap());
|
|
3941
|
+
_defineProperty(this, "_requestIdByRun", /* @__PURE__ */ new Map());
|
|
3924
3942
|
_defineProperty(this, "_webmcpRegistry", new WebMCPRegistry());
|
|
3925
3943
|
_defineProperty(this, "_lastConnectedThreadIdsByAgent", /* @__PURE__ */ new Map());
|
|
3926
3944
|
_defineProperty(this, "_lastActiveThreadIdsByAgent", /* @__PURE__ */ new Map());
|
|
@@ -4155,7 +4173,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4155
4173
|
newMessages: []
|
|
4156
4174
|
};
|
|
4157
4175
|
const runAgentResult = await agent.connectAgent({
|
|
4158
|
-
forwardedProps: this._internal.
|
|
4176
|
+
forwardedProps: this._internal.getPropertiesForAgent(agent.agentId),
|
|
4159
4177
|
tools: this.buildFrontendTools(agent.agentId),
|
|
4160
4178
|
context: this._internal.getContextForAgent(agent.agentId)
|
|
4161
4179
|
}, this.createAgentErrorSubscriber(agent));
|
|
@@ -4208,7 +4226,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4208
4226
|
* Run an agent
|
|
4209
4227
|
*/
|
|
4210
4228
|
async runAgent({ agent, forwardedProps, resume, runId }, continuationHandoff, followUpOf) {
|
|
4211
|
-
var _this$_runDepths$get;
|
|
4229
|
+
var _this$_runDepths$get, _ref2, _ref3;
|
|
4212
4230
|
if (agent.agentId) this._internal.suggestionEngine.clearSuggestions(agent.agentId);
|
|
4213
4231
|
try {
|
|
4214
4232
|
const headersApplied = this._internal.prepareAgentHeadersForRun(agent);
|
|
@@ -4236,6 +4254,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4236
4254
|
const controller = followUpOf !== null && followUpOf !== void 0 ? followUpOf : new AbortController();
|
|
4237
4255
|
const depth = (_this$_runDepths$get = this._runDepths.get(agent)) !== null && _this$_runDepths$get !== void 0 ? _this$_runDepths$get : 0;
|
|
4238
4256
|
this._runDepths.set(agent, depth + 1);
|
|
4257
|
+
const continuedRunId = resumedRunId !== null && resumedRunId !== void 0 ? resumedRunId : continuationHandoff ? runId : void 0;
|
|
4258
|
+
const requestId = (_ref2 = (_ref3 = continuationHandoff ? this._activeRequestIds.get(agent) : void 0) !== null && _ref3 !== void 0 ? _ref3 : continuedRunId !== void 0 ? this._requestIdByRun.get(continuedRunId) : void 0) !== null && _ref2 !== void 0 ? _ref2 : (0, _copilotkit_shared.randomUUID)();
|
|
4239
4259
|
if (!isFollowUp) {
|
|
4240
4260
|
var _this$_runAbortContro3;
|
|
4241
4261
|
const controllers = (_this$_runAbortContro3 = this._runAbortControllers.get(agent)) !== null && _this$_runAbortContro3 !== void 0 ? _this$_runAbortContro3 : /* @__PURE__ */ new Set();
|
|
@@ -4250,6 +4270,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4250
4270
|
originalAbortRun.call(agent);
|
|
4251
4271
|
};
|
|
4252
4272
|
}
|
|
4273
|
+
const previousRequestId = this._activeRequestIds.get(agent);
|
|
4274
|
+
this._activeRequestIds.set(agent, requestId);
|
|
4253
4275
|
try {
|
|
4254
4276
|
if (depth === 0) await this._internal.notifySubscribers((subscriber) => {
|
|
4255
4277
|
var _subscriber$onAgentRu2;
|
|
@@ -4276,8 +4298,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4276
4298
|
const pinRunIdOnWire = runId !== void 0 && !continuationHandoff;
|
|
4277
4299
|
const agentRunInput = {
|
|
4278
4300
|
forwardedProps: {
|
|
4279
|
-
...this._internal.
|
|
4280
|
-
...forwardedProps
|
|
4301
|
+
...this._internal.getPropertiesForAgent(agent.agentId),
|
|
4302
|
+
...forwardedProps,
|
|
4303
|
+
__copilotkitRequestId: requestId
|
|
4281
4304
|
},
|
|
4282
4305
|
...resume !== void 0 ? { resume } : {},
|
|
4283
4306
|
...pinRunIdOnWire ? { runId } : {},
|
|
@@ -4286,6 +4309,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4286
4309
|
};
|
|
4287
4310
|
const runAgentResult = await agent.runAgent(agentRunInput, agentSubscriber);
|
|
4288
4311
|
if (!started) logicalHandoff === null || logicalHandoff === void 0 || logicalHandoff.cancel();
|
|
4312
|
+
if (logicalRunId !== void 0) this.rememberRequestId(logicalRunId, requestId);
|
|
4289
4313
|
return await this.processAgentResult({
|
|
4290
4314
|
runAgentResult,
|
|
4291
4315
|
agent,
|
|
@@ -4322,6 +4346,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4322
4346
|
this._originalAbortRuns.delete(agent);
|
|
4323
4347
|
}
|
|
4324
4348
|
}
|
|
4349
|
+
if (previousRequestId === void 0) this._activeRequestIds.delete(agent);
|
|
4350
|
+
else this._activeRequestIds.set(agent, previousRequestId);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
rememberRequestId(runId, requestId) {
|
|
4354
|
+
this._requestIdByRun.delete(runId);
|
|
4355
|
+
this._requestIdByRun.set(runId, requestId);
|
|
4356
|
+
if (this._requestIdByRun.size > MAX_REMEMBERED_REQUEST_IDS) {
|
|
4357
|
+
const oldest = this._requestIdByRun.keys().next().value;
|
|
4358
|
+
if (oldest !== void 0) this._requestIdByRun.delete(oldest);
|
|
4325
4359
|
}
|
|
4326
4360
|
}
|
|
4327
4361
|
/**
|
|
@@ -7315,6 +7349,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
7315
7349
|
|
|
7316
7350
|
//#endregion
|
|
7317
7351
|
//#region src/core/core.ts
|
|
7352
|
+
/** True for an object literal. Arrays, `null`, and class instances are not plain objects. */
|
|
7353
|
+
function isPlainObject(value) {
|
|
7354
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
7355
|
+
}
|
|
7318
7356
|
let CopilotKitCoreErrorCode = /* @__PURE__ */ function(CopilotKitCoreErrorCode) {
|
|
7319
7357
|
CopilotKitCoreErrorCode["RUNTIME_INFO_FETCH_FAILED"] = "runtime_info_fetch_failed";
|
|
7320
7358
|
CopilotKitCoreErrorCode["AGENT_CONNECT_FAILED"] = "agent_connect_failed";
|
|
@@ -7381,6 +7419,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
7381
7419
|
_defineProperty(this, "_credentials", void 0);
|
|
7382
7420
|
_defineProperty(this, "_messageFilter", void 0);
|
|
7383
7421
|
_defineProperty(this, "_properties", void 0);
|
|
7422
|
+
_defineProperty(this, "_scopedProperties", /* @__PURE__ */ new Map());
|
|
7384
7423
|
_defineProperty(this, "_defaultThrottleMs", void 0);
|
|
7385
7424
|
_defineProperty(this, "_debug", void 0);
|
|
7386
7425
|
_defineProperty(this, "subscribers", /* @__PURE__ */ new Set());
|
|
@@ -7393,6 +7432,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
7393
7432
|
_defineProperty(this, "learningBridge", void 0);
|
|
7394
7433
|
_defineProperty(this, "notifiedTrajectoryId", null);
|
|
7395
7434
|
_defineProperty(this, "learningConfiguredListeners", /* @__PURE__ */ new Set());
|
|
7435
|
+
_defineProperty(this, "_generativeUIDebugSource", void 0);
|
|
7436
|
+
_defineProperty(this, "generativeUIDebugListeners", /* @__PURE__ */ new Set());
|
|
7396
7437
|
_defineProperty(this, "_memoryStore", void 0);
|
|
7397
7438
|
_defineProperty(this, "previousAgentIds", /* @__PURE__ */ new Set());
|
|
7398
7439
|
this.headerSource = new HeaderSourceResolver((error) => {
|
|
@@ -7719,6 +7760,59 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
7719
7760
|
this._messageFilter = messageFilter;
|
|
7720
7761
|
this.agentRegistry.applyMessageFilterToAgents(this.agentRegistry.agents);
|
|
7721
7762
|
}
|
|
7763
|
+
/**
|
|
7764
|
+
* Add run properties that go only to the runs of `agentIds`. When
|
|
7765
|
+
* `agentIds` is omitted, every agent gets them. They merge on top of the
|
|
7766
|
+
* base `properties`.
|
|
7767
|
+
*
|
|
7768
|
+
* When an entry value and the existing value under the same key are both
|
|
7769
|
+
* plain objects, their keys merge one level deep. So several entries can
|
|
7770
|
+
* add keys under one namespace (for example `copilotkit`).
|
|
7771
|
+
*
|
|
7772
|
+
* @param entry - The properties and the optional agent ids.
|
|
7773
|
+
* @returns The id to pass to `removeScopedProperties`.
|
|
7774
|
+
*
|
|
7775
|
+
* @example
|
|
7776
|
+
* const id = copilotkit.addScopedProperties({
|
|
7777
|
+
* properties: { copilotkit: { theme: "dark" } },
|
|
7778
|
+
* agentIds: ["research"],
|
|
7779
|
+
* });
|
|
7780
|
+
* copilotkit.removeScopedProperties(id);
|
|
7781
|
+
*/
|
|
7782
|
+
addScopedProperties({ properties, agentIds }) {
|
|
7783
|
+
let id = (0, _copilotkit_shared.randomUUID)();
|
|
7784
|
+
for (let n = 1; this._scopedProperties.has(id); n++) id = `${id}-${n}`;
|
|
7785
|
+
this._scopedProperties.set(id, {
|
|
7786
|
+
properties,
|
|
7787
|
+
...agentIds ? { agentIds } : {}
|
|
7788
|
+
});
|
|
7789
|
+
return id;
|
|
7790
|
+
}
|
|
7791
|
+
/** Remove an entry that `addScopedProperties` added. An unknown id does nothing. */
|
|
7792
|
+
removeScopedProperties(id) {
|
|
7793
|
+
this._scopedProperties.delete(id);
|
|
7794
|
+
}
|
|
7795
|
+
/**
|
|
7796
|
+
* Build the forwarded properties for a run of the given agent: the base
|
|
7797
|
+
* properties plus every scoped entry that matches the agent. An entry with
|
|
7798
|
+
* `agentIds` does not match when `agentId` is omitted.
|
|
7799
|
+
*/
|
|
7800
|
+
getPropertiesForAgent(agentId) {
|
|
7801
|
+
const merged = { ...this._properties };
|
|
7802
|
+
const entries = this._scopedProperties.values();
|
|
7803
|
+
for (const entry of entries) {
|
|
7804
|
+
if (!isForAgent(entry.agentIds, agentId)) continue;
|
|
7805
|
+
const properties = Object.entries(entry.properties);
|
|
7806
|
+
for (const [key, value] of properties) {
|
|
7807
|
+
const base = merged[key];
|
|
7808
|
+
merged[key] = isPlainObject(base) && isPlainObject(value) ? {
|
|
7809
|
+
...base,
|
|
7810
|
+
...value
|
|
7811
|
+
} : value;
|
|
7812
|
+
}
|
|
7813
|
+
}
|
|
7814
|
+
return merged;
|
|
7815
|
+
}
|
|
7722
7816
|
setProperties(properties) {
|
|
7723
7817
|
this._properties = properties;
|
|
7724
7818
|
this.notifySubscribers((subscriber) => {
|
|
@@ -7801,6 +7895,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
7801
7895
|
this.learningConfiguredListeners.delete(listener);
|
|
7802
7896
|
};
|
|
7803
7897
|
}
|
|
7898
|
+
/**
|
|
7899
|
+
* @internal The generative UI of the framework package, for the inspector.
|
|
7900
|
+
* `undefined` when no provider has a `generativeUI` config.
|
|
7901
|
+
*/
|
|
7902
|
+
get ɵgenerativeUIDebugSource() {
|
|
7903
|
+
return this._generativeUIDebugSource;
|
|
7904
|
+
}
|
|
7905
|
+
/** @internal Set by the framework package. `undefined` removes it. */
|
|
7906
|
+
ɵsetGenerativeUIDebugSource(source) {
|
|
7907
|
+
if (source === this._generativeUIDebugSource) return;
|
|
7908
|
+
this._generativeUIDebugSource = source;
|
|
7909
|
+
for (const listener of [...this.generativeUIDebugListeners]) try {
|
|
7910
|
+
listener();
|
|
7911
|
+
} catch (error) {
|
|
7912
|
+
console.error("Generative UI debug listener error:", error);
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
/** @internal Calls `listener` when {@link ɵgenerativeUIDebugSource} is set or removed. */
|
|
7916
|
+
ɵsubscribeToGenerativeUIDebugSource(listener) {
|
|
7917
|
+
this.generativeUIDebugListeners.add(listener);
|
|
7918
|
+
return () => {
|
|
7919
|
+
this.generativeUIDebugListeners.delete(listener);
|
|
7920
|
+
};
|
|
7921
|
+
}
|
|
7804
7922
|
/** The active capture's Trajectory ID, or null while capture is stopped. */
|
|
7805
7923
|
get trajectoryId() {
|
|
7806
7924
|
return this.learningBridge.trajectoryId;
|
|
@@ -9444,6 +9562,1287 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
9444
9562
|
}
|
|
9445
9563
|
|
|
9446
9564
|
//#endregion
|
|
9565
|
+
//#region src/a2ui-markdown/fence-parser.ts
|
|
9566
|
+
/** Language of a fenced code block that carries A2UI operations. */
|
|
9567
|
+
const A2UI_FENCE_LANGUAGE = "a2ui";
|
|
9568
|
+
/** Column-0 fence opener: a run of 3+ backticks or tildes, then the info string. */
|
|
9569
|
+
const FENCE_OPEN = /^(`{3,}|~{3,})(.*)$/;
|
|
9570
|
+
/** Info-string token that names the placement target of an a2ui fence. */
|
|
9571
|
+
const TARGET_TOKEN = /^target=(.+)$/;
|
|
9572
|
+
function isCloser(line, fence) {
|
|
9573
|
+
const trimmed = line.trim();
|
|
9574
|
+
if (trimmed.length < fence.length) return false;
|
|
9575
|
+
for (const ch of trimmed) if (ch !== fence.char) return false;
|
|
9576
|
+
return true;
|
|
9577
|
+
}
|
|
9578
|
+
/** The id of the first `target=<id>` token. Other tokens are ignored. */
|
|
9579
|
+
function readTarget(tokens) {
|
|
9580
|
+
for (const token of tokens) {
|
|
9581
|
+
const match = TARGET_TOKEN.exec(token);
|
|
9582
|
+
if (match) return match[1];
|
|
9583
|
+
}
|
|
9584
|
+
}
|
|
9585
|
+
function a2uiSegment(fence, text, closed) {
|
|
9586
|
+
const segment = {
|
|
9587
|
+
type: "a2ui",
|
|
9588
|
+
index: fence.index,
|
|
9589
|
+
text,
|
|
9590
|
+
closed
|
|
9591
|
+
};
|
|
9592
|
+
if (fence.target !== void 0) segment.target = fence.target;
|
|
9593
|
+
return segment;
|
|
9594
|
+
}
|
|
9595
|
+
/**
|
|
9596
|
+
* Split a (possibly still streaming) markdown string into prose segments and
|
|
9597
|
+
* top-level ```a2ui fences. Fences of other languages stay inside prose
|
|
9598
|
+
* segments byte-for-byte, and a2ui markers inside them are ignored. Only
|
|
9599
|
+
* column-0 fences are recognised, so a fence indented inside a list item is
|
|
9600
|
+
* left to the markdown renderer.
|
|
9601
|
+
*
|
|
9602
|
+
* The first info-string token must be exactly `a2ui`. A later
|
|
9603
|
+
* `target=<id>` token sets `target` on the segment (for example
|
|
9604
|
+
* ```` ```a2ui target=recommendations ````). Other tokens are ignored.
|
|
9605
|
+
*
|
|
9606
|
+
* An a2ui segment's `text` is the fence body. For a closed fence it ends with
|
|
9607
|
+
* "\n" when non-empty. For an open (still streaming or aborted) fence it is
|
|
9608
|
+
* everything after the opener line, minus a half-streamed closing marker.
|
|
9609
|
+
*
|
|
9610
|
+
* @param markdown - The assistant message text, complete or still streaming.
|
|
9611
|
+
* @returns The segments in source order.
|
|
9612
|
+
*
|
|
9613
|
+
* @example
|
|
9614
|
+
* ```ts
|
|
9615
|
+
* for (const segment of splitA2UIMarkdown(message.content)) {
|
|
9616
|
+
* if (segment.type === "a2ui") renderSurface(segment.text, segment.target);
|
|
9617
|
+
* else renderMarkdown(segment.text);
|
|
9618
|
+
* }
|
|
9619
|
+
* ```
|
|
9620
|
+
*/
|
|
9621
|
+
function splitA2UIMarkdown(markdown) {
|
|
9622
|
+
const segments = [];
|
|
9623
|
+
let proseStart = 0;
|
|
9624
|
+
let fence = null;
|
|
9625
|
+
let a2uiIndex = 0;
|
|
9626
|
+
const pushProse = (end) => {
|
|
9627
|
+
if (end > proseStart) segments.push({
|
|
9628
|
+
type: "markdown",
|
|
9629
|
+
text: markdown.slice(proseStart, end)
|
|
9630
|
+
});
|
|
9631
|
+
};
|
|
9632
|
+
let lineStart = 0;
|
|
9633
|
+
while (lineStart <= markdown.length) {
|
|
9634
|
+
const newline = markdown.indexOf("\n", lineStart);
|
|
9635
|
+
const lineEnd = newline < 0 ? markdown.length : newline;
|
|
9636
|
+
const hasCR = lineEnd > lineStart && markdown[lineEnd - 1] === "\r";
|
|
9637
|
+
const line = markdown.slice(lineStart, hasCR ? lineEnd - 1 : lineEnd);
|
|
9638
|
+
if (fence) {
|
|
9639
|
+
if (isCloser(line, fence)) {
|
|
9640
|
+
if (fence.index >= 0) {
|
|
9641
|
+
const body = markdown.slice(fence.bodyStart, Math.max(fence.bodyStart, lineStart));
|
|
9642
|
+
segments.push(a2uiSegment(fence, body, true));
|
|
9643
|
+
proseStart = hasCR ? lineEnd - 1 : lineEnd;
|
|
9644
|
+
}
|
|
9645
|
+
fence = null;
|
|
9646
|
+
}
|
|
9647
|
+
} else {
|
|
9648
|
+
const open = FENCE_OPEN.exec(line);
|
|
9649
|
+
if (open) {
|
|
9650
|
+
var _open$, _open$2;
|
|
9651
|
+
const marker = (_open$ = open[1]) !== null && _open$ !== void 0 ? _open$ : "";
|
|
9652
|
+
const info = (_open$2 = open[2]) !== null && _open$2 !== void 0 ? _open$2 : "";
|
|
9653
|
+
const char = marker.charAt(0);
|
|
9654
|
+
if (!(char === "`" && info.includes("`"))) {
|
|
9655
|
+
const [lang = "", ...tokens] = info.trim().split(/\s+/);
|
|
9656
|
+
const isA2UI = lang === A2UI_FENCE_LANGUAGE;
|
|
9657
|
+
if (isA2UI) pushProse(lineStart);
|
|
9658
|
+
fence = {
|
|
9659
|
+
char,
|
|
9660
|
+
length: marker.length,
|
|
9661
|
+
bodyStart: newline < 0 ? markdown.length : lineEnd + 1,
|
|
9662
|
+
index: isA2UI ? a2uiIndex++ : -1,
|
|
9663
|
+
target: isA2UI ? readTarget(tokens) : void 0
|
|
9664
|
+
};
|
|
9665
|
+
}
|
|
9666
|
+
}
|
|
9667
|
+
}
|
|
9668
|
+
if (newline < 0) break;
|
|
9669
|
+
lineStart = newline + 1;
|
|
9670
|
+
}
|
|
9671
|
+
if (fence && fence.index >= 0) {
|
|
9672
|
+
const { char } = fence;
|
|
9673
|
+
let body = markdown.slice(fence.bodyStart);
|
|
9674
|
+
const lastNewline = body.lastIndexOf("\n");
|
|
9675
|
+
const lastLine = body.slice(lastNewline + 1).replace(/\r$/, "");
|
|
9676
|
+
if (lastLine.length > 0 && [...lastLine].every((ch) => ch === char)) body = body.slice(0, lastNewline + 1);
|
|
9677
|
+
segments.push(a2uiSegment(fence, body, false));
|
|
9678
|
+
} else pushProse(markdown.length);
|
|
9679
|
+
return segments;
|
|
9680
|
+
}
|
|
9681
|
+
|
|
9682
|
+
//#endregion
|
|
9683
|
+
//#region src/a2ui-markdown/operations.ts
|
|
9684
|
+
/** The operation keys that change a surface. */
|
|
9685
|
+
const SURFACE_OP_KEYS = [
|
|
9686
|
+
"createSurface",
|
|
9687
|
+
"updateComponents",
|
|
9688
|
+
"updateDataModel",
|
|
9689
|
+
"deleteSurface"
|
|
9690
|
+
];
|
|
9691
|
+
/** The operation key of an agent-called function. It has no surface. */
|
|
9692
|
+
const FUNCTION_CALL_KEY = "callRendererFunction";
|
|
9693
|
+
const OP_KEYS = [...SURFACE_OP_KEYS, FUNCTION_CALL_KEY];
|
|
9694
|
+
function isRecord(value) {
|
|
9695
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9696
|
+
}
|
|
9697
|
+
function isWhitespace(ch) {
|
|
9698
|
+
return ch === " " || ch === "\n" || ch === "\r" || ch === " ";
|
|
9699
|
+
}
|
|
9700
|
+
function skipWhitespace(s, i) {
|
|
9701
|
+
while (i < s.length && isWhitespace(s[i])) i++;
|
|
9702
|
+
return i;
|
|
9703
|
+
}
|
|
9704
|
+
/** Index of the closing quote of the JSON string opening at `start`, or -1. */
|
|
9705
|
+
function findStringEnd(s, start) {
|
|
9706
|
+
for (let i = start + 1; i < s.length; i++) {
|
|
9707
|
+
if (s[i] === "\\") {
|
|
9708
|
+
i++;
|
|
9709
|
+
continue;
|
|
9710
|
+
}
|
|
9711
|
+
if (s[i] === "\"") return i;
|
|
9712
|
+
}
|
|
9713
|
+
return -1;
|
|
9714
|
+
}
|
|
9715
|
+
/**
|
|
9716
|
+
* Find the first `"key":` whose value starts with `opener` and return the index
|
|
9717
|
+
* of that opener, or -1.
|
|
9718
|
+
*/
|
|
9719
|
+
function findKeyValue(s, key, opener) {
|
|
9720
|
+
const needle = `"${key}"`;
|
|
9721
|
+
let from = 0;
|
|
9722
|
+
while (true) {
|
|
9723
|
+
const k = s.indexOf(needle, from);
|
|
9724
|
+
if (k < 0) return -1;
|
|
9725
|
+
let i = skipWhitespace(s, k + needle.length);
|
|
9726
|
+
if (s[i] === ":") {
|
|
9727
|
+
i = skipWhitespace(s, i + 1);
|
|
9728
|
+
if (s[i] === opener) return i;
|
|
9729
|
+
}
|
|
9730
|
+
from = k + 1;
|
|
9731
|
+
}
|
|
9732
|
+
}
|
|
9733
|
+
/**
|
|
9734
|
+
* Read `"key":"value"` from partial JSON. The first match anywhere in the
|
|
9735
|
+
* text wins, at any depth.
|
|
9736
|
+
*
|
|
9737
|
+
* @param partialJson - JSON text that can still be streaming.
|
|
9738
|
+
* @param key - The field name.
|
|
9739
|
+
* @returns The string value, or null until its closing quote has arrived.
|
|
9740
|
+
*
|
|
9741
|
+
* @example
|
|
9742
|
+
* ```ts
|
|
9743
|
+
* extractStringField('{"createSurface":{"surfaceId":"plan","cat', "surfaceId"); // "plan"
|
|
9744
|
+
* ```
|
|
9745
|
+
*/
|
|
9746
|
+
function extractStringField(partialJson, key) {
|
|
9747
|
+
const start = findKeyValue(partialJson, key, "\"");
|
|
9748
|
+
if (start < 0) return null;
|
|
9749
|
+
const end = findStringEnd(partialJson, start);
|
|
9750
|
+
if (end < 0) return null;
|
|
9751
|
+
try {
|
|
9752
|
+
const value = JSON.parse(partialJson.slice(start, end + 1));
|
|
9753
|
+
return typeof value === "string" ? value : null;
|
|
9754
|
+
} catch (_unused) {
|
|
9755
|
+
return null;
|
|
9756
|
+
}
|
|
9757
|
+
}
|
|
9758
|
+
function pushItem(raw, items) {
|
|
9759
|
+
const trimmed = raw.trim();
|
|
9760
|
+
if (!trimmed) return;
|
|
9761
|
+
try {
|
|
9762
|
+
items.push(JSON.parse(trimmed));
|
|
9763
|
+
} catch (_unused2) {}
|
|
9764
|
+
}
|
|
9765
|
+
/**
|
|
9766
|
+
* Find `"key":[` in partial JSON and return every complete item of that array
|
|
9767
|
+
* so far, plus whether the array has closed. Items of a `components` array get
|
|
9768
|
+
* structural-key depth repair: a component that lost closing braces is fixed
|
|
9769
|
+
* when its `id`, `component`, `child` or `children` key shows where it ends.
|
|
9770
|
+
*
|
|
9771
|
+
* @param partialJson - JSON text that can still be streaming.
|
|
9772
|
+
* @param key - The name of the array field.
|
|
9773
|
+
* @returns `{ items, closed }`, or null when the key (with an array value)
|
|
9774
|
+
* has not appeared yet.
|
|
9775
|
+
*
|
|
9776
|
+
* @example
|
|
9777
|
+
* ```ts
|
|
9778
|
+
* const result = extractCompleteArrayItems(streamedText, "components");
|
|
9779
|
+
* if (result) render(result.items);
|
|
9780
|
+
* ```
|
|
9781
|
+
*/
|
|
9782
|
+
function extractCompleteArrayItems(partialJson, key) {
|
|
9783
|
+
const open = findKeyValue(partialJson, key, "[");
|
|
9784
|
+
if (open < 0) return null;
|
|
9785
|
+
return completeArrayItemsAt(partialJson, open, { repairComponents: key === "components" });
|
|
9786
|
+
}
|
|
9787
|
+
/** Index of the last non-whitespace character before `i`, or -1. */
|
|
9788
|
+
function prevNonWhitespace(s, i) {
|
|
9789
|
+
let j = i - 1;
|
|
9790
|
+
while (j >= 0 && isWhitespace(s[j])) j--;
|
|
9791
|
+
return j;
|
|
9792
|
+
}
|
|
9793
|
+
/**
|
|
9794
|
+
* Keys that only ever belong at a component's top level. Seen nested inside
|
|
9795
|
+
* the component's objects, they mean the model forgot closing braces.
|
|
9796
|
+
*/
|
|
9797
|
+
const STRUCTURAL_KEYS = new Set([
|
|
9798
|
+
"id",
|
|
9799
|
+
"component",
|
|
9800
|
+
"child",
|
|
9801
|
+
"children"
|
|
9802
|
+
]);
|
|
9803
|
+
/** Whether a value starting with `ch` has the shape `key` takes on a component. */
|
|
9804
|
+
function structuralValueFits(key, ch) {
|
|
9805
|
+
if (key === "children") return ch === "[" || ch === "{";
|
|
9806
|
+
return ch === "\"";
|
|
9807
|
+
}
|
|
9808
|
+
/** `{"id":` — a new component object starting at `i`. */
|
|
9809
|
+
const COMPONENT_START = /^\{\s*"id"\s*:/;
|
|
9810
|
+
/**
|
|
9811
|
+
* Structural-key depth repair for one component item. While scanning, a
|
|
9812
|
+
* structural key (`id`, `component`, `child`, `children`) found as an object
|
|
9813
|
+
* key below the item's top level, with only objects (no arrays) between it
|
|
9814
|
+
* and the item root, a value of the expected shape, and not already present
|
|
9815
|
+
* at the top level, means closing braces were dropped: the missing `}` are
|
|
9816
|
+
* synthesized right before it so it lands at the top level. Containers still
|
|
9817
|
+
* open at the end are closed. Returns null when a string never terminates.
|
|
9818
|
+
*/
|
|
9819
|
+
function repairComponentItem(item) {
|
|
9820
|
+
const stack = [];
|
|
9821
|
+
const topKeys = /* @__PURE__ */ new Set();
|
|
9822
|
+
let out = "";
|
|
9823
|
+
let copied = 0;
|
|
9824
|
+
for (let i = 0; i < item.length; i++) {
|
|
9825
|
+
const c = item[i];
|
|
9826
|
+
if (c === "\"") {
|
|
9827
|
+
const end = findStringEnd(item, i);
|
|
9828
|
+
if (end < 0) return null;
|
|
9829
|
+
const prev = prevNonWhitespace(item, i);
|
|
9830
|
+
const prevCh = item[prev];
|
|
9831
|
+
const colon = skipWhitespace(item, end + 1);
|
|
9832
|
+
if (stack[stack.length - 1] === "{" && (prevCh === "," || prevCh === "{") && item[colon] === ":") {
|
|
9833
|
+
let key;
|
|
9834
|
+
try {
|
|
9835
|
+
key = JSON.parse(item.slice(i, end + 1));
|
|
9836
|
+
} catch (_unused3) {
|
|
9837
|
+
return null;
|
|
9838
|
+
}
|
|
9839
|
+
if (typeof key === "string") {
|
|
9840
|
+
if (stack.length === 1) topKeys.add(key);
|
|
9841
|
+
else if (STRUCTURAL_KEYS.has(key) && !topKeys.has(key) && stack.every((x) => x === "{") && structuralValueFits(key, item[skipWhitespace(item, colon + 1)])) {
|
|
9842
|
+
const closers = "}".repeat(stack.length - 1);
|
|
9843
|
+
if (prevCh === ",") {
|
|
9844
|
+
out += item.slice(copied, prev) + closers;
|
|
9845
|
+
copied = prev;
|
|
9846
|
+
} else {
|
|
9847
|
+
out += item.slice(copied, i) + closers + ",";
|
|
9848
|
+
copied = i;
|
|
9849
|
+
}
|
|
9850
|
+
stack.length = 1;
|
|
9851
|
+
topKeys.add(key);
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
}
|
|
9855
|
+
i = end;
|
|
9856
|
+
continue;
|
|
9857
|
+
}
|
|
9858
|
+
if (c === "{" || c === "[") stack.push(c);
|
|
9859
|
+
else if (c === "}" || c === "]") {
|
|
9860
|
+
stack.pop();
|
|
9861
|
+
if (stack.length === 0) return out + item.slice(copied, i + 1);
|
|
9862
|
+
}
|
|
9863
|
+
}
|
|
9864
|
+
const closers = stack.reduceRight((text, opener) => text + (opener === "{" ? "}" : "]"), "");
|
|
9865
|
+
return out + item.slice(copied) + closers;
|
|
9866
|
+
}
|
|
9867
|
+
function parseRecord(text) {
|
|
9868
|
+
if (text === null) return void 0;
|
|
9869
|
+
try {
|
|
9870
|
+
const value = JSON.parse(text);
|
|
9871
|
+
return isRecord(value) ? value : void 0;
|
|
9872
|
+
} catch (_unused4) {
|
|
9873
|
+
return;
|
|
9874
|
+
}
|
|
9875
|
+
}
|
|
9876
|
+
/**
|
|
9877
|
+
* Complete items of the (possibly unterminated) array whose "[" is at `open`.
|
|
9878
|
+
* With `repairComponents`, an item that balanced but does not parse is retried
|
|
9879
|
+
* with structural-key repair, and a `,{"id":` where an item expects a key
|
|
9880
|
+
* ends that (unbalanced) item there, so one malformed component cannot
|
|
9881
|
+
* swallow the rest of the array; the cut item is kept only if repair makes
|
|
9882
|
+
* it parse.
|
|
9883
|
+
*/
|
|
9884
|
+
function completeArrayItemsAt(partialJson, open, options) {
|
|
9885
|
+
const { repairComponents } = options;
|
|
9886
|
+
const s = partialJson;
|
|
9887
|
+
const items = [];
|
|
9888
|
+
const stack = [];
|
|
9889
|
+
let inString = false;
|
|
9890
|
+
let itemStart = -1;
|
|
9891
|
+
const finishItem = (end, balanced) => {
|
|
9892
|
+
const raw = s.slice(itemStart, end);
|
|
9893
|
+
if (!repairComponents) {
|
|
9894
|
+
pushItem(raw, items);
|
|
9895
|
+
return;
|
|
9896
|
+
}
|
|
9897
|
+
if (balanced) try {
|
|
9898
|
+
items.push(JSON.parse(raw));
|
|
9899
|
+
return;
|
|
9900
|
+
} catch (_unused5) {}
|
|
9901
|
+
const repaired = parseRecord(repairComponentItem(raw.trim()));
|
|
9902
|
+
if (repaired !== void 0) items.push(repaired);
|
|
9903
|
+
};
|
|
9904
|
+
for (let i = open + 1; i < s.length; i++) {
|
|
9905
|
+
const c = s[i];
|
|
9906
|
+
if (inString) {
|
|
9907
|
+
if (c === "\\") i++;
|
|
9908
|
+
else if (c === "\"") inString = false;
|
|
9909
|
+
continue;
|
|
9910
|
+
}
|
|
9911
|
+
if (c === "\"") {
|
|
9912
|
+
inString = true;
|
|
9913
|
+
if (stack.length === 0 && itemStart < 0) itemStart = i;
|
|
9914
|
+
continue;
|
|
9915
|
+
}
|
|
9916
|
+
if (c === "{" || c === "[") {
|
|
9917
|
+
if (repairComponents && c === "{" && stack[stack.length - 1] === "{" && COMPONENT_START.test(s.slice(i, i + 24))) {
|
|
9918
|
+
const prev = prevNonWhitespace(s, i);
|
|
9919
|
+
if (s[prev] === ",") {
|
|
9920
|
+
finishItem(prev, false);
|
|
9921
|
+
stack.length = 0;
|
|
9922
|
+
itemStart = i;
|
|
9923
|
+
stack.push(c);
|
|
9924
|
+
continue;
|
|
9925
|
+
}
|
|
9926
|
+
}
|
|
9927
|
+
if (stack.length === 0) itemStart = i;
|
|
9928
|
+
stack.push(c);
|
|
9929
|
+
continue;
|
|
9930
|
+
}
|
|
9931
|
+
if (c === "}" || c === "]") {
|
|
9932
|
+
if (stack.length === 0) {
|
|
9933
|
+
if (c === "]") {
|
|
9934
|
+
if (itemStart >= 0) pushItem(s.slice(itemStart, i), items);
|
|
9935
|
+
return {
|
|
9936
|
+
items,
|
|
9937
|
+
closed: true
|
|
9938
|
+
};
|
|
9939
|
+
}
|
|
9940
|
+
return {
|
|
9941
|
+
items,
|
|
9942
|
+
closed: false
|
|
9943
|
+
};
|
|
9944
|
+
}
|
|
9945
|
+
stack.pop();
|
|
9946
|
+
if (stack.length === 0) {
|
|
9947
|
+
finishItem(i + 1, true);
|
|
9948
|
+
itemStart = -1;
|
|
9949
|
+
}
|
|
9950
|
+
continue;
|
|
9951
|
+
}
|
|
9952
|
+
if (stack.length === 0) {
|
|
9953
|
+
if (c === ",") {
|
|
9954
|
+
if (itemStart >= 0) pushItem(s.slice(itemStart, i), items);
|
|
9955
|
+
itemStart = -1;
|
|
9956
|
+
} else if (itemStart < 0 && !isWhitespace(c)) itemStart = i;
|
|
9957
|
+
}
|
|
9958
|
+
}
|
|
9959
|
+
return {
|
|
9960
|
+
items,
|
|
9961
|
+
closed: false
|
|
9962
|
+
};
|
|
9963
|
+
}
|
|
9964
|
+
/** The first operation key whose value is an object, with that value. */
|
|
9965
|
+
function getOperationEntry(op) {
|
|
9966
|
+
for (const key of OP_KEYS) {
|
|
9967
|
+
const inner = op[key];
|
|
9968
|
+
if (isRecord(inner)) return {
|
|
9969
|
+
key,
|
|
9970
|
+
inner
|
|
9971
|
+
};
|
|
9972
|
+
}
|
|
9973
|
+
return null;
|
|
9974
|
+
}
|
|
9975
|
+
/**
|
|
9976
|
+
* The surfaceId an operation targets: the one nested under its operation key,
|
|
9977
|
+
* else a top-level `surfaceId`. A `callRendererFunction` operation targets no
|
|
9978
|
+
* surface, so it gets undefined.
|
|
9979
|
+
*
|
|
9980
|
+
* It is named `getMarkdownOperationSurfaceId` because `@copilotkit/shared`
|
|
9981
|
+
* already exports a strict `getOperationSurfaceId`. This one also reads a
|
|
9982
|
+
* top-level `surfaceId`, which models sometimes write.
|
|
9983
|
+
*
|
|
9984
|
+
* @param op - An operation from an a2ui fence.
|
|
9985
|
+
* @returns The surfaceId, or undefined when the operation names none or is a
|
|
9986
|
+
* function call.
|
|
9987
|
+
*
|
|
9988
|
+
* @example
|
|
9989
|
+
* ```ts
|
|
9990
|
+
* getMarkdownOperationSurfaceId({ updateDataModel: { surfaceId: "plan" } }); // "plan"
|
|
9991
|
+
* ```
|
|
9992
|
+
*/
|
|
9993
|
+
function getMarkdownOperationSurfaceId(op) {
|
|
9994
|
+
var _getOperationEntry;
|
|
9995
|
+
if (((_getOperationEntry = getOperationEntry(op)) === null || _getOperationEntry === void 0 ? void 0 : _getOperationEntry.key) === FUNCTION_CALL_KEY) return void 0;
|
|
9996
|
+
for (const key of SURFACE_OP_KEYS) {
|
|
9997
|
+
const inner = op[key];
|
|
9998
|
+
if (isRecord(inner) && typeof inner.surfaceId === "string") return inner.surfaceId;
|
|
9999
|
+
}
|
|
10000
|
+
return typeof op.surfaceId === "string" ? op.surfaceId : void 0;
|
|
10001
|
+
}
|
|
10002
|
+
/**
|
|
10003
|
+
* Index just past the JSON value starting at `start`, or -1 when the value is
|
|
10004
|
+
* still incomplete. A primitive at the very end of the input counts as
|
|
10005
|
+
* incomplete, since more digits or letters may still stream in.
|
|
10006
|
+
*/
|
|
10007
|
+
function findValueEnd(s, start) {
|
|
10008
|
+
const c = s[start];
|
|
10009
|
+
if (c === "\"") {
|
|
10010
|
+
const end = findStringEnd(s, start);
|
|
10011
|
+
return end < 0 ? -1 : end + 1;
|
|
10012
|
+
}
|
|
10013
|
+
if (c === "{" || c === "[") {
|
|
10014
|
+
let depth = 0;
|
|
10015
|
+
for (let i = start; i < s.length; i++) {
|
|
10016
|
+
const ch = s[i];
|
|
10017
|
+
if (ch === "\"") {
|
|
10018
|
+
const end = findStringEnd(s, i);
|
|
10019
|
+
if (end < 0) return -1;
|
|
10020
|
+
i = end;
|
|
10021
|
+
} else if (ch === "{" || ch === "[") depth++;
|
|
10022
|
+
else if (ch === "}" || ch === "]") {
|
|
10023
|
+
depth--;
|
|
10024
|
+
if (depth === 0) return i + 1;
|
|
10025
|
+
}
|
|
10026
|
+
}
|
|
10027
|
+
return -1;
|
|
10028
|
+
}
|
|
10029
|
+
let i = start;
|
|
10030
|
+
while (i < s.length && !isWhitespace(s[i]) && !",}]".includes(s[i])) i++;
|
|
10031
|
+
return i >= s.length ? -1 : i;
|
|
10032
|
+
}
|
|
10033
|
+
/**
|
|
10034
|
+
* Walk the direct entries of the (possibly unterminated) JSON object whose "{"
|
|
10035
|
+
* is at `objStart`, calling `visit` with each key and the index where its value
|
|
10036
|
+
* starts. Nested objects and arrays are skipped whole, so keys inside them are
|
|
10037
|
+
* never visited. Stops when `visit` returns true, at the object's end, or where
|
|
10038
|
+
* the input runs out.
|
|
10039
|
+
*/
|
|
10040
|
+
function visitDirectEntries(s, objStart, visit) {
|
|
10041
|
+
let i = objStart + 1;
|
|
10042
|
+
while (i < s.length) {
|
|
10043
|
+
i = skipWhitespace(s, i);
|
|
10044
|
+
const c = s[i];
|
|
10045
|
+
if (c === ",") {
|
|
10046
|
+
i++;
|
|
10047
|
+
continue;
|
|
10048
|
+
}
|
|
10049
|
+
if (c !== "\"") return;
|
|
10050
|
+
const keyEnd = findStringEnd(s, i);
|
|
10051
|
+
if (keyEnd < 0) return;
|
|
10052
|
+
let key;
|
|
10053
|
+
try {
|
|
10054
|
+
key = JSON.parse(s.slice(i, keyEnd + 1));
|
|
10055
|
+
} catch (_unused6) {
|
|
10056
|
+
return;
|
|
10057
|
+
}
|
|
10058
|
+
i = skipWhitespace(s, keyEnd + 1);
|
|
10059
|
+
if (s[i] !== ":") return;
|
|
10060
|
+
i = skipWhitespace(s, i + 1);
|
|
10061
|
+
if (i >= s.length) return;
|
|
10062
|
+
if (typeof key === "string" && visit(key, i)) return;
|
|
10063
|
+
const valueEnd = findValueEnd(s, i);
|
|
10064
|
+
if (valueEnd < 0) return;
|
|
10065
|
+
i = valueEnd;
|
|
10066
|
+
}
|
|
10067
|
+
}
|
|
10068
|
+
/**
|
|
10069
|
+
* Value start of a direct `key` of the object at `objStart` whose value begins
|
|
10070
|
+
* with `opener` (any value when omitted), or -1.
|
|
10071
|
+
*/
|
|
10072
|
+
function findDirectKeyValue(s, objStart, key, opener) {
|
|
10073
|
+
let found = -1;
|
|
10074
|
+
visitDirectEntries(s, objStart, (k, valueStart) => {
|
|
10075
|
+
if (k !== key) return false;
|
|
10076
|
+
if (opener === void 0 || s[valueStart] === opener) found = valueStart;
|
|
10077
|
+
return true;
|
|
10078
|
+
});
|
|
10079
|
+
return found;
|
|
10080
|
+
}
|
|
10081
|
+
/** A direct string field of the object at `objStart`, once its closing quote has arrived. */
|
|
10082
|
+
function readDirectString(s, objStart, key) {
|
|
10083
|
+
if (objStart < 0) return null;
|
|
10084
|
+
const start = findDirectKeyValue(s, objStart, key, "\"");
|
|
10085
|
+
if (start < 0) return null;
|
|
10086
|
+
const end = findValueEnd(s, start);
|
|
10087
|
+
if (end < 0) return null;
|
|
10088
|
+
try {
|
|
10089
|
+
const value = JSON.parse(s.slice(start, end));
|
|
10090
|
+
return typeof value === "string" ? value : null;
|
|
10091
|
+
} catch (_unused7) {
|
|
10092
|
+
return null;
|
|
10093
|
+
}
|
|
10094
|
+
}
|
|
10095
|
+
/** A direct object field of the object at `objStart`, once the whole object has arrived. */
|
|
10096
|
+
function readDirectRecord(s, objStart, key) {
|
|
10097
|
+
const start = findDirectKeyValue(s, objStart, key, "{");
|
|
10098
|
+
if (start < 0) return void 0;
|
|
10099
|
+
const end = findValueEnd(s, start);
|
|
10100
|
+
if (end < 0) return void 0;
|
|
10101
|
+
return parseRecord(s.slice(start, end));
|
|
10102
|
+
}
|
|
10103
|
+
/**
|
|
10104
|
+
* The complete part of a (possibly unterminated) JSON value: the parsed value
|
|
10105
|
+
* when it is complete; for an open object, its complete entries plus the
|
|
10106
|
+
* complete items of any streaming array entry; otherwise undefined.
|
|
10107
|
+
*/
|
|
10108
|
+
function completePartOfValue(s, start) {
|
|
10109
|
+
const end = findValueEnd(s, start);
|
|
10110
|
+
if (end >= 0) try {
|
|
10111
|
+
return JSON.parse(s.slice(start, end));
|
|
10112
|
+
} catch (_unused8) {
|
|
10113
|
+
return;
|
|
10114
|
+
}
|
|
10115
|
+
if (s[start] !== "{") return void 0;
|
|
10116
|
+
const out = {};
|
|
10117
|
+
visitDirectEntries(s, start, (key, valueStart) => {
|
|
10118
|
+
const valueEnd = findValueEnd(s, valueStart);
|
|
10119
|
+
if (valueEnd >= 0) try {
|
|
10120
|
+
out[key] = JSON.parse(s.slice(valueStart, valueEnd));
|
|
10121
|
+
} catch (_unused9) {}
|
|
10122
|
+
else if (s[valueStart] === "[") {
|
|
10123
|
+
const { items } = completeArrayItemsAt(s, valueStart, { repairComponents: false });
|
|
10124
|
+
if (items.length > 0) out[key] = items;
|
|
10125
|
+
}
|
|
10126
|
+
return false;
|
|
10127
|
+
});
|
|
10128
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
10129
|
+
}
|
|
10130
|
+
/**
|
|
10131
|
+
* Best-effort operation from an unfinished or malformed top-level object.
|
|
10132
|
+
* Fields are read only from the operation's own keys (`version` at the top
|
|
10133
|
+
* level, `surfaceId`, `catalogId`, `path`, `dataModel` and `components` inside
|
|
10134
|
+
* the operation object), never from component props or data-model values that
|
|
10135
|
+
* happen to share a name.
|
|
10136
|
+
*
|
|
10137
|
+
* A `createSurface` keeps its complete components and a `dataModel` that has
|
|
10138
|
+
* fully arrived, so a surface created in one line renders while it streams.
|
|
10139
|
+
* A `callRendererFunction` gives nothing: a function must not run with half
|
|
10140
|
+
* of its args.
|
|
10141
|
+
*/
|
|
10142
|
+
function partialOperation(line) {
|
|
10143
|
+
var _readDirectString;
|
|
10144
|
+
const root = skipWhitespace(line, 0);
|
|
10145
|
+
if (line[root] !== "{") return null;
|
|
10146
|
+
const version = (_readDirectString = readDirectString(line, root, "version")) !== null && _readDirectString !== void 0 ? _readDirectString : _copilotkit_shared.A2UI_VERSION;
|
|
10147
|
+
const components = findDirectKeyValue(line, root, "updateComponents", "{");
|
|
10148
|
+
if (components >= 0) {
|
|
10149
|
+
const arrayStart = findDirectKeyValue(line, components, "components", "[");
|
|
10150
|
+
if (arrayStart < 0) return null;
|
|
10151
|
+
const { items } = completeArrayItemsAt(line, arrayStart, { repairComponents: true });
|
|
10152
|
+
if (items.length === 0) return null;
|
|
10153
|
+
const surfaceId = readDirectString(line, components, "surfaceId");
|
|
10154
|
+
return {
|
|
10155
|
+
version,
|
|
10156
|
+
updateComponents: {
|
|
10157
|
+
...surfaceId ? { surfaceId } : {},
|
|
10158
|
+
components: items
|
|
10159
|
+
}
|
|
10160
|
+
};
|
|
10161
|
+
}
|
|
10162
|
+
const data = findDirectKeyValue(line, root, "updateDataModel", "{");
|
|
10163
|
+
if (data >= 0) {
|
|
10164
|
+
const valueStart = findDirectKeyValue(line, data, "value");
|
|
10165
|
+
if (valueStart < 0) return null;
|
|
10166
|
+
const value = completePartOfValue(line, valueStart);
|
|
10167
|
+
if (value === void 0) return null;
|
|
10168
|
+
const surfaceId = readDirectString(line, data, "surfaceId");
|
|
10169
|
+
const path = readDirectString(line, data, "path");
|
|
10170
|
+
return {
|
|
10171
|
+
version,
|
|
10172
|
+
updateDataModel: {
|
|
10173
|
+
...surfaceId ? { surfaceId } : {},
|
|
10174
|
+
...path ? { path } : {},
|
|
10175
|
+
value
|
|
10176
|
+
}
|
|
10177
|
+
};
|
|
10178
|
+
}
|
|
10179
|
+
const create = findDirectKeyValue(line, root, "createSurface", "{");
|
|
10180
|
+
if (create >= 0) {
|
|
10181
|
+
const surfaceId = readDirectString(line, create, "surfaceId");
|
|
10182
|
+
if (!surfaceId) return null;
|
|
10183
|
+
const catalogId = readDirectString(line, create, "catalogId");
|
|
10184
|
+
const dataModel = readDirectRecord(line, create, "dataModel");
|
|
10185
|
+
const componentsStart = findDirectKeyValue(line, create, "components", "[");
|
|
10186
|
+
const components = componentsStart < 0 ? [] : completeArrayItemsAt(line, componentsStart, { repairComponents: true }).items;
|
|
10187
|
+
return {
|
|
10188
|
+
version,
|
|
10189
|
+
createSurface: {
|
|
10190
|
+
surfaceId,
|
|
10191
|
+
...catalogId ? { catalogId } : {},
|
|
10192
|
+
...dataModel ? { dataModel } : {},
|
|
10193
|
+
...components.length > 0 ? { components } : {}
|
|
10194
|
+
}
|
|
10195
|
+
};
|
|
10196
|
+
}
|
|
10197
|
+
return null;
|
|
10198
|
+
}
|
|
10199
|
+
/**
|
|
10200
|
+
* A line that opens a new top-level operation: `{"version":"v…` or
|
|
10201
|
+
* `{"<operation>":{`. Seen at the start of a line while an earlier object is
|
|
10202
|
+
* still unbalanced, it means that object is malformed and has ended.
|
|
10203
|
+
*/
|
|
10204
|
+
const OPERATION_START = new RegExp(`^\\{\\s*"(?:version"\\s*:\\s*"v\\d|(?:${OP_KEYS.join("|")})"\\s*:\\s*\\{)`);
|
|
10205
|
+
/**
|
|
10206
|
+
* Scan the top-level object whose "{" is at `start`. Returns the index just
|
|
10207
|
+
* past it and whether it balanced. An unbalanced object ends early (at the
|
|
10208
|
+
* start of the line) when a line opens a new operation; otherwise it runs to
|
|
10209
|
+
* the end of the input. JSON strings cannot contain raw newlines, so a newline
|
|
10210
|
+
* inside a string ends it: a stray quote then breaks one line, not the rest of
|
|
10211
|
+
* the fence.
|
|
10212
|
+
*/
|
|
10213
|
+
function scanTopLevelObject(s, start) {
|
|
10214
|
+
let depth = 0;
|
|
10215
|
+
let inString = false;
|
|
10216
|
+
for (let i = start; i < s.length; i++) {
|
|
10217
|
+
const c = s[i];
|
|
10218
|
+
if (inString) {
|
|
10219
|
+
if (c === "\\" && s[i + 1] !== "\n") i++;
|
|
10220
|
+
else if (c === "\"" || c === "\n") inString = false;
|
|
10221
|
+
if (c !== "\n") continue;
|
|
10222
|
+
}
|
|
10223
|
+
if (c === "\n") {
|
|
10224
|
+
const next = skipWhitespace(s, i + 1);
|
|
10225
|
+
if (OPERATION_START.test(s.slice(next, next + 40))) return {
|
|
10226
|
+
end: i + 1,
|
|
10227
|
+
balanced: false
|
|
10228
|
+
};
|
|
10229
|
+
continue;
|
|
10230
|
+
}
|
|
10231
|
+
if (c === "\"") inString = true;
|
|
10232
|
+
else if (c === "{" || c === "[") depth++;
|
|
10233
|
+
else if (c === "}" || c === "]") {
|
|
10234
|
+
depth--;
|
|
10235
|
+
if (depth === 0) return {
|
|
10236
|
+
end: i + 1,
|
|
10237
|
+
balanced: true
|
|
10238
|
+
};
|
|
10239
|
+
}
|
|
10240
|
+
}
|
|
10241
|
+
return {
|
|
10242
|
+
end: s.length,
|
|
10243
|
+
balanced: false
|
|
10244
|
+
};
|
|
10245
|
+
}
|
|
10246
|
+
/**
|
|
10247
|
+
* Parse the body of an a2ui fence as a stream of top-level JSON values, so
|
|
10248
|
+
* operations may be one per line (the documented format), several per line,
|
|
10249
|
+
* pretty-printed over many lines, or wrapped in a top-level array (which is
|
|
10250
|
+
* flattened). Whitespace and commas between objects are ignored.
|
|
10251
|
+
*
|
|
10252
|
+
* - A balanced object is `JSON.parse`d. When that fails (e.g. a stray quote),
|
|
10253
|
+
* its raw text goes to `invalidLines` and whatever `partialOperation` can
|
|
10254
|
+
* salvage (complete components, data-model entries, createSurface fields)
|
|
10255
|
+
* is kept.
|
|
10256
|
+
* - An unbalanced object followed by a line that opens a new operation is
|
|
10257
|
+
* treated the same way.
|
|
10258
|
+
* - The trailing unbalanced object (still streaming, or never closed) is
|
|
10259
|
+
* `partialObject` and yields a partial operation when it has usable data.
|
|
10260
|
+
* - Other text between objects is skipped and reported in `recovered` (and in
|
|
10261
|
+
* `invalidLines`, which predates it).
|
|
10262
|
+
*
|
|
10263
|
+
* `partialLine` is a deprecated alias of `partialObject`.
|
|
10264
|
+
*
|
|
10265
|
+
* @param fenceText - The body of an a2ui fence (`text` of an a2ui
|
|
10266
|
+
* `MarkdownSegment`), complete or still streaming.
|
|
10267
|
+
* @returns `{ operations, partialObject, partialLine, invalidLines, recovered }`.
|
|
10268
|
+
*
|
|
10269
|
+
* @example
|
|
10270
|
+
* ```ts
|
|
10271
|
+
* const { operations } = extractFenceOperations(segment.text);
|
|
10272
|
+
* ```
|
|
10273
|
+
*/
|
|
10274
|
+
function extractFenceOperations(fenceText) {
|
|
10275
|
+
const s = fenceText;
|
|
10276
|
+
const operations = [];
|
|
10277
|
+
const invalidLines = [];
|
|
10278
|
+
const recovered = [];
|
|
10279
|
+
let partialObject = null;
|
|
10280
|
+
const salvage = (raw) => {
|
|
10281
|
+
invalidLines.push(raw.trim());
|
|
10282
|
+
const partial = partialOperation(raw);
|
|
10283
|
+
if (partial) operations.push(partial);
|
|
10284
|
+
};
|
|
10285
|
+
let junkStart = -1;
|
|
10286
|
+
const flushJunk = (end) => {
|
|
10287
|
+
if (junkStart < 0) return;
|
|
10288
|
+
const junk = s.slice(junkStart, end).trim();
|
|
10289
|
+
junkStart = -1;
|
|
10290
|
+
if (!junk) return;
|
|
10291
|
+
recovered.push(junk);
|
|
10292
|
+
invalidLines.push(junk);
|
|
10293
|
+
};
|
|
10294
|
+
let i = 0;
|
|
10295
|
+
while (i < s.length) {
|
|
10296
|
+
const c = s[i];
|
|
10297
|
+
if (c === "{") {
|
|
10298
|
+
flushJunk(i);
|
|
10299
|
+
const { end, balanced } = scanTopLevelObject(s, i);
|
|
10300
|
+
const raw = s.slice(i, end);
|
|
10301
|
+
if (balanced) {
|
|
10302
|
+
let parsed;
|
|
10303
|
+
try {
|
|
10304
|
+
parsed = JSON.parse(raw);
|
|
10305
|
+
} catch (_unused10) {
|
|
10306
|
+
parsed = void 0;
|
|
10307
|
+
}
|
|
10308
|
+
if (isRecord(parsed)) operations.push(parsed);
|
|
10309
|
+
else salvage(raw);
|
|
10310
|
+
} else if (end < s.length) salvage(raw);
|
|
10311
|
+
else {
|
|
10312
|
+
partialObject = raw;
|
|
10313
|
+
const partial = partialOperation(raw);
|
|
10314
|
+
if (partial) operations.push(partial);
|
|
10315
|
+
}
|
|
10316
|
+
i = end;
|
|
10317
|
+
continue;
|
|
10318
|
+
}
|
|
10319
|
+
if (c === "\n" || c === "[" || c === "]") flushJunk(i);
|
|
10320
|
+
else if (junkStart < 0 && !isWhitespace(c) && c !== ",") junkStart = i;
|
|
10321
|
+
i++;
|
|
10322
|
+
}
|
|
10323
|
+
flushJunk(s.length);
|
|
10324
|
+
return {
|
|
10325
|
+
operations,
|
|
10326
|
+
partialObject,
|
|
10327
|
+
partialLine: partialObject,
|
|
10328
|
+
invalidLines,
|
|
10329
|
+
recovered
|
|
10330
|
+
};
|
|
10331
|
+
}
|
|
10332
|
+
/**
|
|
10333
|
+
* Normalise a fence's operations for the renderer: drop unknown messages, fill
|
|
10334
|
+
* in `version` and missing `surfaceId`s, keep only the first `createSurface`,
|
|
10335
|
+
* keep its `catalogId` when `catalogIds` lists it (else use `catalogId`), synthesize
|
|
10336
|
+
* `createSurface` when the model omitted it, and report the
|
|
10337
|
+
* surfaceId (the first one found, else `fallbackSurfaceId`).
|
|
10338
|
+
*
|
|
10339
|
+
* `callRendererFunction` operations target no surface. They get no surfaceId,
|
|
10340
|
+
* do not cause a synthesized `createSurface`, and come back in
|
|
10341
|
+
* `functionCalls` (in fence order), never in `operations`.
|
|
10342
|
+
*
|
|
10343
|
+
* @param input.operations - Operations from `extractFenceOperations`.
|
|
10344
|
+
* @param input.fallbackSurfaceId - The surfaceId to use when no operation
|
|
10345
|
+
* names one.
|
|
10346
|
+
* @param input.catalogId - The client catalog. It replaces a catalogId of the
|
|
10347
|
+
* model that `catalogIds` does not list.
|
|
10348
|
+
* @param input.catalogIds - The catalogs that the model can name. Left out,
|
|
10349
|
+
* only `catalogId`.
|
|
10350
|
+
* @returns `{ surfaceId, operations, functionCalls }`.
|
|
10351
|
+
*
|
|
10352
|
+
* @example
|
|
10353
|
+
* ```ts
|
|
10354
|
+
* const { surfaceId, operations, functionCalls } = prepareSurfaceOperations({
|
|
10355
|
+
* operations: extractFenceOperations(segment.text).operations,
|
|
10356
|
+
* fallbackSurfaceId: `${messageId}-${segment.index}`,
|
|
10357
|
+
* catalogId,
|
|
10358
|
+
* });
|
|
10359
|
+
* ```
|
|
10360
|
+
*/
|
|
10361
|
+
function prepareSurfaceOperations(input) {
|
|
10362
|
+
var _input$catalogIds, _operations$map$find;
|
|
10363
|
+
const { operations, fallbackSurfaceId, catalogId } = input;
|
|
10364
|
+
const catalogIds = (_input$catalogIds = input.catalogIds) !== null && _input$catalogIds !== void 0 ? _input$catalogIds : [catalogId];
|
|
10365
|
+
const surfaceId = (_operations$map$find = operations.map(getMarkdownOperationSurfaceId).find((id) => !!id)) !== null && _operations$map$find !== void 0 ? _operations$map$find : fallbackSurfaceId;
|
|
10366
|
+
const out = [];
|
|
10367
|
+
const functionCalls = [];
|
|
10368
|
+
let hasCreate = false;
|
|
10369
|
+
for (const op of operations) {
|
|
10370
|
+
const entry = getOperationEntry(op);
|
|
10371
|
+
if (!entry) continue;
|
|
10372
|
+
const { key } = entry;
|
|
10373
|
+
const inner = { ...entry.inner };
|
|
10374
|
+
const version = typeof op.version === "string" ? op.version : _copilotkit_shared.A2UI_VERSION;
|
|
10375
|
+
if (key === FUNCTION_CALL_KEY) {
|
|
10376
|
+
functionCalls.push({
|
|
10377
|
+
version,
|
|
10378
|
+
[key]: inner
|
|
10379
|
+
});
|
|
10380
|
+
continue;
|
|
10381
|
+
}
|
|
10382
|
+
if (typeof inner.surfaceId !== "string") inner.surfaceId = surfaceId;
|
|
10383
|
+
if (key === "createSurface") {
|
|
10384
|
+
if (hasCreate) {
|
|
10385
|
+
const { surfaceId: id, dataModel, components } = inner;
|
|
10386
|
+
if (dataModel !== void 0) out.push({
|
|
10387
|
+
version,
|
|
10388
|
+
updateDataModel: {
|
|
10389
|
+
surfaceId: id,
|
|
10390
|
+
path: "/",
|
|
10391
|
+
value: dataModel
|
|
10392
|
+
}
|
|
10393
|
+
});
|
|
10394
|
+
if (Array.isArray(components) && components.length > 0) out.push({
|
|
10395
|
+
version,
|
|
10396
|
+
updateComponents: {
|
|
10397
|
+
surfaceId: id,
|
|
10398
|
+
components
|
|
10399
|
+
}
|
|
10400
|
+
});
|
|
10401
|
+
continue;
|
|
10402
|
+
}
|
|
10403
|
+
hasCreate = true;
|
|
10404
|
+
if (!catalogIds.includes(inner.catalogId)) inner.catalogId = catalogId;
|
|
10405
|
+
}
|
|
10406
|
+
out.push({
|
|
10407
|
+
version,
|
|
10408
|
+
[key]: inner
|
|
10409
|
+
});
|
|
10410
|
+
}
|
|
10411
|
+
if (!hasCreate && out.length > 0) out.unshift({
|
|
10412
|
+
version: _copilotkit_shared.A2UI_VERSION,
|
|
10413
|
+
createSurface: {
|
|
10414
|
+
surfaceId,
|
|
10415
|
+
catalogId
|
|
10416
|
+
}
|
|
10417
|
+
});
|
|
10418
|
+
return {
|
|
10419
|
+
surfaceId,
|
|
10420
|
+
operations: out,
|
|
10421
|
+
functionCalls
|
|
10422
|
+
};
|
|
10423
|
+
}
|
|
10424
|
+
/**
|
|
10425
|
+
* Components a user operates. A Card containing one of these is an
|
|
10426
|
+
* interactive panel and keeps its box; every other Card is informational.
|
|
10427
|
+
*/
|
|
10428
|
+
const INTERACTIVE_COMPONENTS = new Set([
|
|
10429
|
+
"Button",
|
|
10430
|
+
"Pressable",
|
|
10431
|
+
"Form",
|
|
10432
|
+
"TextField",
|
|
10433
|
+
"TextArea",
|
|
10434
|
+
"Select",
|
|
10435
|
+
"CheckBox",
|
|
10436
|
+
"Radio",
|
|
10437
|
+
"RadioGroup",
|
|
10438
|
+
"Slider",
|
|
10439
|
+
"SegmentedControl",
|
|
10440
|
+
"ChoicePicker",
|
|
10441
|
+
"DateTimeInput"
|
|
10442
|
+
]);
|
|
10443
|
+
/** A component id referenced by a `child`/`children` entry or a table cell. */
|
|
10444
|
+
function referencedId(value) {
|
|
10445
|
+
if (typeof value === "string") return value;
|
|
10446
|
+
if (isRecord(value)) {
|
|
10447
|
+
if (typeof value.componentId === "string") return value.componentId;
|
|
10448
|
+
if (typeof value.id === "string") return value.id;
|
|
10449
|
+
}
|
|
10450
|
+
}
|
|
10451
|
+
/** Ids of a table cell / column that renders a component (`{componentId}` or `{id}`). */
|
|
10452
|
+
function cellComponentId(value) {
|
|
10453
|
+
return isRecord(value) ? referencedId(value) : void 0;
|
|
10454
|
+
}
|
|
10455
|
+
/**
|
|
10456
|
+
* Ids a component renders directly: `child`, `children` (string ids, an
|
|
10457
|
+
* array, or a `{componentId}` template), component cells of a Table's
|
|
10458
|
+
* `rows`/`columns`, and the ids that `extra` finds in its typed references.
|
|
10459
|
+
*/
|
|
10460
|
+
function directChildIds(component, extra) {
|
|
10461
|
+
const ids = [];
|
|
10462
|
+
const add = (id) => {
|
|
10463
|
+
if (id) ids.push(id);
|
|
10464
|
+
};
|
|
10465
|
+
const extraIds = extra === null || extra === void 0 ? void 0 : extra(component);
|
|
10466
|
+
if (Array.isArray(extraIds)) extraIds.forEach(add);
|
|
10467
|
+
add(referencedId(component.child));
|
|
10468
|
+
const children = component.children;
|
|
10469
|
+
if (Array.isArray(children)) children.forEach((c) => add(referencedId(c)));
|
|
10470
|
+
else add(referencedId(children));
|
|
10471
|
+
if (Array.isArray(component.columns)) component.columns.forEach((c) => add(cellComponentId(c)));
|
|
10472
|
+
if (Array.isArray(component.rows)) {
|
|
10473
|
+
for (const row of component.rows) if (Array.isArray(row)) row.forEach((c) => add(cellComponentId(c)));
|
|
10474
|
+
}
|
|
10475
|
+
return ids;
|
|
10476
|
+
}
|
|
10477
|
+
/** Components of every updateComponents operation, by id (last definition wins). */
|
|
10478
|
+
function componentsById(operations) {
|
|
10479
|
+
const byId = /* @__PURE__ */ new Map();
|
|
10480
|
+
for (const op of operations) {
|
|
10481
|
+
const update = op.updateComponents;
|
|
10482
|
+
const list = isRecord(update) ? update.components : void 0;
|
|
10483
|
+
if (!Array.isArray(list)) continue;
|
|
10484
|
+
for (const c of list) if (isRecord(c) && typeof c.id === "string") byId.set(c.id, c);
|
|
10485
|
+
}
|
|
10486
|
+
return byId;
|
|
10487
|
+
}
|
|
10488
|
+
function descendantIds(rootId, byId, extra) {
|
|
10489
|
+
var _byId$get;
|
|
10490
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10491
|
+
const stack = [...directChildIds((_byId$get = byId.get(rootId)) !== null && _byId$get !== void 0 ? _byId$get : {}, extra)];
|
|
10492
|
+
while (stack.length > 0) {
|
|
10493
|
+
const id = stack.pop();
|
|
10494
|
+
if (seen.has(id) || id === rootId) continue;
|
|
10495
|
+
seen.add(id);
|
|
10496
|
+
const c = byId.get(id);
|
|
10497
|
+
if (c) stack.push(...directChildIds(c, extra));
|
|
10498
|
+
}
|
|
10499
|
+
return seen;
|
|
10500
|
+
}
|
|
10501
|
+
/**
|
|
10502
|
+
* Ids of the `Card` components that are interactive panels: at least one
|
|
10503
|
+
* descendant (via `child`, `children` or table component cells) is a control
|
|
10504
|
+
* (Button, Pressable, Form, TextField, TextArea, Select, CheckBox, Radio,
|
|
10505
|
+
* RadioGroup, Slider, SegmentedControl, DateTimeInput).
|
|
10506
|
+
*
|
|
10507
|
+
* @param components - The components of one surface.
|
|
10508
|
+
* @returns The ids of the interactive cards.
|
|
10509
|
+
*
|
|
10510
|
+
* @example
|
|
10511
|
+
* ```ts
|
|
10512
|
+
* const interactive = classifySurfaceCards(components);
|
|
10513
|
+
* const keepsBox = interactive.has("quote-form");
|
|
10514
|
+
* ```
|
|
10515
|
+
*/
|
|
10516
|
+
function classifySurfaceCards(components, options = {}) {
|
|
10517
|
+
const byId = /* @__PURE__ */ new Map();
|
|
10518
|
+
for (const c of components) if (isRecord(c) && typeof c.id === "string") byId.set(c.id, c);
|
|
10519
|
+
const interactive = /* @__PURE__ */ new Set();
|
|
10520
|
+
for (const [id, c] of byId) {
|
|
10521
|
+
if (c.component !== "Card") continue;
|
|
10522
|
+
for (const d of descendantIds(id, byId, options.childIds)) {
|
|
10523
|
+
var _byId$get2;
|
|
10524
|
+
const type = (_byId$get2 = byId.get(d)) === null || _byId$get2 === void 0 ? void 0 : _byId$get2.component;
|
|
10525
|
+
if (typeof type === "string" && INTERACTIVE_COMPONENTS.has(type)) {
|
|
10526
|
+
interactive.add(id);
|
|
10527
|
+
break;
|
|
10528
|
+
}
|
|
10529
|
+
}
|
|
10530
|
+
}
|
|
10531
|
+
return interactive;
|
|
10532
|
+
}
|
|
10533
|
+
/**
|
|
10534
|
+
* Markdown mode: only interactive panels keep a box. Every `Card` that is not
|
|
10535
|
+
* an interactive panel (see `classifySurfaceCards`), sets no `variant` or
|
|
10536
|
+
* `border` of its own and is not nested inside an interactive panel becomes
|
|
10537
|
+
* `variant: "section"` (a heading plus content without a box). Operations
|
|
10538
|
+
* other than updateComponents pass through unchanged.
|
|
10539
|
+
*
|
|
10540
|
+
* @param operations - The operations of one surface.
|
|
10541
|
+
* @returns The operations with informational cards set to `variant: "section"`.
|
|
10542
|
+
* When no card changes, it returns the same array.
|
|
10543
|
+
*
|
|
10544
|
+
* @example
|
|
10545
|
+
* ```ts
|
|
10546
|
+
* const operations = flattenInformationalCards(prepared.operations);
|
|
10547
|
+
* ```
|
|
10548
|
+
*/
|
|
10549
|
+
function flattenInformationalCards(operations, options = {}) {
|
|
10550
|
+
const byId = componentsById(operations);
|
|
10551
|
+
if (![...byId.values()].some((c) => c.component === "Card")) return operations;
|
|
10552
|
+
const interactive = classifySurfaceCards([...byId.values()], options);
|
|
10553
|
+
const insideInteractive = /* @__PURE__ */ new Set();
|
|
10554
|
+
for (const id of interactive) for (const d of descendantIds(id, byId, options.childIds)) insideInteractive.add(d);
|
|
10555
|
+
const flatten = (c) => c.component === "Card" && typeof c.id === "string" && !interactive.has(c.id) && !insideInteractive.has(c.id) && c.variant == null && c.border == null;
|
|
10556
|
+
return operations.map((op) => {
|
|
10557
|
+
const update = op.updateComponents;
|
|
10558
|
+
if (!isRecord(update) || !Array.isArray(update.components)) return op;
|
|
10559
|
+
if (!update.components.some((c) => isRecord(c) && flatten(c))) return op;
|
|
10560
|
+
return {
|
|
10561
|
+
...op,
|
|
10562
|
+
updateComponents: {
|
|
10563
|
+
...update,
|
|
10564
|
+
components: update.components.map((c) => isRecord(c) && flatten(c) ? {
|
|
10565
|
+
...c,
|
|
10566
|
+
variant: "section"
|
|
10567
|
+
} : c)
|
|
10568
|
+
}
|
|
10569
|
+
};
|
|
10570
|
+
});
|
|
10571
|
+
}
|
|
10572
|
+
/** Text-bearing components that belong in the chat's markdown, not a surface. */
|
|
10573
|
+
const PROSE_TEXT_COMPONENTS = new Set([
|
|
10574
|
+
"Title",
|
|
10575
|
+
"Text",
|
|
10576
|
+
"Caption",
|
|
10577
|
+
"Markdown"
|
|
10578
|
+
]);
|
|
10579
|
+
/** One line of text: list items and headings cannot span lines in markdown. */
|
|
10580
|
+
function oneLine(text) {
|
|
10581
|
+
return text.trim().replace(/\s*\n\s*/g, " ");
|
|
10582
|
+
}
|
|
10583
|
+
/**
|
|
10584
|
+
* A literal List entry as list-item markdown: a non-empty string, or
|
|
10585
|
+
* `{ label, description? }` with literal strings only. Anything carrying
|
|
10586
|
+
* behaviour or decoration (`icon`, `action`, other keys, bound values) is null.
|
|
10587
|
+
*/
|
|
10588
|
+
function listEntryMarkdown(entry) {
|
|
10589
|
+
if (typeof entry === "string") return entry.trim() ? oneLine(entry) : null;
|
|
10590
|
+
if (!isRecord(entry)) return null;
|
|
10591
|
+
for (const key of Object.keys(entry)) if (key !== "label" && key !== "description") return null;
|
|
10592
|
+
if (typeof entry.label !== "string" || !entry.label.trim()) return null;
|
|
10593
|
+
const label = oneLine(entry.label);
|
|
10594
|
+
if (entry.description === void 0) return label;
|
|
10595
|
+
if (typeof entry.description !== "string") return null;
|
|
10596
|
+
return entry.description.trim() ? `**${label}** — ${oneLine(entry.description)}` : label;
|
|
10597
|
+
}
|
|
10598
|
+
/**
|
|
10599
|
+
* A List of literal text items as a markdown list (`marker: "number"` →
|
|
10600
|
+
* `1. …`, otherwise `- …`), or null when it binds its items, renders
|
|
10601
|
+
* `children`, or any item is not plain text.
|
|
10602
|
+
*/
|
|
10603
|
+
function listToMarkdown(c) {
|
|
10604
|
+
const children = c.children;
|
|
10605
|
+
if (children != null && !(Array.isArray(children) && children.length === 0)) return null;
|
|
10606
|
+
if (!Array.isArray(c.items) || c.items.length === 0) return null;
|
|
10607
|
+
const lines = [];
|
|
10608
|
+
for (const entry of c.items) {
|
|
10609
|
+
const line = listEntryMarkdown(entry);
|
|
10610
|
+
if (line === null) return null;
|
|
10611
|
+
lines.push(line);
|
|
10612
|
+
}
|
|
10613
|
+
if (c.marker === "number") {
|
|
10614
|
+
const start = typeof c.start === "number" && Number.isInteger(c.start) ? c.start : 1;
|
|
10615
|
+
return lines.map((line, i) => `${start + i}. ${line}`).join("\n");
|
|
10616
|
+
}
|
|
10617
|
+
return lines.map((line) => `- ${line}`).join("\n");
|
|
10618
|
+
}
|
|
10619
|
+
/** The prose item a component converts to, or null when it is not prose. */
|
|
10620
|
+
function toProseItem(c) {
|
|
10621
|
+
if (!c) return null;
|
|
10622
|
+
if (c.accessibility !== void 0) return null;
|
|
10623
|
+
if (c.component === "Divider") return { kind: "divider" };
|
|
10624
|
+
if (c.component === "Spacer") return { kind: "spacer" };
|
|
10625
|
+
if (c.component === "List") {
|
|
10626
|
+
if (c.direction !== void 0 && c.direction !== "vertical") return null;
|
|
10627
|
+
const markdown = listToMarkdown(c);
|
|
10628
|
+
return markdown === null ? null : {
|
|
10629
|
+
kind: "text",
|
|
10630
|
+
markdown
|
|
10631
|
+
};
|
|
10632
|
+
}
|
|
10633
|
+
if (typeof c.component !== "string") return null;
|
|
10634
|
+
if (!PROSE_TEXT_COMPONENTS.has(c.component)) return null;
|
|
10635
|
+
if (typeof c.text !== "string" || c.text.trim() === "") return null;
|
|
10636
|
+
const text = c.text.trim();
|
|
10637
|
+
switch (c.component) {
|
|
10638
|
+
case "Title": {
|
|
10639
|
+
const size = typeof c.size === "string" ? c.size : "md";
|
|
10640
|
+
return {
|
|
10641
|
+
kind: "text",
|
|
10642
|
+
markdown: `${size === "sm" ? "####" : size === "md" || size === "lg" ? "###" : "##"} ${text}`
|
|
10643
|
+
};
|
|
10644
|
+
}
|
|
10645
|
+
case "Text":
|
|
10646
|
+
if (directChildIds(c).length > 0) return null;
|
|
10647
|
+
return {
|
|
10648
|
+
kind: "text",
|
|
10649
|
+
markdown: c.strong === true ? `**${text}**` : text
|
|
10650
|
+
};
|
|
10651
|
+
default: return {
|
|
10652
|
+
kind: "text",
|
|
10653
|
+
markdown: text
|
|
10654
|
+
};
|
|
10655
|
+
}
|
|
10656
|
+
}
|
|
10657
|
+
/** Prose items as markdown: separators only survive between two text items. */
|
|
10658
|
+
function proseItemsToMarkdown(items) {
|
|
10659
|
+
const blocks = [];
|
|
10660
|
+
let pendingDivider = false;
|
|
10661
|
+
for (const item of items) if ((item === null || item === void 0 ? void 0 : item.kind) === "text") {
|
|
10662
|
+
if (pendingDivider && blocks.length > 0) blocks.push("---");
|
|
10663
|
+
pendingDivider = false;
|
|
10664
|
+
blocks.push(item.markdown);
|
|
10665
|
+
} else if ((item === null || item === void 0 ? void 0 : item.kind) === "divider") pendingDivider = true;
|
|
10666
|
+
return blocks.join("\n\n");
|
|
10667
|
+
}
|
|
10668
|
+
/** Column, column-direction Box, or an informational Card (section/unset variant). */
|
|
10669
|
+
function isVerticalStack(c, interactiveCards) {
|
|
10670
|
+
if (c.accessibility !== void 0) return false;
|
|
10671
|
+
if (c.component === "Column") return true;
|
|
10672
|
+
if (c.component === "Box") return c.direction == null || c.direction === "col";
|
|
10673
|
+
if (c.component === "Card") return (c.variant == null || c.variant === "section") && typeof c.id === "string" && !interactiveCards.has(c.id);
|
|
10674
|
+
return false;
|
|
10675
|
+
}
|
|
10676
|
+
/** The child-id list of a stack (`children`, or a lone `child`), else null. */
|
|
10677
|
+
/**
|
|
10678
|
+
* The children of a stack in render order: `child` first (a Card renders
|
|
10679
|
+
* its `child` before its `children`), then `children`.
|
|
10680
|
+
*/
|
|
10681
|
+
function stackChildren(c) {
|
|
10682
|
+
const first = typeof c.child === "string" ? [c.child] : [];
|
|
10683
|
+
if (Array.isArray(c.children)) return [...first, ...c.children];
|
|
10684
|
+
if (first.length > 0 && c.children === void 0) return first;
|
|
10685
|
+
return null;
|
|
10686
|
+
}
|
|
10687
|
+
/**
|
|
10688
|
+
* Partitions the stack's children into alternating prose and surface runs.
|
|
10689
|
+
* A run of consecutive prose items is prose only when it holds text: a run of
|
|
10690
|
+
* separators alone (Divider/Spacer between two UI components, or at the very
|
|
10691
|
+
* start/end of the stack) stays with the surface it sits in.
|
|
10692
|
+
*/
|
|
10693
|
+
function partitionChildren(items) {
|
|
10694
|
+
const runs = [];
|
|
10695
|
+
let i = 0;
|
|
10696
|
+
while (i < items.length) {
|
|
10697
|
+
const candidate = items[i] !== null;
|
|
10698
|
+
let hasText = false;
|
|
10699
|
+
let j = i;
|
|
10700
|
+
while (j < items.length && items[j] !== null === candidate) {
|
|
10701
|
+
var _items$j;
|
|
10702
|
+
if (((_items$j = items[j]) === null || _items$j === void 0 ? void 0 : _items$j.kind) === "text") hasText = true;
|
|
10703
|
+
j++;
|
|
10704
|
+
}
|
|
10705
|
+
const prose = candidate && hasText;
|
|
10706
|
+
const last = runs[runs.length - 1];
|
|
10707
|
+
if (!prose && last && !last.prose) last.end = j;
|
|
10708
|
+
else runs.push({
|
|
10709
|
+
prose,
|
|
10710
|
+
start: i,
|
|
10711
|
+
end: j
|
|
10712
|
+
});
|
|
10713
|
+
i = j;
|
|
10714
|
+
}
|
|
10715
|
+
return runs;
|
|
10716
|
+
}
|
|
10717
|
+
/**
|
|
10718
|
+
* Markdown mode: split a surface into markdown and surface segments so that
|
|
10719
|
+
* only real UI renders as A2UI and everything else is the chat's markdown.
|
|
10720
|
+
*
|
|
10721
|
+
* From `root`, descend through single-child vertical containers (Column,
|
|
10722
|
+
* column Box, informational Card) to the first one with several children:
|
|
10723
|
+
* the stack. Its children are partitioned, in order, into runs of prose and
|
|
10724
|
+
* runs of UI. Prose is `Title`, `Text`, `Caption`, `Markdown` with literal
|
|
10725
|
+
* text, a `List` of literal text items, plus `Divider`/`Spacer` next to them:
|
|
10726
|
+
* `Title` → heading by size (sm `####`, md/lg `###`, larger `##`), `Text` →
|
|
10727
|
+
* paragraph (`strong` → `**…**`), `Caption`/`Markdown` → paragraph, `List` →
|
|
10728
|
+
* `- …` (or `1. …` for `marker: "number"`, `**label** — description` for
|
|
10729
|
+
* described items), and a `Divider` between two prose blocks → `---`.
|
|
10730
|
+
*
|
|
10731
|
+
* Not prose: `{path}`-bound text or items, a Text with inline children, a
|
|
10732
|
+
* List with `children`/icons/actions, a template entry, a component with an
|
|
10733
|
+
* `accessibility` envelope, and a child whose component has not streamed
|
|
10734
|
+
* yet. Separators with no text beside them stay in
|
|
10735
|
+
* the surface. An interactive Card (see `classifySurfaceCards`) is never
|
|
10736
|
+
* entered.
|
|
10737
|
+
*
|
|
10738
|
+
* Each prose run becomes a markdown segment; each UI run becomes a surface
|
|
10739
|
+
* segment whose `root` is a copy of the stack (its other props kept, `child`
|
|
10740
|
+
* dropped) with only that run's `children`, followed by every component
|
|
10741
|
+
* reachable from them. When nothing is prose the input comes back as the one
|
|
10742
|
+
* surface segment (same array); when everything is (or `root` itself is),
|
|
10743
|
+
* there are only markdown segments.
|
|
10744
|
+
*
|
|
10745
|
+
* Pure and linear in the number of components, so it runs on every stream
|
|
10746
|
+
* update.
|
|
10747
|
+
*
|
|
10748
|
+
* @param components - The components of one surface, root included.
|
|
10749
|
+
* @returns The segments in render order.
|
|
10750
|
+
*
|
|
10751
|
+
* @example
|
|
10752
|
+
* ```ts
|
|
10753
|
+
* for (const segment of segmentSurfaceProse(components)) {
|
|
10754
|
+
* if (segment.kind === "markdown") renderMarkdown(segment.markdown);
|
|
10755
|
+
* else renderSurface(segment.components);
|
|
10756
|
+
* }
|
|
10757
|
+
* ```
|
|
10758
|
+
*/
|
|
10759
|
+
function segmentSurfaceProse(components, options = {}) {
|
|
10760
|
+
const unchanged = [{
|
|
10761
|
+
kind: "surface",
|
|
10762
|
+
components
|
|
10763
|
+
}];
|
|
10764
|
+
const byId = /* @__PURE__ */ new Map();
|
|
10765
|
+
for (const c of components) if (isRecord(c) && typeof c.id === "string") byId.set(c.id, c);
|
|
10766
|
+
const root = byId.get(_copilotkit_shared.GENERATIVE_UI_ROOT_ID);
|
|
10767
|
+
if (!root) return unchanged;
|
|
10768
|
+
if (components.some((c) => {
|
|
10769
|
+
var _options$childIds;
|
|
10770
|
+
return isRecord(c) && ((_options$childIds = options.childIds) === null || _options$childIds === void 0 ? void 0 : _options$childIds.call(options, c)) === "unknown";
|
|
10771
|
+
})) return unchanged;
|
|
10772
|
+
const rootItem = toProseItem(root);
|
|
10773
|
+
if ((rootItem === null || rootItem === void 0 ? void 0 : rootItem.kind) === "text") return [{
|
|
10774
|
+
kind: "markdown",
|
|
10775
|
+
markdown: rootItem.markdown
|
|
10776
|
+
}];
|
|
10777
|
+
const interactiveCards = classifySurfaceCards(components, options);
|
|
10778
|
+
let stack = root;
|
|
10779
|
+
let stackId = _copilotkit_shared.GENERATIVE_UI_ROOT_ID;
|
|
10780
|
+
let children;
|
|
10781
|
+
const visited = /* @__PURE__ */ new Set();
|
|
10782
|
+
while (true) {
|
|
10783
|
+
if (!isVerticalStack(stack, interactiveCards)) return unchanged;
|
|
10784
|
+
visited.add(stackId);
|
|
10785
|
+
const list = stackChildren(stack);
|
|
10786
|
+
if (!list) return unchanged;
|
|
10787
|
+
children = list;
|
|
10788
|
+
const nextId = list.length === 1 ? list[0] : void 0;
|
|
10789
|
+
if (typeof nextId !== "string") break;
|
|
10790
|
+
const next = byId.get(nextId);
|
|
10791
|
+
if (!next || visited.has(nextId) || toProseItem(next)) break;
|
|
10792
|
+
stack = next;
|
|
10793
|
+
stackId = nextId;
|
|
10794
|
+
}
|
|
10795
|
+
const stackChildIds = children;
|
|
10796
|
+
const items = stackChildIds.map((id) => typeof id === "string" ? toProseItem(byId.get(id)) : null);
|
|
10797
|
+
const runs = partitionChildren(items);
|
|
10798
|
+
if (!runs.some((run) => run.prose)) return unchanged;
|
|
10799
|
+
const surfaceRuns = runs.filter((run) => !run.prose);
|
|
10800
|
+
const owners = /* @__PURE__ */ new Map();
|
|
10801
|
+
surfaceRuns.forEach((run, index) => {
|
|
10802
|
+
const pending = stackChildIds.slice(run.start, run.end).map(referencedId).filter((id) => id !== void 0);
|
|
10803
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10804
|
+
while (pending.length > 0) {
|
|
10805
|
+
const id = pending.pop();
|
|
10806
|
+
if (id === _copilotkit_shared.GENERATIVE_UI_ROOT_ID || id === stackId || seen.has(id)) continue;
|
|
10807
|
+
seen.add(id);
|
|
10808
|
+
const list = owners.get(id);
|
|
10809
|
+
if (list) list.push(index);
|
|
10810
|
+
else owners.set(id, [index]);
|
|
10811
|
+
const c = byId.get(id);
|
|
10812
|
+
if (c) pending.push(...directChildIds(c, options.childIds));
|
|
10813
|
+
}
|
|
10814
|
+
});
|
|
10815
|
+
const surfaceComponents = surfaceRuns.map((run) => {
|
|
10816
|
+
const { child: _child, ...stackRest } = stack;
|
|
10817
|
+
const nextRoot = {
|
|
10818
|
+
...stackRest,
|
|
10819
|
+
id: _copilotkit_shared.GENERATIVE_UI_ROOT_ID,
|
|
10820
|
+
children: stackChildIds.slice(run.start, run.end)
|
|
10821
|
+
};
|
|
10822
|
+
delete nextRoot.child;
|
|
10823
|
+
return [nextRoot];
|
|
10824
|
+
});
|
|
10825
|
+
for (const c of components) {
|
|
10826
|
+
var _owners$get;
|
|
10827
|
+
if (!isRecord(c) || typeof c.id !== "string" || byId.get(c.id) !== c) continue;
|
|
10828
|
+
const ownerIndexes = (_owners$get = owners.get(c.id)) !== null && _owners$get !== void 0 ? _owners$get : [];
|
|
10829
|
+
for (const index of ownerIndexes) surfaceComponents[index].push(c);
|
|
10830
|
+
}
|
|
10831
|
+
let surfaceIndex = 0;
|
|
10832
|
+
return runs.map((run) => {
|
|
10833
|
+
if (run.prose) return {
|
|
10834
|
+
kind: "markdown",
|
|
10835
|
+
markdown: proseItemsToMarkdown(items.slice(run.start, run.end))
|
|
10836
|
+
};
|
|
10837
|
+
return {
|
|
10838
|
+
kind: "surface",
|
|
10839
|
+
components: surfaceComponents[surfaceIndex++]
|
|
10840
|
+
};
|
|
10841
|
+
});
|
|
10842
|
+
}
|
|
10843
|
+
|
|
10844
|
+
//#endregion
|
|
10845
|
+
exports.A2UI_FENCE_LANGUAGE = A2UI_FENCE_LANGUAGE;
|
|
9447
10846
|
exports.AgentRegistry = AgentRegistry;
|
|
9448
10847
|
exports.AgentThreadLockedError = AgentThreadLockedError;
|
|
9449
10848
|
exports.ContextStore = ContextStore;
|
|
@@ -9461,6 +10860,7 @@ exports.StateManager = StateManager;
|
|
|
9461
10860
|
exports.SuggestionEngine = SuggestionEngine;
|
|
9462
10861
|
exports.ToolCallStatus = ToolCallStatus;
|
|
9463
10862
|
exports.WebMCPRegistry = WebMCPRegistry;
|
|
10863
|
+
exports.classifySurfaceCards = classifySurfaceCards;
|
|
9464
10864
|
exports.completePartialMarkdown = completePartialMarkdown;
|
|
9465
10865
|
exports.createActionGroup = createActionGroup;
|
|
9466
10866
|
exports.createEffect = createEffect;
|
|
@@ -9474,6 +10874,11 @@ exports.emitInspectorViewThread = emitInspectorViewThread;
|
|
|
9474
10874
|
exports.emitInspectorViewThreadResult = emitInspectorViewThreadResult;
|
|
9475
10875
|
exports.empty = empty;
|
|
9476
10876
|
exports.ensureObjectArgs = ensureObjectArgs;
|
|
10877
|
+
exports.extractCompleteArrayItems = extractCompleteArrayItems;
|
|
10878
|
+
exports.extractFenceOperations = extractFenceOperations;
|
|
10879
|
+
exports.extractStringField = extractStringField;
|
|
10880
|
+
exports.flattenInformationalCards = flattenInformationalCards;
|
|
10881
|
+
exports.getMarkdownOperationSurfaceId = getMarkdownOperationSurfaceId;
|
|
9477
10882
|
exports.getWebMCPModelContext = getWebMCPModelContext;
|
|
9478
10883
|
exports.isAbortError = isAbortError;
|
|
9479
10884
|
exports.isInspectorThreadBridgeEnabled = isInspectorThreadBridgeEnabled;
|
|
@@ -9485,8 +10890,11 @@ exports.onInspectorStopViewing = onInspectorStopViewing;
|
|
|
9485
10890
|
exports.onInspectorViewThread = onInspectorViewThread;
|
|
9486
10891
|
exports.onInspectorViewThreadResult = onInspectorViewThreadResult;
|
|
9487
10892
|
exports.parseToolArguments = parseToolArguments;
|
|
10893
|
+
exports.prepareSurfaceOperations = prepareSurfaceOperations;
|
|
9488
10894
|
exports.props = props;
|
|
10895
|
+
exports.segmentSurfaceProse = segmentSurfaceProse;
|
|
9489
10896
|
exports.select = select;
|
|
10897
|
+
exports.splitA2UIMarkdown = splitA2UIMarkdown;
|
|
9490
10898
|
exports.ɵCOPILOTKIT_FEATURES = ɵCOPILOTKIT_FEATURES;
|
|
9491
10899
|
exports.ɵInterruptState = ɵInterruptState;
|
|
9492
10900
|
exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
|