@collective-intelligence/external-apps-client-sdk 0.3.4 → 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-DhKJ4NCr.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-DVq8jSnc.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,3 +1,4 @@
|
|
|
1
|
+
import { c as __commonJSMin, l as __toESM, r as CiTransportError, s as ciErrorCodes, t as CiError } from "./errors-C3UmgGGu.js";
|
|
1
2
|
import * as Predicate from "effect/Predicate";
|
|
2
3
|
import * as Schema from "effect/Schema";
|
|
3
4
|
import * as Config from "effect/Config";
|
|
@@ -6,92 +7,109 @@ import * as Effect from "effect/Effect";
|
|
|
6
7
|
import * as Layer from "effect/Layer";
|
|
7
8
|
import * as Option from "effect/Option";
|
|
8
9
|
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
const emptyBlock = () => ({
|
|
11
|
+
comment: false,
|
|
12
|
+
data: [],
|
|
13
|
+
id: void 0,
|
|
14
|
+
type: ""
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* A Server-Sent Events parser that, unlike `EventSource`, reports comments:
|
|
18
|
+
* the server's pings are comments, and the client's watchdog needs them.
|
|
19
|
+
*/
|
|
20
|
+
const createEventStreamParser = (handlers) => {
|
|
21
|
+
let buffer = "";
|
|
22
|
+
let block = emptyBlock();
|
|
23
|
+
let retry;
|
|
24
|
+
const dispatch = () => {
|
|
25
|
+
const ended = block;
|
|
26
|
+
block = emptyBlock();
|
|
27
|
+
if (ended.data.length > 0) handlers.onEvent({
|
|
28
|
+
data: ended.data.join("\n"),
|
|
29
|
+
id: ended.id,
|
|
30
|
+
type: ended.type === "" ? "message" : ended.type
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
else if (ended.comment || ended.id !== void 0) handlers.onPing(ended.id);
|
|
33
|
+
};
|
|
34
|
+
const line = (text) => {
|
|
35
|
+
if (text === "") {
|
|
36
|
+
dispatch();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (text.startsWith(":")) {
|
|
40
|
+
block.comment = true;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const colon = text.indexOf(":");
|
|
44
|
+
const field = colon === -1 ? text : text.slice(0, colon);
|
|
45
|
+
const raw = colon === -1 ? "" : text.slice(colon + 1);
|
|
46
|
+
const value = raw.startsWith(" ") ? raw.slice(1) : raw;
|
|
47
|
+
if (field === "data") block.data.push(value);
|
|
48
|
+
else if (field === "event") block.type = value;
|
|
49
|
+
else if (field === "id" && !value.includes("\0")) block.id = value;
|
|
50
|
+
else if (field === "retry" && /^\d+$/u.test(value)) retry = Number(value);
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
push: (chunk) => {
|
|
54
|
+
buffer += chunk;
|
|
55
|
+
const lines = buffer.split("\n");
|
|
56
|
+
buffer = lines.pop() ?? "";
|
|
57
|
+
for (const text of lines) line(text.endsWith("\r") ? text.slice(0, -1) : text);
|
|
58
|
+
},
|
|
59
|
+
/** The last `retry:` the stream sent, in milliseconds. */
|
|
60
|
+
retry: () => retry
|
|
61
|
+
};
|
|
34
62
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}) {};
|
|
77
|
-
/** An Expected Error of the federated sign-in flow. */
|
|
78
|
-
var FederatedAuthError = class extends Schema.TaggedError()("FederatedAuthError", {
|
|
79
|
-
code: FederatedAuthErrorCode,
|
|
80
|
-
message: Schema.String
|
|
81
|
-
}) {
|
|
82
|
-
constructor(first, second) {
|
|
83
|
-
if (Predicate.isString(first)) super({
|
|
84
|
-
code: first,
|
|
85
|
-
message: Predicate.isString(second) ? second : ""
|
|
63
|
+
/** A `Retry-After` header value in milliseconds, seconds form only. */
|
|
64
|
+
const retryAfterMilliseconds = (value) => value !== null && value !== void 0 && /^\d+$/u.test(value) ? Number(value) * 1e3 : void 0;
|
|
65
|
+
/** Reads `text/event-stream` with `fetch`, so pings and refusals are visible. */
|
|
66
|
+
const createFetchEventSourceFactory = (fetch) => (url, handlers) => {
|
|
67
|
+
const abort = new AbortController();
|
|
68
|
+
const live = () => !abort.signal.aborted;
|
|
69
|
+
const parser = createEventStreamParser({
|
|
70
|
+
onEvent: (event) => {
|
|
71
|
+
if (live()) handlers.onEvent(event);
|
|
72
|
+
},
|
|
73
|
+
onPing: (id) => {
|
|
74
|
+
if (live()) handlers.onPing(id);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const read = async () => {
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(url, {
|
|
80
|
+
cache: "no-store",
|
|
81
|
+
headers: { accept: "text/event-stream" },
|
|
82
|
+
signal: abort.signal
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok || response.body === null) {
|
|
85
|
+
parser.push(`${await response.text()}\n\n`);
|
|
86
|
+
if (live()) handlers.onEnd({
|
|
87
|
+
retryMilliseconds: retryAfterMilliseconds(response.headers.get("retry-after")) ?? parser.retry(),
|
|
88
|
+
status: response.status
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (live()) handlers.onOpen();
|
|
93
|
+
const decoder = new TextDecoder();
|
|
94
|
+
const reader = response.body.getReader();
|
|
95
|
+
for (;;) {
|
|
96
|
+
const { done, value } = await reader.read();
|
|
97
|
+
if (done) break;
|
|
98
|
+
parser.push(decoder.decode(value, { stream: true }));
|
|
99
|
+
}
|
|
100
|
+
} catch {}
|
|
101
|
+
if (live()) handlers.onEnd({
|
|
102
|
+
retryMilliseconds: parser.retry(),
|
|
103
|
+
status: void 0
|
|
86
104
|
});
|
|
87
|
-
|
|
88
|
-
|
|
105
|
+
};
|
|
106
|
+
read();
|
|
107
|
+
return { close: () => abort.abort() };
|
|
89
108
|
};
|
|
90
|
-
/** The request did not reach CI, or CI's response was not readable. */
|
|
91
|
-
var CiTransportError = class extends Schema.TaggedError()("CiTransportError", { cause: Schema.Defect() }) {};
|
|
92
109
|
const completeOperationRegistry = (ids) => ids;
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
const completeChatOperationRegistry = (ids) => ids;
|
|
111
|
+
/** Runtime counterpart of the dedicated-HTTP request discriminant union. */
|
|
112
|
+
const externalApplicationOperationIds = completeOperationRegistry([
|
|
95
113
|
"context_get",
|
|
96
114
|
"knowledge_query",
|
|
97
115
|
"knowledge_get_entity_schema_snapshot",
|
|
@@ -118,6 +136,69 @@ const clientOperationIds = completeOperationRegistry([
|
|
|
118
136
|
"conversations_continue",
|
|
119
137
|
"conversations_history"
|
|
120
138
|
]);
|
|
139
|
+
/** Runtime counterpart of `ExternalApplicationChatOperationId`. */
|
|
140
|
+
const externalApplicationChatOperationIds = completeChatOperationRegistry([
|
|
141
|
+
"chat_conversations_list",
|
|
142
|
+
"chat_conversations_create",
|
|
143
|
+
"chat_conversations_get",
|
|
144
|
+
"chat_conversations_update",
|
|
145
|
+
"chat_conversations_delete",
|
|
146
|
+
"chat_conversations_transcript",
|
|
147
|
+
"chat_turns_submit",
|
|
148
|
+
"chat_turns_stream",
|
|
149
|
+
"chat_turns_cancel",
|
|
150
|
+
"chat_steering_messages_send",
|
|
151
|
+
"chat_queued_messages_create",
|
|
152
|
+
"chat_queued_messages_list",
|
|
153
|
+
"chat_queued_messages_update",
|
|
154
|
+
"chat_queued_messages_delete",
|
|
155
|
+
"chat_place_context_get",
|
|
156
|
+
"chat_presentation_get",
|
|
157
|
+
"chat_presentation_stream",
|
|
158
|
+
"chat_agents_list",
|
|
159
|
+
"chat_skills_list",
|
|
160
|
+
"chat_tools_list",
|
|
161
|
+
"chat_agent_conversations_submit_turn",
|
|
162
|
+
"chat_agent_conversations_cancel_turn",
|
|
163
|
+
"chat_agent_conversations_close",
|
|
164
|
+
"chat_attachments_upload",
|
|
165
|
+
"chat_attachments_download_url",
|
|
166
|
+
"chat_attachments_capabilities",
|
|
167
|
+
"chat_feedback_upsert",
|
|
168
|
+
"chat_feedback_clear",
|
|
169
|
+
"chat_approvals_search_requests",
|
|
170
|
+
"chat_approvals_search",
|
|
171
|
+
"chat_approvals_get",
|
|
172
|
+
"chat_approvals_decide",
|
|
173
|
+
"chat_approvals_reject",
|
|
174
|
+
"chat_approvals_withdraw",
|
|
175
|
+
"chat_permissions_decide_wait",
|
|
176
|
+
"chat_permissions_list",
|
|
177
|
+
"chat_permissions_update",
|
|
178
|
+
"chat_permissions_revoke",
|
|
179
|
+
"chat_artifacts_progress",
|
|
180
|
+
"chat_compaction_get",
|
|
181
|
+
"chat_compaction_compact",
|
|
182
|
+
"chat_compaction_regenerate",
|
|
183
|
+
"chat_compaction_reset",
|
|
184
|
+
"chat_evidence_resolve",
|
|
185
|
+
"chat_interactions_respond",
|
|
186
|
+
"chat_interactions_stream",
|
|
187
|
+
"chat_projects_list",
|
|
188
|
+
"chat_projects_create",
|
|
189
|
+
"chat_projects_update",
|
|
190
|
+
"chat_projects_delete",
|
|
191
|
+
"chat_projects_list_files",
|
|
192
|
+
"chat_projects_upload_file",
|
|
193
|
+
"chat_projects_delete_file",
|
|
194
|
+
"chat_projects_file_download_url",
|
|
195
|
+
"chat_speech_create_clip",
|
|
196
|
+
"chat_speech_transcribe",
|
|
197
|
+
"chat_speech_availability",
|
|
198
|
+
"chat_speech_read_aloud_part"
|
|
199
|
+
]);
|
|
200
|
+
/** Generated, curated external-application operation authority: the application and the chat operations. */
|
|
201
|
+
const clientOperationIds = [...externalApplicationOperationIds, ...externalApplicationChatOperationIds];
|
|
121
202
|
const clientOperationIdSet = new Set(clientOperationIds);
|
|
122
203
|
const isClientOperationId = (value) => clientOperationIdSet.has(value);
|
|
123
204
|
const decodeCiError = Schema.decodeUnknownOption(CiError);
|
|
@@ -277,6 +358,297 @@ const runCall = (operationId, record) => {
|
|
|
277
358
|
default: return null;
|
|
278
359
|
}
|
|
279
360
|
};
|
|
361
|
+
/** The External App chat route of each `chat_*` operation; `path` is checked against the generated route. */
|
|
362
|
+
const chatRoutes = {
|
|
363
|
+
chat_agent_conversations_cancel_turn: {
|
|
364
|
+
method: "POST",
|
|
365
|
+
path: "/chat/conversations/{conversationId}/agent-turns/{turnId}/cancel"
|
|
366
|
+
},
|
|
367
|
+
chat_agent_conversations_close: {
|
|
368
|
+
method: "POST",
|
|
369
|
+
path: "/chat/conversations/{conversationId}/agent-close"
|
|
370
|
+
},
|
|
371
|
+
chat_agent_conversations_submit_turn: {
|
|
372
|
+
method: "POST",
|
|
373
|
+
path: "/chat/conversations/{conversationId}/agent-turns"
|
|
374
|
+
},
|
|
375
|
+
chat_agents_list: {
|
|
376
|
+
method: "GET",
|
|
377
|
+
path: "/chat/agents"
|
|
378
|
+
},
|
|
379
|
+
chat_approvals_decide: {
|
|
380
|
+
method: "POST",
|
|
381
|
+
path: "/chat/approvals/{approvalId}/decision"
|
|
382
|
+
},
|
|
383
|
+
chat_approvals_get: {
|
|
384
|
+
method: "GET",
|
|
385
|
+
path: "/chat/approvals/{approvalId}"
|
|
386
|
+
},
|
|
387
|
+
chat_approvals_reject: {
|
|
388
|
+
method: "POST",
|
|
389
|
+
path: "/chat/approvals/{approvalId}/reject"
|
|
390
|
+
},
|
|
391
|
+
chat_approvals_search: {
|
|
392
|
+
method: "POST",
|
|
393
|
+
path: "/chat/approvals/search"
|
|
394
|
+
},
|
|
395
|
+
chat_approvals_search_requests: {
|
|
396
|
+
method: "POST",
|
|
397
|
+
path: "/chat/approvals/requests/search"
|
|
398
|
+
},
|
|
399
|
+
chat_approvals_withdraw: {
|
|
400
|
+
method: "POST",
|
|
401
|
+
path: "/chat/approvals/{approvalId}/withdraw"
|
|
402
|
+
},
|
|
403
|
+
chat_artifacts_progress: {
|
|
404
|
+
method: "GET",
|
|
405
|
+
path: "/chat/conversations/{conversationId}/artifact-progress"
|
|
406
|
+
},
|
|
407
|
+
chat_attachments_capabilities: {
|
|
408
|
+
method: "GET",
|
|
409
|
+
path: "/chat/attachment-capabilities"
|
|
410
|
+
},
|
|
411
|
+
chat_attachments_download_url: {
|
|
412
|
+
method: "GET",
|
|
413
|
+
path: "/chat/conversations/{conversationId}/attachments/{attachmentId}/download-url"
|
|
414
|
+
},
|
|
415
|
+
chat_attachments_upload: {
|
|
416
|
+
form: true,
|
|
417
|
+
method: "POST",
|
|
418
|
+
path: "/chat/conversations/{conversationId}/attachments"
|
|
419
|
+
},
|
|
420
|
+
chat_compaction_compact: {
|
|
421
|
+
method: "POST",
|
|
422
|
+
path: "/chat/conversations/{conversationId}/compactions"
|
|
423
|
+
},
|
|
424
|
+
chat_compaction_get: {
|
|
425
|
+
method: "GET",
|
|
426
|
+
path: "/chat/conversations/{conversationId}/compaction"
|
|
427
|
+
},
|
|
428
|
+
chat_compaction_regenerate: {
|
|
429
|
+
method: "POST",
|
|
430
|
+
path: "/chat/conversations/{conversationId}/compactions/regenerate"
|
|
431
|
+
},
|
|
432
|
+
chat_compaction_reset: {
|
|
433
|
+
method: "DELETE",
|
|
434
|
+
path: "/chat/conversations/{conversationId}/compactions/active"
|
|
435
|
+
},
|
|
436
|
+
chat_conversations_create: {
|
|
437
|
+
method: "POST",
|
|
438
|
+
path: "/chat/conversations"
|
|
439
|
+
},
|
|
440
|
+
chat_conversations_delete: {
|
|
441
|
+
method: "DELETE",
|
|
442
|
+
path: "/chat/conversations/{conversationId}"
|
|
443
|
+
},
|
|
444
|
+
chat_conversations_get: {
|
|
445
|
+
method: "GET",
|
|
446
|
+
path: "/chat/conversations/{conversationId}"
|
|
447
|
+
},
|
|
448
|
+
chat_conversations_list: {
|
|
449
|
+
method: "GET",
|
|
450
|
+
path: "/chat/conversations"
|
|
451
|
+
},
|
|
452
|
+
chat_conversations_transcript: {
|
|
453
|
+
method: "GET",
|
|
454
|
+
path: "/chat/conversations/{conversationId}/transcript"
|
|
455
|
+
},
|
|
456
|
+
chat_conversations_update: {
|
|
457
|
+
method: "PATCH",
|
|
458
|
+
path: "/chat/conversations/{conversationId}"
|
|
459
|
+
},
|
|
460
|
+
chat_evidence_resolve: {
|
|
461
|
+
method: "POST",
|
|
462
|
+
path: "/chat/invocations/{invocationId}/evidence-navigation"
|
|
463
|
+
},
|
|
464
|
+
chat_feedback_clear: {
|
|
465
|
+
method: "DELETE",
|
|
466
|
+
path: "/chat/answers/{invocationId}/feedback"
|
|
467
|
+
},
|
|
468
|
+
chat_feedback_upsert: {
|
|
469
|
+
method: "PUT",
|
|
470
|
+
path: "/chat/answers/{invocationId}/feedback"
|
|
471
|
+
},
|
|
472
|
+
chat_interactions_respond: {
|
|
473
|
+
method: "POST",
|
|
474
|
+
path: "/chat/interactions/{interactionId}/response"
|
|
475
|
+
},
|
|
476
|
+
chat_interactions_stream: {
|
|
477
|
+
method: "POST",
|
|
478
|
+
parse: "event_frames",
|
|
479
|
+
path: "/chat/interactions/{interactionId}/response/stream"
|
|
480
|
+
},
|
|
481
|
+
chat_permissions_decide_wait: {
|
|
482
|
+
method: "POST",
|
|
483
|
+
path: "/chat/capability-permission-waits/{invocationId}/decision"
|
|
484
|
+
},
|
|
485
|
+
chat_permissions_list: {
|
|
486
|
+
method: "GET",
|
|
487
|
+
path: "/chat/capability-permissions"
|
|
488
|
+
},
|
|
489
|
+
chat_permissions_revoke: {
|
|
490
|
+
method: "DELETE",
|
|
491
|
+
path: "/chat/capability-permissions/{permissionId}"
|
|
492
|
+
},
|
|
493
|
+
chat_permissions_update: {
|
|
494
|
+
method: "PATCH",
|
|
495
|
+
path: "/chat/capability-permissions/{permissionId}"
|
|
496
|
+
},
|
|
497
|
+
chat_place_context_get: {
|
|
498
|
+
method: "GET",
|
|
499
|
+
path: "/chat/chat/place-context"
|
|
500
|
+
},
|
|
501
|
+
chat_presentation_get: {
|
|
502
|
+
method: "GET",
|
|
503
|
+
path: "/chat/executions/{invocationId}/presentation"
|
|
504
|
+
},
|
|
505
|
+
chat_presentation_stream: {
|
|
506
|
+
method: "GET",
|
|
507
|
+
parse: "event_frames",
|
|
508
|
+
path: "/chat/executions/{invocationId}/presentation/stream"
|
|
509
|
+
},
|
|
510
|
+
chat_projects_create: {
|
|
511
|
+
method: "POST",
|
|
512
|
+
path: "/chat/projects"
|
|
513
|
+
},
|
|
514
|
+
chat_projects_delete: {
|
|
515
|
+
method: "DELETE",
|
|
516
|
+
path: "/chat/projects/{projectId}"
|
|
517
|
+
},
|
|
518
|
+
chat_projects_delete_file: {
|
|
519
|
+
method: "DELETE",
|
|
520
|
+
path: "/chat/projects/{projectId}/files/{fileId}"
|
|
521
|
+
},
|
|
522
|
+
chat_projects_file_download_url: {
|
|
523
|
+
method: "GET",
|
|
524
|
+
path: "/chat/projects/{projectId}/files/{fileId}/download-url"
|
|
525
|
+
},
|
|
526
|
+
chat_projects_list: {
|
|
527
|
+
method: "GET",
|
|
528
|
+
path: "/chat/projects"
|
|
529
|
+
},
|
|
530
|
+
chat_projects_list_files: {
|
|
531
|
+
method: "GET",
|
|
532
|
+
path: "/chat/projects/{projectId}/files"
|
|
533
|
+
},
|
|
534
|
+
chat_projects_update: {
|
|
535
|
+
method: "PATCH",
|
|
536
|
+
path: "/chat/projects/{projectId}"
|
|
537
|
+
},
|
|
538
|
+
chat_projects_upload_file: {
|
|
539
|
+
form: true,
|
|
540
|
+
method: "POST",
|
|
541
|
+
path: "/chat/projects/{projectId}/files"
|
|
542
|
+
},
|
|
543
|
+
chat_queued_messages_create: {
|
|
544
|
+
method: "POST",
|
|
545
|
+
path: "/chat/chat/conversations/{conversationId}/queued-messages"
|
|
546
|
+
},
|
|
547
|
+
chat_queued_messages_delete: {
|
|
548
|
+
method: "DELETE",
|
|
549
|
+
path: "/chat/chat/conversations/{conversationId}/queued-messages/{queuedMessageId}"
|
|
550
|
+
},
|
|
551
|
+
chat_queued_messages_list: {
|
|
552
|
+
method: "GET",
|
|
553
|
+
path: "/chat/chat/conversations/{conversationId}/queued-messages"
|
|
554
|
+
},
|
|
555
|
+
chat_queued_messages_update: {
|
|
556
|
+
method: "PATCH",
|
|
557
|
+
path: "/chat/chat/conversations/{conversationId}/queued-messages/{queuedMessageId}"
|
|
558
|
+
},
|
|
559
|
+
chat_skills_list: {
|
|
560
|
+
method: "GET",
|
|
561
|
+
path: "/chat/skills"
|
|
562
|
+
},
|
|
563
|
+
chat_speech_availability: {
|
|
564
|
+
method: "GET",
|
|
565
|
+
path: "/chat/speech/availability"
|
|
566
|
+
},
|
|
567
|
+
chat_speech_create_clip: {
|
|
568
|
+
method: "POST",
|
|
569
|
+
path: "/chat/speech/clips"
|
|
570
|
+
},
|
|
571
|
+
chat_speech_read_aloud_part: {
|
|
572
|
+
method: "GET",
|
|
573
|
+
path: "/chat/speech/read-aloud/{invocationId}/parts/{partIndex}"
|
|
574
|
+
},
|
|
575
|
+
chat_speech_transcribe: {
|
|
576
|
+
method: "POST",
|
|
577
|
+
path: "/chat/speech/transcriptions"
|
|
578
|
+
},
|
|
579
|
+
chat_steering_messages_send: {
|
|
580
|
+
method: "POST",
|
|
581
|
+
path: "/chat/chat/conversations/{conversationId}/steering-messages"
|
|
582
|
+
},
|
|
583
|
+
chat_tools_list: {
|
|
584
|
+
method: "GET",
|
|
585
|
+
path: "/chat/tools"
|
|
586
|
+
},
|
|
587
|
+
chat_turns_cancel: {
|
|
588
|
+
method: "POST",
|
|
589
|
+
path: "/chat/chat/turns/{invocationId}/cancel"
|
|
590
|
+
},
|
|
591
|
+
chat_turns_stream: {
|
|
592
|
+
method: "POST",
|
|
593
|
+
parse: "event_frames",
|
|
594
|
+
path: "/chat/chat/stream"
|
|
595
|
+
},
|
|
596
|
+
chat_turns_submit: {
|
|
597
|
+
method: "POST",
|
|
598
|
+
path: "/chat/chat/turns"
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
const isChatOperationId = (operationId) => Object.hasOwn(chatRoutes, operationId);
|
|
602
|
+
const chatQuery = (query) => {
|
|
603
|
+
if (!isRecord$1(query)) return;
|
|
604
|
+
const entries = Object.entries(query).flatMap(([name, value]) => {
|
|
605
|
+
if (typeof value === "string") return [[name, value]];
|
|
606
|
+
return Array.isArray(value) ? [[name, value.filter((item) => typeof item === "string")]] : [];
|
|
607
|
+
});
|
|
608
|
+
return entries.length === 0 ? void 0 : Object.fromEntries(entries);
|
|
609
|
+
};
|
|
610
|
+
/**
|
|
611
|
+
* The form of a multipart body: each field once, a list field once per item.
|
|
612
|
+
* CI reads the type of a file from the extension of its name, so a file
|
|
613
|
+
* without a name (a plain `Blob`) is bad input and throws `TypeError`.
|
|
614
|
+
*/
|
|
615
|
+
const chatForm = (operationId, body) => {
|
|
616
|
+
const form = new FormData();
|
|
617
|
+
if (!isRecord$1(body)) return form;
|
|
618
|
+
for (const [name, value] of Object.entries(body)) for (const item of Array.isArray(value) ? value : [value]) {
|
|
619
|
+
if (item instanceof Blob && (!(item instanceof File) || item.name === "")) throw new TypeError(`${operationId} needs a named File in body.${name}`);
|
|
620
|
+
if (item instanceof Blob || typeof item === "string") form.append(name, item);
|
|
621
|
+
}
|
|
622
|
+
return form;
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* Maps a chat operation onto its External App chat route. The input is the
|
|
626
|
+
* `path`, `query` and `body` of the generated operation: `path` fills the
|
|
627
|
+
* route, `query` and `body` go as they are. A missing path value is bad
|
|
628
|
+
* input and throws `TypeError`.
|
|
629
|
+
*/
|
|
630
|
+
const chatCall = (operationId, input) => {
|
|
631
|
+
const route = chatRoutes[operationId];
|
|
632
|
+
const record = isRecord$1(input) ? input : {};
|
|
633
|
+
const values = isRecord$1(record.path) ? record.path : {};
|
|
634
|
+
const pathname = route.path.replaceAll(/\{(?<name>\w+)\}/gu, (_match, name) => {
|
|
635
|
+
const value = textField(values, name);
|
|
636
|
+
if (value === void 0) throw new TypeError(`${operationId} needs path.${name}`);
|
|
637
|
+
return encodeURIComponent(value);
|
|
638
|
+
});
|
|
639
|
+
const call = {
|
|
640
|
+
method: route.method,
|
|
641
|
+
parse: route.parse ?? "body",
|
|
642
|
+
pathname
|
|
643
|
+
};
|
|
644
|
+
const query = chatQuery(record.query);
|
|
645
|
+
if (query !== void 0) call.query = query;
|
|
646
|
+
if (route.form === true) call.form = chatForm(operationId, record.body);
|
|
647
|
+
else if (record.body !== void 0) call.body = record.body;
|
|
648
|
+
return call;
|
|
649
|
+
};
|
|
650
|
+
/** The value of a chat answer: its JSON body, and none for `204 No Content`. */
|
|
651
|
+
const chatResult = (status, body) => status === 204 ? void 0 : body;
|
|
280
652
|
const removedEntityOperation = /* @__PURE__ */ new Set([
|
|
281
653
|
"knowledge_create_entity",
|
|
282
654
|
"knowledge_delete_entity",
|
|
@@ -287,6 +659,7 @@ const removedEntityOperation = /* @__PURE__ */ new Set([
|
|
|
287
659
|
]);
|
|
288
660
|
/** Maps a client operation onto T1 dedicated Application HTTP. */
|
|
289
661
|
const dedicatedHttpCall = (operationId, input) => {
|
|
662
|
+
if (isChatOperationId(operationId)) return chatCall(operationId, input);
|
|
290
663
|
if (removedEntityOperation.has(operationId)) return null;
|
|
291
664
|
const record = isRecord$1(input) ? input : {};
|
|
292
665
|
switch (operationId) {
|
|
@@ -348,10 +721,56 @@ const dedicatedResult = (value) => {
|
|
|
348
721
|
if (Array.isArray(value.items)) return { items: value.items };
|
|
349
722
|
return value;
|
|
350
723
|
};
|
|
724
|
+
/** The search string of a call's query; a name with a list of values repeats. */
|
|
725
|
+
const searchOf = (query) => {
|
|
726
|
+
const search = new URLSearchParams();
|
|
727
|
+
for (const [name, value] of Object.entries(query ?? {})) for (const item of typeof value === "string" ? [value] : value) search.append(name, item);
|
|
728
|
+
return search.toString();
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* The frames of one live event stream, as the server sends them; comments
|
|
732
|
+
* such as `: ping` are not frames. The iteration ends when the server closes
|
|
733
|
+
* the stream. A cut connection throws `CiTransportError`, and an abort of
|
|
734
|
+
* `signal` throws its reason. A consumer that stops early closes the stream.
|
|
735
|
+
*
|
|
736
|
+
* @yields {EventFrame} Each frame, in the order that the server sent it.
|
|
737
|
+
*/
|
|
738
|
+
const eventFrames = async function* eventFrames(body, signal) {
|
|
739
|
+
if (body === null) return;
|
|
740
|
+
const frames = [];
|
|
741
|
+
const parser = createEventStreamParser({
|
|
742
|
+
onEvent: ({ data, id, type }) => {
|
|
743
|
+
frames.push(id === void 0 ? {
|
|
744
|
+
data,
|
|
745
|
+
event: type
|
|
746
|
+
} : {
|
|
747
|
+
data,
|
|
748
|
+
event: type,
|
|
749
|
+
id
|
|
750
|
+
});
|
|
751
|
+
},
|
|
752
|
+
onPing: () => null
|
|
753
|
+
});
|
|
754
|
+
const reader = body.getReader();
|
|
755
|
+
const decoder = new TextDecoder();
|
|
756
|
+
try {
|
|
757
|
+
for (;;) {
|
|
758
|
+
const chunk = await reader.read().catch((error) => {
|
|
759
|
+
throw signal?.aborted === true ? signal.reason : new CiTransportError({ cause: error });
|
|
760
|
+
});
|
|
761
|
+
if (chunk.done) return;
|
|
762
|
+
parser.push(decoder.decode(chunk.value, { stream: true }));
|
|
763
|
+
yield* frames.splice(0);
|
|
764
|
+
}
|
|
765
|
+
} finally {
|
|
766
|
+
await reader.cancel().catch(() => null);
|
|
767
|
+
}
|
|
768
|
+
};
|
|
351
769
|
const isRecord = (value) => value !== null && Object(value) === value && !Array.isArray(value);
|
|
352
770
|
const isString = (value) => typeof value === "string";
|
|
353
771
|
const isBoolean = (value) => typeof value === "boolean";
|
|
354
|
-
|
|
772
|
+
const isCiErrorCode = (value) => ciErrorCodes.some((code) => code === value);
|
|
773
|
+
/** The `CiErrorCode` of a backend error code; a `CiErrorCode`, as the chat answers, stays. */
|
|
355
774
|
const backendErrorCode = (value) => {
|
|
356
775
|
switch (value) {
|
|
357
776
|
case "authentication_required": return "unauthenticated";
|
|
@@ -362,20 +781,23 @@ const backendErrorCode = (value) => {
|
|
|
362
781
|
case "not_found": return "not_found";
|
|
363
782
|
case "operation_not_allowed": return "not_found";
|
|
364
783
|
case "temporarily_unavailable": return "unavailable";
|
|
365
|
-
default: return "internal";
|
|
784
|
+
default: return isCiErrorCode(value) ? value : "internal";
|
|
366
785
|
}
|
|
367
786
|
};
|
|
368
787
|
const transportFailure = (response, value) => {
|
|
369
788
|
if (isRecord(value) && isRecord(value.error)) {
|
|
370
|
-
const rawCode = value.error
|
|
371
|
-
const
|
|
789
|
+
const { code: rawCode, details } = value.error;
|
|
790
|
+
const fields = {
|
|
791
|
+
code: isString(rawCode) ? backendErrorCode(rawCode) : "internal",
|
|
792
|
+
message: isString(value.error.message) ? value.error.message : "The CI operation failed",
|
|
793
|
+
retryable: isBoolean(value.error.retryable) ? value.error.retryable : response.status >= 500
|
|
794
|
+
};
|
|
372
795
|
return {
|
|
373
796
|
correlationId: isString(value.correlationId) ? value.correlationId : response.headers.get("x-correlation-id") ?? "unavailable",
|
|
374
|
-
error: new CiError({
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}),
|
|
797
|
+
error: details !== void 0 && isRecord(details) ? new CiError({
|
|
798
|
+
...fields,
|
|
799
|
+
details
|
|
800
|
+
}) : new CiError(fields),
|
|
379
801
|
ok: false
|
|
380
802
|
};
|
|
381
803
|
}
|
|
@@ -434,14 +856,15 @@ const makeHttpExecute = ({ authorization, basePath, credentials = "omit", fetch,
|
|
|
434
856
|
if (authorized.token !== void 0) headers.set("authorization", `Bearer ${authorized.token}`);
|
|
435
857
|
if (call.idempotencyKey !== void 0) headers.set("idempotency-key", call.idempotencyKey);
|
|
436
858
|
if (call.lastEventId !== void 0) headers.set("last-event-id", call.lastEventId);
|
|
437
|
-
const search =
|
|
859
|
+
const search = searchOf(call.query);
|
|
438
860
|
const endpoint = new URL(`${basePath}${call.pathname}${search === "" ? "" : `?${search}`}`, origin);
|
|
439
861
|
const requestInit = {
|
|
440
862
|
credentials,
|
|
441
863
|
headers,
|
|
442
864
|
method: call.method
|
|
443
865
|
};
|
|
444
|
-
if (call.
|
|
866
|
+
if (call.form !== void 0) requestInit.body = call.form;
|
|
867
|
+
else if (call.body !== void 0) requestInit.body = JSON.stringify(call.body);
|
|
445
868
|
const response = yield* Effect.tryPromise({
|
|
446
869
|
catch: transportError$1,
|
|
447
870
|
try: (signal) => fetch(endpoint, {
|
|
@@ -450,6 +873,14 @@ const makeHttpExecute = ({ authorization, basePath, credentials = "omit", fetch,
|
|
|
450
873
|
})
|
|
451
874
|
});
|
|
452
875
|
const headerCorrelation = response.headers.get("x-correlation-id") ?? "unavailable";
|
|
876
|
+
if (call.parse === "event_frames") {
|
|
877
|
+
if (!response.ok) return transportFailure(response, yield* responseJson(response));
|
|
878
|
+
return {
|
|
879
|
+
correlationId: headerCorrelation,
|
|
880
|
+
ok: true,
|
|
881
|
+
value: eventFrames(response.body, options.signal)
|
|
882
|
+
};
|
|
883
|
+
}
|
|
453
884
|
if (call.parse === "event_stream") {
|
|
454
885
|
if (!response.ok) return transportFailure(response, yield* responseJson(response));
|
|
455
886
|
const text = yield* Effect.tryPromise({
|
|
@@ -467,7 +898,7 @@ const makeHttpExecute = ({ authorization, basePath, credentials = "omit", fetch,
|
|
|
467
898
|
return {
|
|
468
899
|
correlationId: isRecord(value) && isString(value.correlationId) ? value.correlationId : headerCorrelation,
|
|
469
900
|
ok: true,
|
|
470
|
-
value: dedicatedResult(value)
|
|
901
|
+
value: call.parse === "body" ? chatResult(response.status, value) : dedicatedResult(value)
|
|
471
902
|
};
|
|
472
903
|
});
|
|
473
904
|
const parseOriginUrl = (value, field) => {
|
|
@@ -8831,4 +9262,4 @@ const makeLegacy = (options) => LegacyResources.of({ bind: (definition) => {
|
|
|
8831
9262
|
const layerLegacy = (options) => Layer.succeed(LegacyResources, makeLegacy(options));
|
|
8832
9263
|
/** `layerLegacy` with options that Effect `Config` reads. */
|
|
8833
9264
|
const layerLegacyConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layerLegacy));
|
|
8834
|
-
export {
|
|
9265
|
+
export { isClientOperationId as C, retryAfterMilliseconds as E, fromCiResult as S, createFetchEventSourceFactory as T, backendErrorCode as _, layerConfig as a, proxyHttpOptions as b, layerLegacyConfig as c, createEntityHttpTransport as d, makeEntityHttpExecute as f, isEntityReadLimitError as g, isEntityBatchRefusedError as h, layer as i, makeEntityCore as l, createEntityProtocol as m, Resources as n, layerFromEntityTransport as o, runEntityRequest as p, fromEntityTransport as r, layerLegacy as s, LegacyResources as t, makeLegacyResourceCore as u, directHttpOptions as v, toCiResult as w, clientOperationIds as x, makeHttpExecute as y };
|