@copilotkit/shared 0.5.0-mme-experimental-actions.0 → 0.5.0-mme-assistant-api.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.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +55 -62
  2. package/CHANGELOG.md +2 -2
  3. package/dist/chunk-FD6FGKYY.mjs +1 -0
  4. package/dist/chunk-NSY3OEEP.mjs +32 -0
  5. package/dist/chunk-NSY3OEEP.mjs.map +1 -0
  6. package/dist/{chunk-T6YVHLB7.mjs → chunk-TYZD5BQY.mjs} +1 -1
  7. package/dist/chunk-TYZD5BQY.mjs.map +1 -0
  8. package/dist/index.d.ts +1 -2
  9. package/dist/index.js +0 -81
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +6 -9
  12. package/dist/types/index.d.ts +0 -1
  13. package/dist/types/index.js.map +1 -1
  14. package/dist/types/index.mjs +1 -2
  15. package/dist/utils/annotated-function.d.ts +1 -3
  16. package/dist/utils/annotated-function.js +0 -81
  17. package/dist/utils/annotated-function.js.map +1 -1
  18. package/dist/utils/annotated-function.mjs +1 -3
  19. package/dist/utils/index.d.ts +1 -2
  20. package/dist/utils/index.js +0 -81
  21. package/dist/utils/index.js.map +1 -1
  22. package/dist/utils/index.mjs +5 -7
  23. package/dist/utils/parse-chat-completion.d.ts +1 -0
  24. package/dist/utils/parse-chat-completion.js.map +1 -1
  25. package/dist/utils/parse-chat-completion.mjs +1 -1
  26. package/dist/utils/utils.d.ts +6 -6
  27. package/package.json +5 -5
  28. package/src/types/index.ts +0 -1
  29. package/src/utils/annotated-function.ts +1 -90
  30. package/src/utils/parse-chat-completion.ts +1 -0
  31. package/dist/chunk-DE5K76I2.mjs +0 -1
  32. package/dist/chunk-GI5AWM7D.mjs +0 -112
  33. package/dist/chunk-GI5AWM7D.mjs.map +0 -1
  34. package/dist/chunk-NAFEBKSO.mjs +0 -1
  35. package/dist/chunk-NAFEBKSO.mjs.map +0 -1
  36. package/dist/chunk-T6YVHLB7.mjs.map +0 -1
  37. package/dist/types/action.d.ts +0 -54
  38. package/dist/types/action.js +0 -19
  39. package/dist/types/action.js.map +0 -1
  40. package/dist/types/action.mjs +0 -2
  41. package/dist/types/action.mjs.map +0 -1
  42. package/src/types/action.ts +0 -71
  43. /package/dist/{chunk-DE5K76I2.mjs.map → chunk-FD6FGKYY.mjs.map} +0 -0
