@effect/chat-teams 0.0.0-stage → 4.1.5
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 +434 -0
- package/CLAUDE.md +434 -0
- package/LICENSE +21 -0
- package/README.md +115 -2
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +7 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +163 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/40_sql/10_basics.ts +175 -0
- package/ai-docs/src/40_sql/index.md +6 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +118 -0
- package/ai-docs/src/51_http-server/20_testing.ts +100 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/52_graphql/10_basics.ts +117 -0
- package/ai-docs/src/52_graphql/20_testing.ts +45 -0
- package/ai-docs/src/52_graphql/30_batching.ts +118 -0
- package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
- package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
- package/ai-docs/src/52_graphql/index.md +6 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +162 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +28 -0
- package/dist/TeamsChat.d.ts +318 -0
- package/dist/TeamsChat.d.ts.map +1 -0
- package/dist/TeamsChat.js +316 -0
- package/dist/TeamsChat.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/adapter.d.ts +2 -0
- package/dist/internal/adapter.d.ts.map +1 -0
- package/dist/internal/adapter.js +300 -0
- package/dist/internal/adapter.js.map +1 -0
- package/dist/internal/address.d.ts +2 -0
- package/dist/internal/address.d.ts.map +1 -0
- package/dist/internal/address.js +52 -0
- package/dist/internal/address.js.map +1 -0
- package/dist/internal/auth.d.ts +2 -0
- package/dist/internal/auth.d.ts.map +1 -0
- package/dist/internal/auth.js +142 -0
- package/dist/internal/auth.js.map +1 -0
- package/dist/internal/connector.d.ts +2 -0
- package/dist/internal/connector.d.ts.map +1 -0
- package/dist/internal/connector.js +173 -0
- package/dist/internal/connector.js.map +1 -0
- package/dist/internal/download.d.ts +5 -0
- package/dist/internal/download.d.ts.map +1 -0
- package/dist/internal/download.js +183 -0
- package/dist/internal/download.js.map +1 -0
- package/dist/internal/envelope.d.ts +2 -0
- package/dist/internal/envelope.d.ts.map +1 -0
- package/dist/internal/envelope.js +337 -0
- package/dist/internal/envelope.js.map +1 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +113 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/interactions.d.ts +2 -0
- package/dist/internal/interactions.d.ts.map +1 -0
- package/dist/internal/interactions.js +288 -0
- package/dist/internal/interactions.js.map +1 -0
- package/dist/internal/length.d.ts +2 -0
- package/dist/internal/length.d.ts.map +1 -0
- package/dist/internal/length.js +147 -0
- package/dist/internal/length.js.map +1 -0
- package/dist/internal/normalize.d.ts +2 -0
- package/dist/internal/normalize.d.ts.map +1 -0
- package/dist/internal/normalize.js +224 -0
- package/dist/internal/normalize.js.map +1 -0
- package/dist/internal/parse.d.ts +2 -0
- package/dist/internal/parse.d.ts.map +1 -0
- package/dist/internal/parse.js +33 -0
- package/dist/internal/parse.js.map +1 -0
- package/dist/internal/render.d.ts +2 -0
- package/dist/internal/render.d.ts.map +1 -0
- package/dist/internal/render.js +316 -0
- package/dist/internal/render.js.map +1 -0
- package/dist/internal/webhook.d.ts +2 -0
- package/dist/internal/webhook.d.ts.map +1 -0
- package/dist/internal/webhook.js +88 -0
- package/dist/internal/webhook.js.map +1 -0
- package/package.json +58 -3
- package/src/TeamsChat.ts +470 -0
- package/src/index.ts +12 -0
- package/src/internal/adapter.ts +351 -0
- package/src/internal/address.ts +67 -0
- package/src/internal/auth.ts +192 -0
- package/src/internal/connector.ts +253 -0
- package/src/internal/download.ts +277 -0
- package/src/internal/envelope.ts +427 -0
- package/src/internal/errors.ts +94 -0
- package/src/internal/interactions.ts +294 -0
- package/src/internal/length.ts +170 -0
- package/src/internal/normalize.ts +232 -0
- package/src/internal/parse.ts +41 -0
- package/src/internal/render.ts +318 -0
- package/src/internal/webhook.ts +117 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import * as ChatInteraction from "effect/chat/ChatInteraction";
|
|
2
|
+
import * as Duration from "effect/Duration";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Str from "effect/String";
|
|
6
|
+
import { modalFields, modalMetadataLength } from "./adapter.js";
|
|
7
|
+
import * as Envelope from "./envelope.js";
|
|
8
|
+
import * as Errors from "./errors.js";
|
|
9
|
+
import { locate, threadOf, userId } from "./normalize.js";
|
|
10
|
+
import { isObject, object, string } from "./parse.js";
|
|
11
|
+
import * as Render from "./render.js";
|
|
12
|
+
/** The default share of Teams' invoke timeout the handler gets. @internal */
|
|
13
|
+
export const defaultDeadline = /*#__PURE__*/Duration.seconds(4);
|
|
14
|
+
const ok = {
|
|
15
|
+
status: 200
|
|
16
|
+
};
|
|
17
|
+
/** What an invoke that fails a check gets. It names no reason. */
|
|
18
|
+
const safeFailure = name => name === "adaptiveCard/action" ? {
|
|
19
|
+
status: 200,
|
|
20
|
+
body: {
|
|
21
|
+
statusCode: 400,
|
|
22
|
+
type: "application/vnd.microsoft.error",
|
|
23
|
+
value: {
|
|
24
|
+
code: "BadRequest",
|
|
25
|
+
message: "This action could not be completed."
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} : {
|
|
29
|
+
status: 200,
|
|
30
|
+
body: {
|
|
31
|
+
task: {
|
|
32
|
+
type: "message",
|
|
33
|
+
value: "This action could not be completed."
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const executeAck = {
|
|
38
|
+
status: 200,
|
|
39
|
+
body: {
|
|
40
|
+
statusCode: 200,
|
|
41
|
+
type: "application/vnd.microsoft.activity.message",
|
|
42
|
+
value: ""
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const refused = (event, error) => Effect.flatMap(ChatInteraction.Handler, handler => handler.refused(event, error));
|
|
46
|
+
/** The adaptive card of a dialog, built only from the signed definition. */
|
|
47
|
+
const dialogCard = (modal, token, submitted) => {
|
|
48
|
+
// A dialog sent again with errors keeps what the user entered, not the
|
|
49
|
+
// definition's `initial`. Lookups are own properties only, so a field id
|
|
50
|
+
// such as `constructor` reads nothing inherited.
|
|
51
|
+
const own = (record, key) => Object.hasOwn(record, key) && typeof record[key] === "string" ? record[key] : undefined;
|
|
52
|
+
const valueOf = element => submitted === undefined ? element.initial : own(submitted.values, element.id);
|
|
53
|
+
const body = [];
|
|
54
|
+
for (const element of modal.elements) {
|
|
55
|
+
if (element._tag === "Text") {
|
|
56
|
+
body.push(Render.textBlock(Render.escapeText(Str.toWellFormed(element.text))));
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (element._tag === "TextInput") {
|
|
60
|
+
body.push({
|
|
61
|
+
type: "Input.Text",
|
|
62
|
+
id: element.id,
|
|
63
|
+
label: element.label,
|
|
64
|
+
isMultiline: element.multiline === true,
|
|
65
|
+
isRequired: element.optional !== true,
|
|
66
|
+
maxLength: element.maxLength ?? Envelope.defaultMaxLength,
|
|
67
|
+
...(element.placeholder === undefined ? {} : {
|
|
68
|
+
placeholder: element.placeholder
|
|
69
|
+
}),
|
|
70
|
+
...(valueOf(element) === undefined ? {} : {
|
|
71
|
+
value: valueOf(element)
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
body.push({
|
|
76
|
+
type: "Input.ChoiceSet",
|
|
77
|
+
id: element.id,
|
|
78
|
+
label: element.label,
|
|
79
|
+
style: "compact",
|
|
80
|
+
isRequired: element.optional !== true,
|
|
81
|
+
choices: element.options.map(option => ({
|
|
82
|
+
title: option.label,
|
|
83
|
+
value: option.value
|
|
84
|
+
})),
|
|
85
|
+
...(element.placeholder === undefined ? {} : {
|
|
86
|
+
placeholder: element.placeholder
|
|
87
|
+
}),
|
|
88
|
+
...(valueOf(element) === undefined ? {} : {
|
|
89
|
+
value: valueOf(element)
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const error = submitted === undefined ? undefined : own(submitted.errors, element.id);
|
|
94
|
+
if (error !== undefined) {
|
|
95
|
+
body.push({
|
|
96
|
+
...Render.textBlock(Render.escapeText(Str.toWellFormed(error))),
|
|
97
|
+
color: "attention"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
task: {
|
|
103
|
+
type: "continue",
|
|
104
|
+
value: {
|
|
105
|
+
title: modal.title,
|
|
106
|
+
card: {
|
|
107
|
+
contentType: Render.cardContentType,
|
|
108
|
+
content: {
|
|
109
|
+
...Render.card(body),
|
|
110
|
+
actions: [{
|
|
111
|
+
type: "Action.Submit",
|
|
112
|
+
title: modal.submitLabel ?? "Submit",
|
|
113
|
+
data: {
|
|
114
|
+
[Envelope.reservedKey]: token
|
|
115
|
+
}
|
|
116
|
+
}]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const modalRefusal = modal => modal.elements.length > modalFields ? Errors.tooLarge(undefined, "too_many_modal_fields") : Envelope.checkModal(modal);
|
|
124
|
+
/**
|
|
125
|
+
* One verified invoke, or a card's `Action.Submit` fallback, which comes as
|
|
126
|
+
* a `message` with a `value`.
|
|
127
|
+
*
|
|
128
|
+
* - `adaptiveCard/action` and the fallback are clicks. A click can't open
|
|
129
|
+
* a dialog there: an `OpenModal` goes to `Handler.refused` as
|
|
130
|
+
* `Unsupported`.
|
|
131
|
+
* - `task/fetch` is a click on a button named in `modalButtons`, whose
|
|
132
|
+
* `OpenModal` opens the dialog, signed for the clicking user.
|
|
133
|
+
* - `task/submit` is a dialog submit, checked against its signed
|
|
134
|
+
* definition.
|
|
135
|
+
* - A token that does not verify, or values that do not match the
|
|
136
|
+
* definition, get the safe failure and dispatch nothing.
|
|
137
|
+
*
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
export const invoke = (activity, options) => Effect.gen(function* () {
|
|
141
|
+
const name = activity.type === "message" ? "message" : string(activity, "name") ?? "";
|
|
142
|
+
const failure = safeFailure(name);
|
|
143
|
+
const envelope = options.envelope;
|
|
144
|
+
if (envelope === undefined || !options.capabilities.has("buttons")) return failure;
|
|
145
|
+
const conversationId = string(object(activity, "conversation"), "id");
|
|
146
|
+
const user = userId(object(activity, "from"));
|
|
147
|
+
if (conversationId === undefined || user === undefined) return failure;
|
|
148
|
+
const value = object(activity, "value");
|
|
149
|
+
const data = name === "adaptiveCard/action" ? object(object(value, "action"), "data") : name === "message" ? value : object(value, "data");
|
|
150
|
+
const token = data?.[Envelope.reservedKey];
|
|
151
|
+
if (name === "task/submit") {
|
|
152
|
+
if (!options.capabilities.has("modals")) return failure;
|
|
153
|
+
const dialog = yield* envelope.verifyDialog(token, {
|
|
154
|
+
conversationId,
|
|
155
|
+
userId: user
|
|
156
|
+
});
|
|
157
|
+
if (Option.isNone(dialog)) return failure;
|
|
158
|
+
const values = Envelope.validateSubmission(dialog.value.modal, data);
|
|
159
|
+
// The thread of the click that opened it, from the signed conversation
|
|
160
|
+
// id and message, never from the submit.
|
|
161
|
+
const origin = locate(dialog.value.conversationId, dialog.value.messageId)?.thread;
|
|
162
|
+
if (Option.isNone(values) || origin === undefined) return failure;
|
|
163
|
+
const modal = dialog.value.modal;
|
|
164
|
+
const event = ChatInteraction.ModalSubmitted.make({
|
|
165
|
+
id: modal.id,
|
|
166
|
+
...(modal.metadata === undefined ? {} : {
|
|
167
|
+
metadata: modal.metadata
|
|
168
|
+
}),
|
|
169
|
+
values: values.value,
|
|
170
|
+
thread: origin,
|
|
171
|
+
...(dialog.value.messageId === undefined ? {} : {
|
|
172
|
+
messageId: dialog.value.messageId
|
|
173
|
+
}),
|
|
174
|
+
userId: user,
|
|
175
|
+
raw: activity
|
|
176
|
+
});
|
|
177
|
+
const reply = yield* ChatInteraction.handle(event, options.deadline);
|
|
178
|
+
if (reply._tag === "Late") return failure;
|
|
179
|
+
if (reply._tag === "Errors") {
|
|
180
|
+
return {
|
|
181
|
+
status: 200,
|
|
182
|
+
body: dialogCard(modal, token, {
|
|
183
|
+
values: values.value,
|
|
184
|
+
errors: reply.errors
|
|
185
|
+
})
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return ok;
|
|
189
|
+
}
|
|
190
|
+
if (name !== "adaptiveCard/action" && name !== "message" && name !== "task/fetch") return failure;
|
|
191
|
+
const button = yield* envelope.verifyButton(token, {
|
|
192
|
+
conversationId
|
|
193
|
+
});
|
|
194
|
+
const messageId = string(activity, "replyToId");
|
|
195
|
+
// A card posted as a channel post has the channel as its address, as `normalize` gives it.
|
|
196
|
+
const thread = locate(conversationId, messageId)?.thread;
|
|
197
|
+
if (Option.isNone(button) || thread === undefined || messageId === undefined) return failure;
|
|
198
|
+
const opensDialog = name === "task/fetch";
|
|
199
|
+
if (opensDialog !== options.modalButtons.has(button.value.id)) return failure;
|
|
200
|
+
const event = ChatInteraction.ButtonClicked.make({
|
|
201
|
+
id: button.value.id,
|
|
202
|
+
...(button.value.value === undefined ? {} : {
|
|
203
|
+
value: button.value.value
|
|
204
|
+
}),
|
|
205
|
+
thread,
|
|
206
|
+
messageId,
|
|
207
|
+
userId: user,
|
|
208
|
+
raw: activity
|
|
209
|
+
});
|
|
210
|
+
const reply = yield* ChatInteraction.handle(event, options.deadline);
|
|
211
|
+
const acked = name === "adaptiveCard/action" ? executeAck : name === "message" ? ok : failure;
|
|
212
|
+
if (reply._tag === "Late" || reply._tag === "Ack") return acked;
|
|
213
|
+
if (!opensDialog || !options.capabilities.has("modals")) {
|
|
214
|
+
yield* refused(event, Errors.chatError("openModal", Errors.unsupported("modals")));
|
|
215
|
+
return acked;
|
|
216
|
+
}
|
|
217
|
+
const refusal = modalRefusal(reply.modal);
|
|
218
|
+
if (refusal !== undefined) {
|
|
219
|
+
yield* refused(event, Errors.chatError("openModal", refusal));
|
|
220
|
+
return failure;
|
|
221
|
+
}
|
|
222
|
+
const signed = yield* Effect.result(envelope.signDialog({
|
|
223
|
+
conversationId,
|
|
224
|
+
userId: user,
|
|
225
|
+
messageId,
|
|
226
|
+
modal: reply.modal
|
|
227
|
+
}));
|
|
228
|
+
// `modalMetadataLength` holds the whole signed token: the definition,
|
|
229
|
+
// the metadata and every claim. Signing is local, so the check is exact
|
|
230
|
+
// and nothing has opened yet.
|
|
231
|
+
const tooLong = signed._tag === "Success" && signed.success.length > modalMetadataLength;
|
|
232
|
+
if (signed._tag === "Failure" || tooLong) {
|
|
233
|
+
const reason = signed._tag === "Failure" ? signed.failure : Errors.tooLarge(undefined, "modal_too_large");
|
|
234
|
+
yield* refused(event, Errors.chatError("openModal", reason));
|
|
235
|
+
return failure;
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
status: 200,
|
|
239
|
+
body: dialogCard(reply.modal, signed.success)
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
/** Leading `<at>…</at>` tokens, spaces and one slash, before a command's name. */
|
|
243
|
+
const commandPrefix = /^(?:\s|<at>[^<]*<\/at>)*\/?/;
|
|
244
|
+
/**
|
|
245
|
+
* A verified targeted message. Its first word names the command, and the
|
|
246
|
+
* rest is the command's `text`. A message whose first word names no
|
|
247
|
+
* registered command is acked and nothing is sent. Nothing here ever
|
|
248
|
+
* reaches `ChatHandler` or posts in public unless the handler asks.
|
|
249
|
+
*
|
|
250
|
+
* @internal
|
|
251
|
+
*/
|
|
252
|
+
export const command = (activity, options) => Effect.gen(function* () {
|
|
253
|
+
if (!options.capabilities.has("commands")) return;
|
|
254
|
+
const text = typeof activity.text === "string" ? activity.text : "";
|
|
255
|
+
const rest = text.replace(commandPrefix, "");
|
|
256
|
+
const match = /^(\S+)\s*([\s\S]*)$/.exec(rest);
|
|
257
|
+
const user = userId(object(activity, "from"));
|
|
258
|
+
const at = threadOf(activity);
|
|
259
|
+
if (match === null || user === undefined || at === undefined) return;
|
|
260
|
+
const id = match[1];
|
|
261
|
+
if (!(yield* options.isRegistered(id))) return;
|
|
262
|
+
const event = ChatInteraction.CommandInvoked.make({
|
|
263
|
+
id,
|
|
264
|
+
text: match[2],
|
|
265
|
+
thread: at.thread,
|
|
266
|
+
userId: user,
|
|
267
|
+
raw: activity
|
|
268
|
+
});
|
|
269
|
+
const reply = yield* ChatInteraction.handle(event, options.deadline);
|
|
270
|
+
switch (reply._tag) {
|
|
271
|
+
case "Late":
|
|
272
|
+
case "Ack":
|
|
273
|
+
case "Defer":
|
|
274
|
+
return;
|
|
275
|
+
case "OpenModal":
|
|
276
|
+
return yield* refused(event, Errors.chatError("openModal", Errors.unsupported("modals")));
|
|
277
|
+
case "Respond":
|
|
278
|
+
return yield* options.answer("respond", activity, {
|
|
279
|
+
markdown: reply.markdown,
|
|
280
|
+
...(reply.actions === undefined ? {} : {
|
|
281
|
+
actions: reply.actions
|
|
282
|
+
})
|
|
283
|
+
}, reply.visibility).pipe(Effect.catch(error => refused(event, error)));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
/** Whether a `message` is a card's `Action.Submit` fallback. @internal */
|
|
287
|
+
export const isSubmitFallback = activity => activity.type === "message" && isObject(activity.value) && Envelope.reservedKey in activity.value;
|
|
288
|
+
//# sourceMappingURL=interactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions.js","names":[],"sources":["../../src/internal/interactions.ts"],"sourcesContent":[null],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,6BAA6B;AAE9D,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,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,EAAE,CAAC,MAAM;IACjB,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE;GACN,CAAC;EACF,MAAM,KAAK,GAAG,OAAO,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC;EACpE,QAAQ,KAAK,CAAC,IAAI;IAChB,KAAK,MAAM;IACX,KAAK,KAAK;IACV,KAAK,OAAO;MACV;IACF,KAAK,WAAW;MACd,OAAO,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3F,KAAK,SAAS;MACZ,OAAO,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE;QAChD,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,GAAG,EAAE,GAAG;UAAE,OAAO,EAAE,KAAK,CAAC;QAAO,CAAE;OAClE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAE,KAAK,IAAK,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;EAC7E;AACF,CAAC,CAAC;AAEJ;AACA,OAAO,MAAM,gBAAgB,GAAI,QAAoB,IACnD,QAAQ,CAAC,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,KAAK","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"length.d.ts","sourceRoot":"","sources":["../../src/internal/length.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { maxIdLength } from "./address.js";
|
|
2
|
+
import * as Render from "./render.js";
|
|
3
|
+
const size = value => JSON.stringify(value).length;
|
|
4
|
+
/** An element in an array, with the comma before or after it. */
|
|
5
|
+
const element = value => size(value) + 1;
|
|
6
|
+
/**
|
|
7
|
+
* The size of a serialised activity body the Connector takes, in UTF-16
|
|
8
|
+
* units.
|
|
9
|
+
*
|
|
10
|
+
* Provisional: Microsoft documents no exact number, and this is not verified
|
|
11
|
+
* against the Connector yet.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export const Edge = 50_000;
|
|
16
|
+
/** The text form with empty `text`. @internal */
|
|
17
|
+
export const S = /*#__PURE__*/size(/*#__PURE__*/Render.textActivity(""));
|
|
18
|
+
/** The card form with an empty card body. @internal */
|
|
19
|
+
export const T = /*#__PURE__*/size(/*#__PURE__*/Render.cardActivityOf([]));
|
|
20
|
+
/** One table cell and its column definition. @internal */
|
|
21
|
+
export const K = /*#__PURE__*/element(/*#__PURE__*/Render.tableCell("")) + /*#__PURE__*/element(Render.column);
|
|
22
|
+
/**
|
|
23
|
+
* The largest element group a source line can add: a `TextBlock`, a
|
|
24
|
+
* `CodeBlock` (with `PlainText` as its language), or a `Table` with one
|
|
25
|
+
* row of one cell, which is also more than a new row of one cell.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export const E = /*#__PURE__*/Math.max(/*#__PURE__*/element(/*#__PURE__*/Render.textBlock("")), /*#__PURE__*/element(/*#__PURE__*/Render.codeBlock("", "PlainText")), /*#__PURE__*/element(/*#__PURE__*/Render.table([[""]])));
|
|
30
|
+
const id = /*#__PURE__*/"x".repeat(maxIdLength);
|
|
31
|
+
/**
|
|
32
|
+
* The members the adapter may add to an activity besides what the renderer
|
|
33
|
+
* gives, each id at `maxIdLength`: `replyToId`, `recipient`, and
|
|
34
|
+
* `entities` holding a `streaminfo` entity, the AI-generated label and a
|
|
35
|
+
* `targetedMessageInfo` entity. Ids are sent without JSON escapes.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export const A = /*#__PURE__*/size({
|
|
40
|
+
replyToId: id,
|
|
41
|
+
recipient: {
|
|
42
|
+
id
|
|
43
|
+
},
|
|
44
|
+
entities: [{
|
|
45
|
+
type: "streaminfo",
|
|
46
|
+
streamId: id,
|
|
47
|
+
streamType: "informative",
|
|
48
|
+
streamSequence: Number.MAX_SAFE_INTEGER
|
|
49
|
+
}, {
|
|
50
|
+
type: "https://schema.org/Message",
|
|
51
|
+
"@type": "Message",
|
|
52
|
+
"@context": "https://schema.org",
|
|
53
|
+
"@id": "",
|
|
54
|
+
additionalType: ["AIGeneratedContent"]
|
|
55
|
+
}, {
|
|
56
|
+
type: "targetedMessageInfo",
|
|
57
|
+
messageId: id
|
|
58
|
+
}]
|
|
59
|
+
}) - 1;
|
|
60
|
+
/**
|
|
61
|
+
* Units set aside for mention entities.
|
|
62
|
+
*
|
|
63
|
+
* Provisional: the adapter does not send mentions in v1.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export const M_units = 4_000;
|
|
68
|
+
/** Units set aside for file attachments: none, files are not sent in v1. @internal */
|
|
69
|
+
export const F_units = 0;
|
|
70
|
+
/**
|
|
71
|
+
* The fixed part of a message: the larger of the two forms with the first
|
|
72
|
+
* element of the card. The first source line has no line break before it to
|
|
73
|
+
* pay for its element, so `E` is reserved once for it.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export const skeleton = /*#__PURE__*/Math.max(S, T + E);
|
|
78
|
+
/** @internal */
|
|
79
|
+
export const R = skeleton + A + M_units + F_units;
|
|
80
|
+
/** @internal */
|
|
81
|
+
export const messageLength = Edge - R;
|
|
82
|
+
/**
|
|
83
|
+
* What one UTF-16 unit of the source can cost once rendered and serialised.
|
|
84
|
+
* A line break pays for the element its line may start, and a pipe for the
|
|
85
|
+
* table cell and column it may add.
|
|
86
|
+
*/
|
|
87
|
+
const unit = code => {
|
|
88
|
+
switch (code) {
|
|
89
|
+
case 0x0a:
|
|
90
|
+
case 0x0d:
|
|
91
|
+
return 2 + E;
|
|
92
|
+
case 0x7c:
|
|
93
|
+
return 1 + K;
|
|
94
|
+
case 0x22:
|
|
95
|
+
case 0x5c:
|
|
96
|
+
return 2;
|
|
97
|
+
case 0x09: // A partially stripped tab in fenced code can leave three spaces.
|
|
98
|
+
case 0x24:
|
|
99
|
+
return 3;
|
|
100
|
+
case 0x3c:
|
|
101
|
+
return 4;
|
|
102
|
+
case 0x26:
|
|
103
|
+
return 5;
|
|
104
|
+
default:
|
|
105
|
+
return code < 0x20 ? 6 : 1;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/** @internal */
|
|
109
|
+
export const weight = text => {
|
|
110
|
+
let total = 0;
|
|
111
|
+
for (let i = 0; i < text.length; i++) total += unit(text.charCodeAt(i));
|
|
112
|
+
return total;
|
|
113
|
+
};
|
|
114
|
+
const row = /*#__PURE__*/element(/*#__PURE__*/Render.actionSet([]));
|
|
115
|
+
const actionCost = (action, tokenLength) => {
|
|
116
|
+
switch (action._tag) {
|
|
117
|
+
case "Button":
|
|
118
|
+
return element(Render.buttonAction({
|
|
119
|
+
...action,
|
|
120
|
+
label: ""
|
|
121
|
+
}, "")) + 2 * weight(action.label) + 2 * tokenLength(action) + row;
|
|
122
|
+
case "LinkButton":
|
|
123
|
+
return element(Render.linkAction({
|
|
124
|
+
...action,
|
|
125
|
+
label: "",
|
|
126
|
+
url: ""
|
|
127
|
+
})) + weight(action.label) + weight(action.url) + row;
|
|
128
|
+
case "Select":
|
|
129
|
+
// The adapter refuses a select before it renders anything.
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* The descriptor's `measure`: the weight of each unit of the Markdown plus
|
|
135
|
+
* the cost of each action, where a button's cost holds its token twice (the
|
|
136
|
+
* action and its fallback) at `tokenLength`, and each action pays for a
|
|
137
|
+
* whole `ActionSet` row. With `R` added it is never less than the size of
|
|
138
|
+
* either form of the activity.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export const makeMeasure = tokenLength => (markdown, actions) => {
|
|
143
|
+
let total = weight(markdown);
|
|
144
|
+
for (const action of actions ?? []) total += actionCost(action, tokenLength);
|
|
145
|
+
return total;
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=length.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"length.js","names":[],"sources":["../../src/internal/length.ts"],"sourcesContent":[null],"mappings":"AAQA,SAAS,WAAW,QAAQ,cAAc;AAC1C,OAAO,KAAK,MAAM,MAAM,aAAa;AAErC,MAAM,IAAI,GAAI,KAAc,IAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM;AAErE;AACA,MAAM,OAAO,GAAI,KAAc,IAAa,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;AAE3D;;;;;;;;;AASA,OAAO,MAAM,IAAI,GAAG,MAAM;AAE1B;AACA,OAAO,MAAM,CAAC,gBAAG,IAAI,cAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;AAE9C;AACA,OAAO,MAAM,CAAC,gBAAG,IAAI,cAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AAEhD;AACA,OAAO,MAAM,CAAC,GAAG,oBAAO,cAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,gBAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;AAEvE;;;;;;;AAOA,OAAO,MAAM,CAAC,gBAAG,IAAI,CAAC,GAAG,cACvB,OAAO,cAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,eAC7B,OAAO,cAAC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,eAC1C,OAAO,cAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAC9B;AAED,MAAM,EAAE,gBAAG,GAAG,CAAC,M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