@copilotkitnext/core 1.52.2-next.1 → 1.52.2-next.2
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 +151 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +42 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +154 -4
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +158 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -4
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ag-ui/client'), require('@copilotkitnext/shared'), require('rxjs'), require('rxjs/operators'), require('zod-to-json-schema')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@ag-ui/client', '@copilotkitnext/shared', 'rxjs', 'rxjs/operators', 'zod-to-json-schema'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitNextCore = {}), global.AgUIClient,global.CopilotKitNextShared,global.rxjs,global.rxjs.operators,global.zodToJsonSchema));
|
|
5
|
-
})(this, function(exports, _ag_ui_client, _copilotkitnext_shared, rxjs, rxjs_operators, zod_to_json_schema) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ag-ui/client'), require('@copilotkitnext/shared'), require('rxjs'), require('rxjs/operators'), require('zod-to-json-schema'), require('phoenix')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@ag-ui/client', '@copilotkitnext/shared', 'rxjs', 'rxjs/operators', 'zod-to-json-schema', 'phoenix'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitNextCore = {}), global.AgUIClient,global.CopilotKitNextShared,global.rxjs,global.rxjs.operators,global.zodToJsonSchema,global.phoenix));
|
|
5
|
+
})(this, function(exports, _ag_ui_client, _copilotkitnext_shared, rxjs, rxjs_operators, zod_to_json_schema, phoenix) {
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
7
|
|
|
8
8
|
//#region \0@oxc-project+runtime@0.112.0/helpers/typeof.js
|
|
@@ -1828,12 +1828,166 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1828
1828
|
return result;
|
|
1829
1829
|
}
|
|
1830
1830
|
|
|
1831
|
+
//#endregion
|
|
1832
|
+
//#region src/intelligence-agent.ts
|
|
1833
|
+
var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAgent {
|
|
1834
|
+
constructor(config) {
|
|
1835
|
+
super();
|
|
1836
|
+
_defineProperty(this, "config", void 0);
|
|
1837
|
+
_defineProperty(this, "socket", null);
|
|
1838
|
+
_defineProperty(this, "activeChannel", null);
|
|
1839
|
+
_defineProperty(this, "threadId", null);
|
|
1840
|
+
this.config = config;
|
|
1841
|
+
}
|
|
1842
|
+
clone() {
|
|
1843
|
+
return new IntelligenceAgent(this.config);
|
|
1844
|
+
}
|
|
1845
|
+
abortRun() {
|
|
1846
|
+
if (!this.threadId) return;
|
|
1847
|
+
if (typeof fetch === "undefined") {
|
|
1848
|
+
this.cleanup();
|
|
1849
|
+
return;
|
|
1850
|
+
}
|
|
1851
|
+
const { runtimeUrl, agentId, headers, credentials } = this.config;
|
|
1852
|
+
const stopPath = `${runtimeUrl}/agent/${encodeURIComponent(agentId)}/stop/${encodeURIComponent(this.threadId)}`;
|
|
1853
|
+
const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
|
|
1854
|
+
const stopUrl = new URL(stopPath, new URL(runtimeUrl, origin));
|
|
1855
|
+
fetch(stopUrl.toString(), {
|
|
1856
|
+
method: "POST",
|
|
1857
|
+
headers: {
|
|
1858
|
+
"Content-Type": "application/json",
|
|
1859
|
+
...headers
|
|
1860
|
+
},
|
|
1861
|
+
...credentials ? { credentials } : {}
|
|
1862
|
+
}).catch((error) => {
|
|
1863
|
+
console.error("IntelligenceAgent: stop request failed", error);
|
|
1864
|
+
});
|
|
1865
|
+
this.cleanup();
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Connect to a Phoenix channel scoped to the thread, trigger the run via
|
|
1869
|
+
* REST, and relay server-pushed AG-UI events to the Observable subscriber.
|
|
1870
|
+
*
|
|
1871
|
+
* The server pushes each AG-UI event using its EventType string as the
|
|
1872
|
+
* Phoenix event name (e.g. "TEXT_MESSAGE_CHUNK", "TOOL_CALL_START"), with
|
|
1873
|
+
* the full BaseEvent as payload. RUN_FINISHED and RUN_ERROR are terminal
|
|
1874
|
+
* events that complete or error the Observable.
|
|
1875
|
+
*/
|
|
1876
|
+
run(input) {
|
|
1877
|
+
return new rxjs.Observable((observer) => {
|
|
1878
|
+
var _this$config$socketPa;
|
|
1879
|
+
this.threadId = input.threadId;
|
|
1880
|
+
const socket = new phoenix.Socket(this.config.url, { params: (_this$config$socketPa = this.config.socketParams) !== null && _this$config$socketPa !== void 0 ? _this$config$socketPa : {} });
|
|
1881
|
+
this.socket = socket;
|
|
1882
|
+
socket.connect();
|
|
1883
|
+
const channel = socket.channel(`agent:${input.threadId}`, { runId: input.runId });
|
|
1884
|
+
this.activeChannel = channel;
|
|
1885
|
+
channel.on(_copilotkitnext_shared.AG_UI_CHANNEL_EVENT, (payload) => {
|
|
1886
|
+
observer.next(payload);
|
|
1887
|
+
if (payload.type === _ag_ui_client.EventType.RUN_FINISHED) {
|
|
1888
|
+
observer.complete();
|
|
1889
|
+
this.cleanup();
|
|
1890
|
+
} else if (payload.type === _ag_ui_client.EventType.RUN_ERROR) {
|
|
1891
|
+
var _message;
|
|
1892
|
+
observer.error(new Error((_message = payload.message) !== null && _message !== void 0 ? _message : "Run error"));
|
|
1893
|
+
this.cleanup();
|
|
1894
|
+
}
|
|
1895
|
+
});
|
|
1896
|
+
channel.join().receive("ok", () => {
|
|
1897
|
+
const { runtimeUrl, agentId, headers, credentials } = this.config;
|
|
1898
|
+
const runPath = `${runtimeUrl}/agent/${encodeURIComponent(agentId)}/run`;
|
|
1899
|
+
const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
|
|
1900
|
+
const runUrl = new URL(runPath, new URL(runtimeUrl, origin));
|
|
1901
|
+
fetch(runUrl.toString(), {
|
|
1902
|
+
method: "POST",
|
|
1903
|
+
headers: {
|
|
1904
|
+
"Content-Type": "application/json",
|
|
1905
|
+
...headers
|
|
1906
|
+
},
|
|
1907
|
+
body: JSON.stringify({
|
|
1908
|
+
threadId: input.threadId,
|
|
1909
|
+
runId: input.runId,
|
|
1910
|
+
messages: input.messages,
|
|
1911
|
+
tools: input.tools,
|
|
1912
|
+
context: input.context,
|
|
1913
|
+
state: input.state,
|
|
1914
|
+
forwardedProps: input.forwardedProps
|
|
1915
|
+
}),
|
|
1916
|
+
...credentials ? { credentials } : {}
|
|
1917
|
+
}).catch((error) => {
|
|
1918
|
+
var _error$message;
|
|
1919
|
+
observer.error(/* @__PURE__ */ new Error(`REST run request failed: ${(_error$message = error.message) !== null && _error$message !== void 0 ? _error$message : error}`));
|
|
1920
|
+
this.cleanup();
|
|
1921
|
+
});
|
|
1922
|
+
}).receive("error", (resp) => {
|
|
1923
|
+
observer.error(/* @__PURE__ */ new Error(`Failed to join channel: ${JSON.stringify(resp)}`));
|
|
1924
|
+
this.cleanup();
|
|
1925
|
+
}).receive("timeout", () => {
|
|
1926
|
+
observer.error(/* @__PURE__ */ new Error("Timed out joining channel"));
|
|
1927
|
+
this.cleanup();
|
|
1928
|
+
});
|
|
1929
|
+
return () => {
|
|
1930
|
+
this.cleanup();
|
|
1931
|
+
};
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Reconnect to an existing thread by joining the Phoenix channel in
|
|
1936
|
+
* "connect" mode and requesting the server replay history.
|
|
1937
|
+
*/
|
|
1938
|
+
connect(input) {
|
|
1939
|
+
return new rxjs.Observable((observer) => {
|
|
1940
|
+
var _this$config$socketPa2;
|
|
1941
|
+
this.threadId = input.threadId;
|
|
1942
|
+
const socket = new phoenix.Socket(this.config.url, { params: (_this$config$socketPa2 = this.config.socketParams) !== null && _this$config$socketPa2 !== void 0 ? _this$config$socketPa2 : {} });
|
|
1943
|
+
this.socket = socket;
|
|
1944
|
+
socket.connect();
|
|
1945
|
+
const channel = socket.channel(`agent:${input.threadId}`, { mode: "connect" });
|
|
1946
|
+
this.activeChannel = channel;
|
|
1947
|
+
channel.on(_copilotkitnext_shared.AG_UI_CHANNEL_EVENT, (payload) => {
|
|
1948
|
+
observer.next(payload);
|
|
1949
|
+
if (payload.type === _ag_ui_client.EventType.RUN_FINISHED || payload.type === _ag_ui_client.EventType.RUN_ERROR) {
|
|
1950
|
+
observer.complete();
|
|
1951
|
+
this.cleanup();
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
channel.join().receive("ok", () => {
|
|
1955
|
+
channel.push(_ag_ui_client.EventType.CUSTOM, {
|
|
1956
|
+
type: _ag_ui_client.EventType.CUSTOM,
|
|
1957
|
+
name: "connect",
|
|
1958
|
+
value: { threadId: input.threadId }
|
|
1959
|
+
});
|
|
1960
|
+
}).receive("error", (resp) => {
|
|
1961
|
+
observer.error(/* @__PURE__ */ new Error(`Failed to join channel: ${JSON.stringify(resp)}`));
|
|
1962
|
+
this.cleanup();
|
|
1963
|
+
}).receive("timeout", () => {
|
|
1964
|
+
observer.error(/* @__PURE__ */ new Error("Timed out joining channel"));
|
|
1965
|
+
this.cleanup();
|
|
1966
|
+
});
|
|
1967
|
+
return () => {
|
|
1968
|
+
this.cleanup();
|
|
1969
|
+
};
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
cleanup() {
|
|
1973
|
+
if (this.activeChannel) {
|
|
1974
|
+
this.activeChannel.leave();
|
|
1975
|
+
this.activeChannel = null;
|
|
1976
|
+
}
|
|
1977
|
+
if (this.socket) {
|
|
1978
|
+
this.socket.disconnect();
|
|
1979
|
+
this.socket = null;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
|
|
1831
1984
|
//#endregion
|
|
1832
1985
|
exports.AgentRegistry = AgentRegistry;
|
|
1833
1986
|
exports.ContextStore = ContextStore;
|
|
1834
1987
|
exports.CopilotKitCore = CopilotKitCore;
|
|
1835
1988
|
exports.CopilotKitCoreErrorCode = CopilotKitCoreErrorCode;
|
|
1836
1989
|
exports.CopilotKitCoreRuntimeConnectionStatus = CopilotKitCoreRuntimeConnectionStatus;
|
|
1990
|
+
exports.IntelligenceAgent = IntelligenceAgent;
|
|
1837
1991
|
exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
|
|
1838
1992
|
exports.RunHandler = RunHandler;
|
|
1839
1993
|
exports.StateManager = StateManager;
|