@@ -1,112 +0,0 @@
1
- // src/utils/annotated-function.ts
2
- function annotatedFunctionToChatCompletionFunction(annotatedFunction) {
3
- let parameters = {};
4
- for (let arg of annotatedFunction.argumentAnnotations) {
5
- let { name, required, ...forwardedArgs } = arg;
6
- parameters[arg.name] = forwardedArgs;
7
- }
8
- let requiredParameterNames = [];
9
- for (let arg of annotatedFunction.argumentAnnotations) {
10
- if (arg.required) {
11
- requiredParameterNames.push(arg.name);
12
- }
13
- }
14
- let chatCompletionFunction = {
15
- type: "function",
16
- function: {
17
- name: annotatedFunction.name,
18
- description: annotatedFunction.description,
19
- parameters: {
20
- type: "object",
21
- properties: parameters,
22
- required: requiredParameterNames
23
- }
24
- }
25
- };
26
- return chatCompletionFunction;
27
- }
28
- function convertAttribute(attribute) {
29
- var _a, _b, _c;
30
- switch (attribute.type) {
31
- case "string":
32
- return {
33
- type: "string",
34
- description: attribute.description,
35
- ...attribute.enum && { enum: attribute.enum }
36
- };
37
- case "number":
38
- case "boolean":
39
- return {
40
- type: attribute.type,
41
- description: attribute.description
42
- };
43
- case "object":
44
- case "object[]":
45
- const properties = (_a = attribute.attributes) == null ? void 0 : _a.reduce((acc, attr) => {
46
- acc[attr.name] = convertAttribute(attr);
47
- return acc;
48
- }, {});
49
- const required = (_b = attribute.attributes) == null ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
50
- if (attribute.type === "object[]") {
51
- return {
52
- type: "array",
53
- items: {
54
- type: "object",
55
- ...properties && { properties },
56
- ...required && required.length > 0 && { required }
57
- },
58
- description: attribute.description
59
- };
60
- }
61
- return {
62
- type: "object",
63
- description: attribute.description,
64
- ...properties && { properties },
65
- ...required && required.length > 0 && { required }
66
- };
67
- default:
68
- if ((_c = attribute.type) == null ? void 0 : _c.endsWith("[]")) {
69
- const itemType = attribute.type.slice(0, -2);
70
- return {
71
- type: "array",
72
- items: { type: itemType },
73
- description: attribute.description
74
- };
75
- }
76
- return {
77
- type: "string",
78
- description: attribute.description
79
- };
80
- }
81
- }
82
- function actionToChatCompletionFunction(action) {
83
- let parameters = {};
84
- for (let parameter of action.parameters || []) {
85
- parameters[parameter.name] = convertAttribute(parameter);
86
- }
87
- let requiredParameterNames = [];
88
- for (let arg of action.parameters || []) {
89
- if (arg.required !== false) {
90
- requiredParameterNames.push(arg.name);
91
- }
92
- }
93
- let chatCompletionFunction = {
94
- type: "function",
95
- function: {
96
- name: action.name,
97
- ...action.description && { description: action.description },
98
- parameters: {
99
- type: "object",
100
- properties: parameters,
101
- required: requiredParameterNames
102
- }
103
- }
104
- };
105
- return chatCompletionFunction;
106
- }
107
-
108
- export {
109
- annotatedFunctionToChatCompletionFunction,
110
- actionToChatCompletionFunction
111
- };
112
- //# sourceMappingURL=chunk-GI5AWM7D.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/annotated-function.ts"],"sourcesContent":["import { Action, AnnotatedFunction, ToolDefinition, Parameter } from \"../types\";\n\nexport function annotatedFunctionToChatCompletionFunction(\n annotatedFunction: AnnotatedFunction<any[]>,\n): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let arg of annotatedFunction.argumentAnnotations) {\n // isolate the args we should forward inline\n let { name, required, ...forwardedArgs } = arg;\n parameters[arg.name] = forwardedArgs;\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of annotatedFunction.argumentAnnotations) {\n if (arg.required) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: annotatedFunction.name,\n description: annotatedFunction.description,\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n\nfunction convertAttribute(attribute: Parameter): any {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce((acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n }, {} as Record<string, any>);\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function actionToChatCompletionFunction(action: Action<any>): ToolDefinition {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of action.parameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of action.parameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n let chatCompletionFunction: ToolDefinition = {\n type: \"function\",\n function: {\n name: action.name,\n ...(action.description && { description: action.description }),\n parameters: {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n },\n },\n };\n\n return chatCompletionFunction;\n}\n"],"mappings":";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"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/parse-chat-completion.ts"],"sourcesContent":["import { Role } from \"../types/openai-assistant\";\n\nexport interface ChatCompletionChunk {\n choices: {\n delta: {\n role: Role;\n content?: string | null;\n\n // TODO:\n // Temporarily add name to the OpenAI protocol until we\n // have our own protocol.\n // When name is set, we return the result of a server-side\n // function call.\n name?: string;\n\n function_call?: {\n name?: string;\n arguments?: string;\n };\n tool_calls?: {\n index: number;\n id?: string;\n function: {\n arguments?: string;\n\n name?: string;\n // TODO:\n // Temporarily add scope to the OpenAI protocol until we\n // have our own protocol.\n // When scope is \"server\", the client will not attempt to\n // execute the function.\n scope?: \"client\" | \"server\";\n };\n }[];\n };\n }[];\n}\n\n// TODO:\n// it's possible that unicode characters could be split across chunks\n// make sure to properly handle that\nexport function parseChatCompletion(\n stream: ReadableStream<Uint8Array>,\n): ReadableStream<ChatCompletionChunk> {\n const reader = stream.getReader();\n let buffer = new Uint8Array();\n\n async function cleanup(controller?: ReadableStreamDefaultController<any>) {\n if (controller) {\n try {\n controller.close();\n } catch (_) {}\n }\n if (reader) {\n try {\n await reader.cancel();\n } catch (_) {}\n }\n }\n\n return new ReadableStream<ChatCompletionChunk>({\n async pull(controller) {\n while (true) {\n try {\n const { done, value } = await reader.read();\n\n if (done) {\n await cleanup(controller);\n return;\n }\n\n const newBuffer = new Uint8Array(buffer.length + value.length);\n newBuffer.set(buffer);\n newBuffer.set(value, buffer.length);\n buffer = newBuffer;\n\n const valueString = new TextDecoder(\"utf-8\").decode(buffer);\n const lines = valueString.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\n // If the last line isn't complete, keep it in the buffer for next time\n buffer = !valueString.endsWith(\"\\n\")\n ? new TextEncoder().encode(lines.pop() || \"\")\n : new Uint8Array();\n\n for (const line of lines) {\n const cleanedLine = line.replace(/^data: /, \"\");\n\n if (cleanedLine === \"[DONE]\") {\n await cleanup(controller);\n return;\n }\n\n const json = JSON.parse(cleanedLine);\n controller.enqueue(json);\n }\n } catch (error) {\n controller.error(error);\n await cleanup(controller);\n return;\n }\n }\n },\n cancel() {\n reader.cancel();\n },\n });\n}\n"],"mappings":";AAyCO,SAAS,oBACd,QACqC;AACrC,QAAM,SAAS,OAAO,UAAU;AAChC,MAAI,SAAS,IAAI,WAAW;AAE5B,iBAAe,QAAQ,YAAmD;AACxE,QAAI,YAAY;AACd,UAAI;AACF,mBAAW,MAAM;AAAA,MACnB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AACA,QAAI,QAAQ;AACV,UAAI;AACF,cAAM,OAAO,OAAO;AAAA,MACtB,SAAS,GAAP;AAAA,MAAW;AAAA,IACf;AAAA,EACF;AAEA,SAAO,IAAI,eAAoC;AAAA,IAC7C,MAAM,KAAK,YAAY;AACrB,aAAO,MAAM;AACX,YAAI;AACF,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,cAAI,MAAM;AACR,kBAAM,QAAQ,UAAU;AACxB;AAAA,UACF;AAEA,gBAAM,YAAY,IAAI,WAAW,OAAO,SAAS,MAAM,MAAM;AAC7D,oBAAU,IAAI,MAAM;AACpB,oBAAU,IAAI,OAAO,OAAO,MAAM;AAClC,mBAAS;AAET,gBAAM,cAAc,IAAI,YAAY,OAAO,EAAE,OAAO,MAAM;AAC1D,gBAAM,QAAQ,YAAY,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,MAAM,EAAE;AAGzE,mBAAS,CAAC,YAAY,SAAS,IAAI,IAC/B,IAAI,YAAY,EAAE,OAAO,MAAM,IAAI,KAAK,EAAE,IAC1C,IAAI,WAAW;AAEnB,qBAAW,QAAQ,OAAO;AACxB,kBAAM,cAAc,KAAK,QAAQ,WAAW,EAAE;AAE9C,gBAAI,gBAAgB,UAAU;AAC5B,oBAAM,QAAQ,UAAU;AACxB;AAAA,YACF;AAEA,kBAAM,OAAO,KAAK,MAAM,WAAW;AACnC,uBAAW,QAAQ,IAAI;AAAA,UACzB;AAAA,QACF,SAAS,OAAP;AACA,qBAAW,MAAM,KAAK;AACtB,gBAAM,QAAQ,UAAU;AACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,OAAO;AAAA,IAChB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,54 +0,0 @@
1
- type TypeMap = {
2
- string: string;
3
- number: number;
4
- boolean: boolean;
5
- object: object;
6
- "string[]": string[];
7
- "number[]": number[];
8
- "boolean[]": boolean[];
9
- "object[]": object[];
10
- };
11
- type BaseParameter = {
12
- name: string;
13
- type?: Exclude<keyof TypeMap, "string" | "object" | "object[]">;
14
- description?: string;
15
- required?: boolean;
16
- };
17
- type StringParameter = {
18
- name: string;
19
- type: "string";
20
- description?: string;
21
- required?: boolean;
22
- enum?: string[];
23
- };
24
- type ObjectParameter = {
25
- name: string;
26
- type: "object" | "object[]";
27
- description?: string;
28
- required?: boolean;
29
- attributes?: Parameter[];
30
- };
31
- type Parameter = BaseParameter | StringParameter | ObjectParameter;
32
- type MappedParameterTypes<T extends Parameter[]> = {
33
- [P in T[number] as P["name"]]: P extends {
34
- enum: Array<infer E>;
35
- } ? E extends string ? P["required"] extends false ? E | undefined : E : never : P extends {
36
- type: "object";
37
- attributes: infer Attributes;
38
- } ? Attributes extends Parameter[] ? MappedParameterTypes<Attributes> : never : P extends {
39
- type: "object[]";
40
- attributes?: never;
41
- } ? any[] : P extends {
42
- type: "object[]";
43
- attributes: infer Attributes;
44
- } ? Attributes extends Parameter[] ? MappedParameterTypes<Attributes>[] : any[] : P["required"] extends false ? // Include 'undefined' for optional parameters
45
- TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined : TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
46
- };
47
- type Action<T extends Parameter[] | [] = []> = {
48
- name: string;
49
- description?: string;
50
- parameters?: T;
51
- handler: T extends [] ? () => void : (args: MappedParameterTypes<T>) => any | Promise<any>;
52
- };
53
-
54
- export { Action, BaseParameter, ObjectParameter, Parameter, StringParameter };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/types/action.ts
17
- var action_exports = {};
18
- module.exports = __toCommonJS(action_exports);
19
- //# sourceMappingURL=action.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/action.ts"],"sourcesContent":["type TypeMap = {\n string: string;\n number: number;\n boolean: boolean;\n object: object;\n \"string[]\": string[];\n \"number[]\": number[];\n \"boolean[]\": boolean[];\n \"object[]\": object[];\n};\n\nexport type BaseParameter = {\n name: string;\n type?: Exclude<keyof TypeMap, \"string\" | \"object\" | \"object[]\">; // Exclude object types for BaseParameter\n description?: string;\n required?: boolean;\n};\n\nexport type StringParameter = {\n name: string;\n type: \"string\";\n description?: string;\n required?: boolean;\n enum?: string[];\n};\n\nexport type ObjectParameter = {\n name: string;\n type: \"object\" | \"object[]\";\n description?: string;\n required?: boolean;\n attributes?: Parameter[];\n};\n\nexport type Parameter = BaseParameter | StringParameter | ObjectParameter;\n\ntype MappedParameterTypes<T extends Parameter[]> = {\n // Check if the parameter has an 'enum' defined\n [P in T[number] as P[\"name\"]]: P extends { enum: Array<infer E> }\n ? E extends string // Ensure the enum values are strings\n ? P[\"required\"] extends false // Check if the parameter is optional\n ? E | undefined // If so, include 'undefined' in the type\n : E // Otherwise, use the enum type directly\n : never // This case should not occur since 'enum' implies string values\n : // Handle parameters defined as 'object' with specified attributes\n P extends { type: \"object\"; attributes: infer Attributes }\n ? Attributes extends Parameter[]\n ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object\n : never // If 'attributes' is not an array of Parameters, this is invalid\n : // Handle parameters defined as 'object[]' without specified attributes\n P extends { type: \"object[]\"; attributes?: never }\n ? any[] // Default to 'any[]' for arrays of objects without specific attributes\n : // Handle parameters defined as 'object[]' with specified attributes\n P extends { type: \"object[]\"; attributes: infer Attributes }\n ? Attributes extends Parameter[]\n ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array\n : any[] // Default to 'any[]' if attributes are not properly defined\n : // Handle all other parameter types\n P[\"required\"] extends false\n ? // Include 'undefined' for optional parameters\n TypeMap[P[\"type\"] extends keyof TypeMap ? P[\"type\"] : \"string\"] | undefined\n : // Use the direct mapping from 'TypeMap' for the parameter's type\n TypeMap[P[\"type\"] extends keyof TypeMap ? P[\"type\"] : \"string\"];\n};\n\nexport type Action<T extends Parameter[] | [] = []> = {\n name: string;\n description?: string;\n parameters?: T;\n handler: T extends [] ? () => void : (args: MappedParameterTypes<T>) => any | Promise<any>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,2 +0,0 @@
1
- import "../chunk-NAFEBKSO.mjs";
2
- //# sourceMappingURL=action.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,71 +0,0 @@
1
- type TypeMap = {
2
- string: string;
3
- number: number;
4
- boolean: boolean;
5
- object: object;
6
- "string[]": string[];
7
- "number[]": number[];
8
- "boolean[]": boolean[];
9
- "object[]": object[];
10
- };
11
-
12
- export type BaseParameter = {
13
- name: string;
14
- type?: Exclude<keyof TypeMap, "string" | "object" | "object[]">; // Exclude object types for BaseParameter
15
- description?: string;
16
- required?: boolean;
17
- };
18
-
19
- export type StringParameter = {
20
- name: string;
21
- type: "string";
22
- description?: string;
23
- required?: boolean;
24
- enum?: string[];
25
- };
26
-
27
- export type ObjectParameter = {
28
- name: string;
29
- type: "object" | "object[]";
30
- description?: string;
31
- required?: boolean;
32
- attributes?: Parameter[];
33
- };
34
-
35
- export type Parameter = BaseParameter | StringParameter | ObjectParameter;
36
-
37
- type MappedParameterTypes<T extends Parameter[]> = {
38
- // Check if the parameter has an 'enum' defined
39
- [P in T[number] as P["name"]]: P extends { enum: Array<infer E> }
40
- ? E extends string // Ensure the enum values are strings
41
- ? P["required"] extends false // Check if the parameter is optional
42
- ? E | undefined // If so, include 'undefined' in the type
43
- : E // Otherwise, use the enum type directly
44
- : never // This case should not occur since 'enum' implies string values
45
- : // Handle parameters defined as 'object' with specified attributes
46
- P extends { type: "object"; attributes: infer Attributes }
47
- ? Attributes extends Parameter[]
48
- ? MappedParameterTypes<Attributes> // Recursively map the attributes of the object
49
- : never // If 'attributes' is not an array of Parameters, this is invalid
50
- : // Handle parameters defined as 'object[]' without specified attributes
51
- P extends { type: "object[]"; attributes?: never }
52
- ? any[] // Default to 'any[]' for arrays of objects without specific attributes
53
- : // Handle parameters defined as 'object[]' with specified attributes
54
- P extends { type: "object[]"; attributes: infer Attributes }
55
- ? Attributes extends Parameter[]
56
- ? MappedParameterTypes<Attributes>[] // Recursively map each object in the array
57
- : any[] // Default to 'any[]' if attributes are not properly defined
58
- : // Handle all other parameter types
59
- P["required"] extends false
60
- ? // Include 'undefined' for optional parameters
61
- TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"] | undefined
62
- : // Use the direct mapping from 'TypeMap' for the parameter's type
63
- TypeMap[P["type"] extends keyof TypeMap ? P["type"] : "string"];
64
- };
65
-
66
- export type Action<T extends Parameter[] | [] = []> = {
67
- name: string;
68
- description?: string;
69
- parameters?: T;
70
- handler: T extends [] ? () => void : (args: MappedParameterTypes<T>) => any | Promise<any>;
71
- };