@krak-stack/registry 0.1.14 → 0.1.15

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.
@@ -19,10 +19,18 @@ import { HttpClient } from "effect/unstable/http";
19
19
  import {
20
20
  HttpApiClient as EffectHttpApiClient
21
21
  } from "effect/unstable/httpapi";
22
- var HttpApiOperationResult = Schema.Union([
23
- Schema.Json,
22
+ var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
23
+ Schema.Null,
24
+ Schema.String,
25
+ Schema.Number,
26
+ Schema.Boolean,
24
27
  Schema.DateFromString,
25
28
  Schema.Uint8ArrayFromBase64,
29
+ Schema.Array(HttpApiOperationResultValue),
30
+ Schema.Record(Schema.String, HttpApiOperationResultValue)
31
+ ]));
32
+ var HttpApiOperationResult = Schema.Union([
33
+ HttpApiOperationResultValue,
26
34
  Schema.Undefined
27
35
  ]).annotate({ identifier: "HttpApiOperationResult" });
28
36
  var encodeHttpApiOperationResult = Effect.fn("HttpApiClient.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
@@ -12,7 +12,10 @@ export type ApiClientExecuteOptions = {
12
12
  readonly operation: HttpApiOperationEntry;
13
13
  readonly input: HttpApiOperationInput;
14
14
  };
15
- export declare const HttpApiOperationResult: Schema.Union<readonly [Schema.Codec<Json, Json, never, never>, Schema.DateFromString, Schema.Uint8ArrayFromBase64, Schema.Undefined]>;
15
+ export type HttpApiOperationResultValue = null | string | number | boolean | Date | Uint8Array | ReadonlyArray<HttpApiOperationResultValue> | {
16
+ readonly [key: string]: HttpApiOperationResultValue;
17
+ };
18
+ export declare const HttpApiOperationResult: Schema.Union<readonly [Schema.Codec<HttpApiOperationResultValue, Json, never, never>, Schema.Undefined]>;
16
19
  export type HttpApiOperationResult = typeof HttpApiOperationResult.Type;
17
20
  export declare const encodeHttpApiOperationResult: (result: unknown) => Effect.Effect<string | number | boolean | Schema.JsonArray | Schema.JsonObject | null, Error, never>;
18
21
  export type ApiClientService = {
@@ -4,10 +4,18 @@ import { HttpClient } from "effect/unstable/http";
4
4
  import {
5
5
  HttpApiClient as EffectHttpApiClient
6
6
  } from "effect/unstable/httpapi";
7
- var HttpApiOperationResult = Schema.Union([
8
- Schema.Json,
7
+ var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
8
+ Schema.Null,
9
+ Schema.String,
10
+ Schema.Number,
11
+ Schema.Boolean,
9
12
  Schema.DateFromString,
10
13
  Schema.Uint8ArrayFromBase64,
14
+ Schema.Array(HttpApiOperationResultValue),
15
+ Schema.Record(Schema.String, HttpApiOperationResultValue)
16
+ ]));
17
+ var HttpApiOperationResult = Schema.Union([
18
+ HttpApiOperationResultValue,
11
19
  Schema.Undefined
12
20
  ]).annotate({ identifier: "HttpApiOperationResult" });
13
21
  var encodeHttpApiOperationResult = Effect.fn("HttpApiClient.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
@@ -8,10 +8,18 @@ import { HttpClient } from "effect/unstable/http";
8
8
  import {
9
9
  HttpApiClient as EffectHttpApiClient
10
10
  } from "effect/unstable/httpapi";
11
- var HttpApiOperationResult = Schema.Union([
12
- Schema.Json,
11
+ var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
12
+ Schema.Null,
13
+ Schema.String,
14
+ Schema.Number,
15
+ Schema.Boolean,
13
16
  Schema.DateFromString,
14
17
  Schema.Uint8ArrayFromBase64,
18
+ Schema.Array(HttpApiOperationResultValue),
19
+ Schema.Record(Schema.String, HttpApiOperationResultValue)
20
+ ]));
21
+ var HttpApiOperationResult = Schema.Union([
22
+ HttpApiOperationResultValue,
15
23
  Schema.Undefined
16
24
  ]).annotate({ identifier: "HttpApiOperationResult" });
17
25
  var encodeHttpApiOperationResult = Effect.fn("HttpApiClient.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
@@ -8,10 +8,18 @@ import { HttpClient } from "effect/unstable/http";
8
8
  import {
9
9
  HttpApiClient as EffectHttpApiClient
10
10
  } from "effect/unstable/httpapi";
11
- var HttpApiOperationResult = Schema.Union([
12
- Schema.Json,
11
+ var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
12
+ Schema.Null,
13
+ Schema.String,
14
+ Schema.Number,
15
+ Schema.Boolean,
13
16
  Schema.DateFromString,
14
17
  Schema.Uint8ArrayFromBase64,
18
+ Schema.Array(HttpApiOperationResultValue),
19
+ Schema.Record(Schema.String, HttpApiOperationResultValue)
20
+ ]));
21
+ var HttpApiOperationResult = Schema.Union([
22
+ HttpApiOperationResultValue,
15
23
  Schema.Undefined
16
24
  ]).annotate({ identifier: "HttpApiOperationResult" });
17
25
  var encodeHttpApiOperationResult = Effect.fn("HttpApiClient.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
@@ -1527,7 +1527,30 @@ var highlightedInput = (input, references) => {
1527
1527
  children: part
1528
1528
  }, `${part}:${index}`) : part);
