@collective-intelligence/external-apps-client-sdk 0.3.5 → 0.3.7
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/AGENTS.md +3 -0
- package/README.md +126 -2
- package/dist/chat.d.ts +15 -0
- package/dist/chat.js +110 -0
- package/dist/client-_rl-iXS8.d.ts +424 -0
- package/dist/effect.d.ts +9 -7
- package/dist/effect.js +4 -3
- package/dist/errors-C3UmgGGu.js +86 -0
- package/dist/{index-BEmAHAvd.d.ts → index-DFCHAlar.d.ts} +1536 -213
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/proxy-DRPEFvaV.d.ts +2847 -0
- package/dist/{resources-B6e3qsBD.js → resources-BZKqGxBT.js} +2 -1
- package/dist/{resources-CALtYMtN.d.ts → resources-r2t8pcv2.d.ts} +3 -513
- package/dist/resources.d.ts +1 -1
- package/dist/resources.js +2 -2
- package/dist/{service-BIyZo-CO.js → service-D-POpqlt.js} +117 -116
- package/dist/{service-Db0c8eg9.js → service-l8wUAlPK.js} +525 -94
- package/docs/chat.md +49 -0
- package/docs/guide/develop/extensions.md +44 -11
- package/docs/guide/platform/access.md +9 -7
- package/docs/guide/platform/architecture.md +17 -2
- package/docs/guide/template/index.md +23 -30
- package/package.json +19 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as FederatedAuthError, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-C3UmgGGu.js";
|
|
2
|
+
import { E as retryAfterMilliseconds, S as fromCiResult, T as createFetchEventSourceFactory, _ as backendErrorCode, b as proxyHttpOptions, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-l8wUAlPK.js";
|
|
2
3
|
import * as Predicate from "effect/Predicate";
|
|
3
4
|
import * as Schema from "effect/Schema";
|
|
4
5
|
import * as Arr from "effect/Array";
|
|
@@ -27,105 +28,6 @@ import * as Deferred from "effect/Deferred";
|
|
|
27
28
|
import * as Data from "effect/Data";
|
|
28
29
|
import * as Equal from "effect/Equal";
|
|
29
30
|
import * as Exit from "effect/Exit";
|
|
30
|
-
const emptyBlock = () => ({
|
|
31
|
-
comment: false,
|
|
32
|
-
data: [],
|
|
33
|
-
id: void 0,
|
|
34
|
-
type: ""
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* A Server-Sent Events parser that, unlike `EventSource`, reports comments:
|
|
38
|
-
* the server's pings are comments, and the client's watchdog needs them.
|
|
39
|
-
*/
|
|
40
|
-
const createEventStreamParser = (handlers) => {
|
|
41
|
-
let buffer = "";
|
|
42
|
-
let block = emptyBlock();
|
|
43
|
-
let retry;
|
|
44
|
-
const dispatch = () => {
|
|
45
|
-
const ended = block;
|
|
46
|
-
block = emptyBlock();
|
|
47
|
-
if (ended.data.length > 0) handlers.onEvent({
|
|
48
|
-
data: ended.data.join("\n"),
|
|
49
|
-
id: ended.id,
|
|
50
|
-
type: ended.type === "" ? "message" : ended.type
|
|
51
|
-
});
|
|
52
|
-
else if (ended.comment || ended.id !== void 0) handlers.onPing(ended.id);
|
|
53
|
-
};
|
|
54
|
-
const line = (text) => {
|
|
55
|
-
if (text === "") {
|
|
56
|
-
dispatch();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (text.startsWith(":")) {
|
|
60
|
-
block.comment = true;
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const colon = text.indexOf(":");
|
|
64
|
-
const field = colon === -1 ? text : text.slice(0, colon);
|
|
65
|
-
const raw = colon === -1 ? "" : text.slice(colon + 1);
|
|
66
|
-
const value = raw.startsWith(" ") ? raw.slice(1) : raw;
|
|
67
|
-
if (field === "data") block.data.push(value);
|
|
68
|
-
else if (field === "event") block.type = value;
|
|
69
|
-
else if (field === "id" && !value.includes("\0")) block.id = value;
|
|
70
|
-
else if (field === "retry" && /^\d+$/u.test(value)) retry = Number(value);
|
|
71
|
-
};
|
|
72
|
-
return {
|
|
73
|
-
push: (chunk) => {
|
|
74
|
-
buffer += chunk;
|
|
75
|
-
const lines = buffer.split("\n");
|
|
76
|
-
buffer = lines.pop() ?? "";
|
|
77
|
-
for (const text of lines) line(text.endsWith("\r") ? text.slice(0, -1) : text);
|
|
78
|
-
},
|
|
79
|
-
/** The last `retry:` the stream sent, in milliseconds. */
|
|
80
|
-
retry: () => retry
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
/** A `Retry-After` header value in milliseconds, seconds form only. */
|
|
84
|
-
const retryAfterMilliseconds = (value) => value !== null && value !== void 0 && /^\d+$/u.test(value) ? Number(value) * 1e3 : void 0;
|
|
85
|
-
/** Reads `text/event-stream` with `fetch`, so pings and refusals are visible. */
|
|
86
|
-
const createFetchEventSourceFactory = (fetch) => (url, handlers) => {
|
|
87
|
-
const abort = new AbortController();
|
|
88
|
-
const live = () => !abort.signal.aborted;
|
|
89
|
-
const parser = createEventStreamParser({
|
|
90
|
-
onEvent: (event) => {
|
|
91
|
-
if (live()) handlers.onEvent(event);
|
|
92
|
-
},
|
|
93
|
-
onPing: (id) => {
|
|
94
|
-
if (live()) handlers.onPing(id);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
const read = async () => {
|
|
98
|
-
try {
|
|
99
|
-
const response = await fetch(url, {
|
|
100
|
-
cache: "no-store",
|
|
101
|
-
headers: { accept: "text/event-stream" },
|
|
102
|
-
signal: abort.signal
|
|
103
|
-
});
|
|
104
|
-
if (!response.ok || response.body === null) {
|
|
105
|
-
parser.push(`${await response.text()}\n\n`);
|
|
106
|
-
if (live()) handlers.onEnd({
|
|
107
|
-
retryMilliseconds: retryAfterMilliseconds(response.headers.get("retry-after")) ?? parser.retry(),
|
|
108
|
-
status: response.status
|
|
109
|
-
});
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (live()) handlers.onOpen();
|
|
113
|
-
const decoder = new TextDecoder();
|
|
114
|
-
const reader = response.body.getReader();
|
|
115
|
-
for (;;) {
|
|
116
|
-
const { done, value } = await reader.read();
|
|
117
|
-
if (done) break;
|
|
118
|
-
parser.push(decoder.decode(value, { stream: true }));
|
|
119
|
-
}
|
|
120
|
-
} catch {}
|
|
121
|
-
if (live()) handlers.onEnd({
|
|
122
|
-
retryMilliseconds: parser.retry(),
|
|
123
|
-
status: void 0
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
read();
|
|
127
|
-
return { close: () => abort.abort() };
|
|
128
|
-
};
|
|
129
31
|
const topicSetDebounceMilliseconds = 300;
|
|
130
32
|
const pingTimeoutMilliseconds = 45e3;
|
|
131
33
|
const backoffBaseMilliseconds = 1e3;
|
|
@@ -422,7 +324,7 @@ const layerBrowser = ({ document, window }) => {
|
|
|
422
324
|
* The page of this runtime: the browser `document` and `window`, or a page
|
|
423
325
|
* that is always visible where they do not exist.
|
|
424
326
|
*/
|
|
425
|
-
const layer$
|
|
327
|
+
const layer$6 = Layer.suspend(() => {
|
|
426
328
|
const host = globalThis;
|
|
427
329
|
return layerBrowser({
|
|
428
330
|
document: host.document,
|
|
@@ -463,7 +365,7 @@ const fromFactory = (factory) => EventStreams.of({ open: (url) => Stream.callbac
|
|
|
463
365
|
/** The streams of a `RealtimeEventSourceFactory`. */
|
|
464
366
|
const layerFromFactory = (factory) => Layer.succeed(EventStreams, fromFactory(factory));
|
|
465
367
|
/** Reads each stream with the `fetch` of `FetchHttpClient.Fetch`. */
|
|
466
|
-
const layer$
|
|
368
|
+
const layer$5 = Layer.effect(EventStreams, FetchHttpClient.Fetch.pipe(Effect.map((fetch) => fromFactory(createFetchEventSourceFactory(fetch)))));
|
|
467
369
|
/** One stable key per topic, whatever the key order of the object. */
|
|
468
370
|
const realtimeTopicKey = ({ filter, schema }) => JSON.stringify(filter === void 0 ? [schema] : [
|
|
469
371
|
schema,
|
|
@@ -850,7 +752,7 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
850
752
|
};
|
|
851
753
|
});
|
|
852
754
|
/** The `RealtimeClient` of one connection, open for the life of the scope. */
|
|
853
|
-
const make$
|
|
755
|
+
const make$5 = Effect.fn("RealtimeClient.make")(function* make(options) {
|
|
854
756
|
const connection = yield* makeConnection({
|
|
855
757
|
...options,
|
|
856
758
|
resyncOnAccessChange: true
|
|
@@ -868,15 +770,15 @@ const make$4 = Effect.fn("RealtimeClient.make")(function* make(options) {
|
|
|
868
770
|
});
|
|
869
771
|
});
|
|
870
772
|
/** `RealtimeClient` over the `HttpClient`, `EventStreams` and `PageLifecycle` of the context. */
|
|
871
|
-
const layerWithoutDependencies = (options) => Layer.effect(RealtimeClient, make$
|
|
773
|
+
const layerWithoutDependencies = (options) => Layer.effect(RealtimeClient, make$5(options));
|
|
872
774
|
/** `RealtimeClient` with the `fetch` of `FetchHttpClient.Fetch` and the page of this runtime. */
|
|
873
|
-
const layer$
|
|
775
|
+
const layer$4 = (options) => layerWithoutDependencies(options).pipe(Layer.provide([
|
|
874
776
|
FetchHttpClient.layer,
|
|
875
|
-
layer$
|
|
876
|
-
layer$
|
|
777
|
+
layer$5,
|
|
778
|
+
layer$6
|
|
877
779
|
]));
|
|
878
780
|
/** `layer` with options that Effect `Config` reads. */
|
|
879
|
-
const layerConfig$2 = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layer$
|
|
781
|
+
const layerConfig$2 = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layer$4));
|
|
880
782
|
/** The changes and Resyncs of `topic` from the `RealtimeClient` of the context. */
|
|
881
783
|
const subscribe = (topic) => Stream.unwrap(RealtimeClient.useSync((client) => client.subscribe(topic)));
|
|
882
784
|
/**
|
|
@@ -888,7 +790,7 @@ const subscribe = (topic) => Stream.unwrap(RealtimeClient.useSync((client) => cl
|
|
|
888
790
|
*/
|
|
889
791
|
var CiClient = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/CiClient") {};
|
|
890
792
|
/** The `CiClient` over one adapter. */
|
|
891
|
-
const make$
|
|
793
|
+
const make$4 = (executeResult) => CiClient.of({
|
|
892
794
|
execute: (operationId, input, options) => Effect.flatMap(executeResult(operationId, input, options), fromCiResult),
|
|
893
795
|
executeResult
|
|
894
796
|
});
|
|
@@ -909,11 +811,11 @@ const executeOf = (executor) => (operationId, input, options) => Effect.tryPromi
|
|
|
909
811
|
})
|
|
910
812
|
}).pipe(Effect.catchCauseIf(() => options.signal?.aborted === true, () => Effect.interrupt), Effect.map(toCiResult));
|
|
911
813
|
/** `CiClient` over the tenant Application HTTP API; a bad `tenantUrl` dies with `TypeError`. */
|
|
912
|
-
const layerDirect = (options) => Layer.sync(CiClient, () => make$
|
|
814
|
+
const layerDirect = (options) => Layer.sync(CiClient, () => make$4(makeHttpExecute(directHttpOptions(options))));
|
|
913
815
|
/** `CiClient` over the app's protocol proxy; a bad `serverUrl` or `path` dies with `TypeError`. */
|
|
914
|
-
const layerProxy = (options) => Layer.sync(CiClient, () => make$
|
|
816
|
+
const layerProxy = (options) => Layer.sync(CiClient, () => make$4(makeHttpExecute(proxyHttpOptions(options))));
|
|
915
817
|
/** `CiClient` over a `TypedOperationExecutor`, such as the transport of `createClient`. */
|
|
916
|
-
const layerFromExecutor = (executor) => Layer.succeed(CiClient, make$
|
|
818
|
+
const layerFromExecutor = (executor) => Layer.succeed(CiClient, make$4(executeOf(executor)));
|
|
917
819
|
/** `layerDirect` with options that Effect `Config` reads. */
|
|
918
820
|
const layerDirectConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layerDirect));
|
|
919
821
|
/** `layerProxy` with options that Effect `Config` reads. */
|
|
@@ -1009,7 +911,7 @@ const followSource = Effect.fnUntraced(function* followSource(source, options) {
|
|
|
1009
911
|
});
|
|
1010
912
|
});
|
|
1011
913
|
var Runs = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/Runs") {};
|
|
1012
|
-
const make$
|
|
914
|
+
const make$3 = Effect.gen(function* make() {
|
|
1013
915
|
const client = yield* CiClient;
|
|
1014
916
|
return Runs.of({ follow: (options) => {
|
|
1015
917
|
const execution = { organizationId: options.organizationId };
|
|
@@ -1020,7 +922,106 @@ const make$2 = Effect.gen(function* make() {
|
|
|
1020
922
|
} });
|
|
1021
923
|
});
|
|
1022
924
|
/** `Runs` over the `CiClient` of the context. */
|
|
1023
|
-
const layer$
|
|
925
|
+
const layer$3 = Layer.effect(Runs, make$3);
|
|
926
|
+
/** The `chat_*` operation of each method of the chat domain. */
|
|
927
|
+
const chatOperations = {
|
|
928
|
+
agentConversations: {
|
|
929
|
+
cancelTurn: "chat_agent_conversations_cancel_turn",
|
|
930
|
+
close: "chat_agent_conversations_close",
|
|
931
|
+
submitTurn: "chat_agent_conversations_submit_turn"
|
|
932
|
+
},
|
|
933
|
+
agents: { list: "chat_agents_list" },
|
|
934
|
+
approvals: {
|
|
935
|
+
decide: "chat_approvals_decide",
|
|
936
|
+
get: "chat_approvals_get",
|
|
937
|
+
reject: "chat_approvals_reject",
|
|
938
|
+
search: "chat_approvals_search",
|
|
939
|
+
searchRequests: "chat_approvals_search_requests",
|
|
940
|
+
withdraw: "chat_approvals_withdraw"
|
|
941
|
+
},
|
|
942
|
+
artifacts: { progress: "chat_artifacts_progress" },
|
|
943
|
+
attachments: {
|
|
944
|
+
capabilities: "chat_attachments_capabilities",
|
|
945
|
+
downloadUrl: "chat_attachments_download_url",
|
|
946
|
+
upload: "chat_attachments_upload"
|
|
947
|
+
},
|
|
948
|
+
compaction: {
|
|
949
|
+
compact: "chat_compaction_compact",
|
|
950
|
+
get: "chat_compaction_get",
|
|
951
|
+
regenerate: "chat_compaction_regenerate",
|
|
952
|
+
reset: "chat_compaction_reset"
|
|
953
|
+
},
|
|
954
|
+
conversations: {
|
|
955
|
+
create: "chat_conversations_create",
|
|
956
|
+
delete: "chat_conversations_delete",
|
|
957
|
+
get: "chat_conversations_get",
|
|
958
|
+
list: "chat_conversations_list",
|
|
959
|
+
transcript: "chat_conversations_transcript",
|
|
960
|
+
update: "chat_conversations_update"
|
|
961
|
+
},
|
|
962
|
+
evidence: { resolve: "chat_evidence_resolve" },
|
|
963
|
+
feedback: {
|
|
964
|
+
clear: "chat_feedback_clear",
|
|
965
|
+
upsert: "chat_feedback_upsert"
|
|
966
|
+
},
|
|
967
|
+
interactions: {
|
|
968
|
+
respond: "chat_interactions_respond",
|
|
969
|
+
stream: "chat_interactions_stream"
|
|
970
|
+
},
|
|
971
|
+
permissions: {
|
|
972
|
+
decideWait: "chat_permissions_decide_wait",
|
|
973
|
+
list: "chat_permissions_list",
|
|
974
|
+
revoke: "chat_permissions_revoke",
|
|
975
|
+
update: "chat_permissions_update"
|
|
976
|
+
},
|
|
977
|
+
placeContext: { get: "chat_place_context_get" },
|
|
978
|
+
presentation: {
|
|
979
|
+
get: "chat_presentation_get",
|
|
980
|
+
stream: "chat_presentation_stream"
|
|
981
|
+
},
|
|
982
|
+
projects: {
|
|
983
|
+
create: "chat_projects_create",
|
|
984
|
+
delete: "chat_projects_delete",
|
|
985
|
+
deleteFile: "chat_projects_delete_file",
|
|
986
|
+
fileDownloadUrl: "chat_projects_file_download_url",
|
|
987
|
+
list: "chat_projects_list",
|
|
988
|
+
listFiles: "chat_projects_list_files",
|
|
989
|
+
update: "chat_projects_update",
|
|
990
|
+
uploadFile: "chat_projects_upload_file"
|
|
991
|
+
},
|
|
992
|
+
queuedMessages: {
|
|
993
|
+
create: "chat_queued_messages_create",
|
|
994
|
+
delete: "chat_queued_messages_delete",
|
|
995
|
+
list: "chat_queued_messages_list",
|
|
996
|
+
update: "chat_queued_messages_update"
|
|
997
|
+
},
|
|
998
|
+
skills: { list: "chat_skills_list" },
|
|
999
|
+
speech: {
|
|
1000
|
+
availability: "chat_speech_availability",
|
|
1001
|
+
createClip: "chat_speech_create_clip",
|
|
1002
|
+
readAloudPart: "chat_speech_read_aloud_part",
|
|
1003
|
+
transcribe: "chat_speech_transcribe"
|
|
1004
|
+
},
|
|
1005
|
+
steeringMessages: { send: "chat_steering_messages_send" },
|
|
1006
|
+
tools: { list: "chat_tools_list" },
|
|
1007
|
+
turns: {
|
|
1008
|
+
cancel: "chat_turns_cancel",
|
|
1009
|
+
stream: "chat_turns_stream",
|
|
1010
|
+
submit: "chat_turns_submit"
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
/**
|
|
1014
|
+
* Internal. The chat domain with `method(id)` as each method. The caller
|
|
1015
|
+
* gives the type of the result, which `chatOperations` decides.
|
|
1016
|
+
*/
|
|
1017
|
+
const mapChatOperations = (method) => Object.fromEntries(Object.entries(chatOperations).map(([group, methods]) => [group, Object.fromEntries(Object.entries(methods).map(([name, operationId]) => [name, method(operationId)]))]));
|
|
1018
|
+
var Chat = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/Chat") {};
|
|
1019
|
+
const make$2 = Effect.gen(function* make() {
|
|
1020
|
+
const client = yield* CiClient;
|
|
1021
|
+
return Chat.of(mapChatOperations((operationId) => (input, options) => client.execute(operationId, input, options)));
|
|
1022
|
+
});
|
|
1023
|
+
/** `Chat` over the `CiClient` of the context. */
|
|
1024
|
+
const layer$2 = Layer.effect(Chat, make$2);
|
|
1024
1025
|
const base64Url = (bytes) => {
|
|
1025
1026
|
let binary = "";
|
|
1026
1027
|
for (const byte of bytes) binary += String.fromCodePoint(byte);
|
|
@@ -1729,7 +1730,7 @@ const make = Effect.fnUntraced(function* make(options) {
|
|
|
1729
1730
|
const layer = (options) => {
|
|
1730
1731
|
const fetch = options.fetch ?? globalThis.fetch;
|
|
1731
1732
|
const { authBasePath, proxyPath } = resolvedPaths(options);
|
|
1732
|
-
return Layer.effect(DelegatedRuntime, make(options)).pipe(Layer.provideMerge(layer$
|
|
1733
|
+
return Layer.effect(DelegatedRuntime, make(options)).pipe(Layer.provideMerge(layer$3), Layer.provideMerge(layerProxy({
|
|
1733
1734
|
authentication: {
|
|
1734
1735
|
credentials: "same-origin",
|
|
1735
1736
|
mode: "server_delegated"
|
|
@@ -1746,4 +1747,4 @@ const layer = (options) => {
|
|
|
1746
1747
|
};
|
|
1747
1748
|
/** `layer` with options that Effect `Config` reads. */
|
|
1748
1749
|
const layerConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layer));
|
|
1749
|
-
export {
|
|
1750
|
+
export { subscribe as A, layerProxy as C, layer$4 as D, RealtimeClient as E, currentLink as F, layer$5 as M, layerFromFactory as N, layerConfig$2 as O, layerBrowser as P, layerFromExecutor as S, make$4 as T, followSource as _, layer$1 as a, layerDirect as b, layerFederated as c, layerServerSessionConfig as d, Chat as f, Runs as g, DEFAULT_FOLLOW_RUN_DEADLINE_MS as h, FixedWorkflows as i, realtimeTopicKey as j, makeConnection as k, layerFederatedConfig as l, mapChatOperations as m, layer as n, layerConfig$1 as o, layer$2 as p, layerConfig as r, FederatedAuth as s, DelegatedRuntime as t, layerServerSession as u, layer$3 as v, layerProxyConfig as w, layerDirectConfig as x, CiClient as y };
|