1529
1529
  };
1530
- var referenceSearchQuery = (input) => input.match(/(?:^|\s)@([^@\n]*)$/)?.[1].trimEnd();
1530
+ var referenceSearchAtCursor = (input, cursor) => {
1531
+ const beforeCursor = input.slice(0, cursor);
1532
+ const match = beforeCursor.match(/(?:^|\s)@([^@\n]*)$/);
1533
+ if (!match)
1534
+ return;
1535
+ return {
1536
+ start: beforeCursor.lastIndexOf("@"),
1537
+ end: cursor,
1538
+ query: match[1].trimEnd()
1539
+ };
1540
+ };
1541
+ var insertReferenceMention = (input, search, label) => {
1542
+ const suffix = input.slice(search.end);
1543
+ const mention = `@${label}`;
1544
+ const separator = /^[ \t]/.test(suffix) ? "" : " ";
1545
+ return {
1546
+ input: `${input.slice(0, search.start)}${mention}${separator}${suffix}`,
1547
+ cursor: search.start + mention.length + 1
1548
+ };
1549
+ };
1550
+ var completesSelectedReference = (input, search, references) => {
1551
+ const searchText = input.slice(search.start + 1, search.end);
1552
+ return references.some(({ label }) => searchText.startsWith(`${label} `));
1553
+ };
1531
1554
  var ToolLabel = ({
1532
1555
  description,
1533
1556
  label
@@ -1873,14 +1896,16 @@ function AgentWidget({
1873
1896
  const [maximized, setMaximized] = useState(false);
1874
1897
  const [referencePickerOpen, setReferencePickerOpen] = useState(false);
1875
1898
  const [activeReferenceKey, setActiveReferenceKey] = useState("");
1899
+ const [activeReferenceSearch, setActiveReferenceSearch] = useState();
1876
1900
  const [input, setInput] = useState("");
1901
+ const inputRef = useRef(null);
1877
1902
  const inputOverlayRef = useRef(null);
1878
1903
  const [references, setReferences] = useState([]);
1879
1904
  const activeContext = state.contextLocked ? state.context ? {
1880
1905
  ...state.context,
1881
1906
  icon: availableReferences.find(({ key }) => key === state.context?.key)?.icon
1882
1907
  } : undefined : context;
1883
- const referenceQuery = referenceSearchQuery(input);
1908
+ const referenceQuery = activeReferenceSearch?.query;
1884
1909
  const selectedKeys = new Set(references.map(({ key }) => key));
1885
1910
  const selectedLabels = new Set(references.map(({ label }) => label));
1886
1911
  const selectableReferences = availableReferences.filter((reference) => references.length < AGENT_REFERENCE_LIMIT && reference.key !== activeContext?.key && !selectedKeys.has(reference.key) && !selectedLabels.has(reference.label));
@@ -1894,6 +1919,7 @@ function AgentWidget({
1894
1919
  return;
1895
1920
  setInput("");
1896
1921
  setReferences([]);
1922
+ setActiveReferenceSearch(undefined);
1897
1923
  setReferencePickerOpen(false);
1898
1924
  const messageReferences = references.length > 0 ? references.map(({ label, resource }) => ({ label, resource })) : undefined;
1899
1925
  const action = {
@@ -1914,15 +1940,24 @@ function AgentWidget({
1914
1940
  });
1915
1941
  };
1916
1942
  const selectReference = (reference) => {
1943
+ if (!activeReferenceSearch)
1944
+ return;
1945
+ const replacement = insertReferenceMention(input, activeReferenceSearch, reference.label);
1917
1946
  setReferences((current) => [...current, reference]);
1918
- setInput((current) => current.replace(/@[^@\n]*$/, `@${reference.label}`));
1947
+ setInput(replacement.input);
1948
+ setActiveReferenceSearch(undefined);
1919
1949
  setReferencePickerOpen(false);
1950
+ requestAnimationFrame(() => {
1951
+ inputRef.current?.focus();
1952
+ inputRef.current?.setSelectionRange(replacement.cursor, replacement.cursor);
1953
+ });
1920
1954
  };
1921
1955
  const clearConversation = () => {
1922
1956
  onInterrupt();
1923
1957
  onReset();
1924
1958
  setInput("");
1925
1959
  setReferences([]);
1960
+ setActiveReferenceSearch(undefined);
1926
1961
  setReferencePickerOpen(false);
1927
1962
  };
1928
1963
  const handleOpenChange = (nextOpen) => {
@@ -2116,6 +2151,7 @@ function AgentWidget({
2116
2151
  /* @__PURE__ */ jsx17(PopoverTrigger, {
2117
2152
  id: referenceInputId,
2118
2153
  render: /* @__PURE__ */ jsx17(InputGroupTextarea, {
2154
+ ref: inputRef,
2119
2155
  className: "caret-foreground selection:bg-primary selection:text-primary-foreground relative max-h-32 w-full [scrollbar-width:thin] [scrollbar-color:var(--border)_transparent] [scrollbar-gutter:stable] overflow-y-auto overscroll-contain text-left text-transparent",
2120
2156
  value: input,
2121
2157
  placeholder: labels.placeholder,
@@ -2134,11 +2170,12 @@ function AgentWidget({
2134
2170
  },
2135
2171
  onChange: (event) => {
2136
2172
  const value = event.target.value;
2173
+ const candidate = referenceSearchAtCursor(value, event.currentTarget.selectionStart);
2174
+ const search = candidate && !completesSelectedReference(value, candidate, references) ? candidate : undefined;
2137
2175
  setInput(value);
2176
+ setActiveReferenceSearch(search);
2138
2177
  setReferences((current) => current.filter(({ label }) => hasReferenceMention(value, label)));
2139
- const query = referenceSearchQuery(value);
2140
- const startsReferenceQuery = query !== undefined && value.lastIndexOf("@") > input.lastIndexOf("@");
2141
- setReferencePickerOpen((current) => current || startsReferenceQuery && selectableReferences.length > 0);
2178
+ setReferencePickerOpen(search !== undefined && selectableReferences.length > 0);
2142
2179
  },
2143
2180
  onKeyDown: (event) => {
2144
2181
  if (event.key === "Escape" && referencePickerOpen) {
@@ -2180,7 +2217,7 @@ function AgentWidget({
2180
2217
  /* @__PURE__ */ jsx17(CommandEmpty, {
2181
2218
  children: labels.noReferences
2182
2219
  }),
2183
- /* @__PURE__ */ jsx17(CommandGroup, {
2220
+ matchingReferences.length > 0 ? /* @__PURE__ */ jsx17(CommandGroup, {
2184
2221
  heading: labels.references,
2185
2222
  children: matchingReferences.map((reference, index) => /* @__PURE__ */ jsxs5(CommandItem, {
2186
2223
  id: `${referenceInputId}-reference-${index}`,
@@ -2194,7 +2231,7 @@ function AgentWidget({
2194
2231
  })
2195
2232
  ]
2196
2233
  }, reference.key))
2197
- })
2234
+ }) : null
2198
2235
  ]
2199
2236
  })
2200
2237
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {