@krak-stack/registry 0.1.13 → 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.
Files changed (44) hide show
  1. package/README.md +19 -0
  2. package/dist/components/ui/app-brand.d.ts +18 -13
  3. package/dist/components/ui/app-brand.js +48 -15
  4. package/dist/components/ui/code-block.js +10 -6
  5. package/dist/components/ui/copy-button.d.ts +1 -1
  6. package/dist/components/ui/copy-button.js +1 -1
  7. package/dist/components/ui/data-table.d.ts +1 -1
  8. package/dist/components/ui/data-table.js +21 -20
  9. package/dist/components/ui/effect-form.js +7 -6
  10. package/dist/components/ui/file-picker.js +2 -1
  11. package/dist/components/ui/form.js +17 -15
  12. package/dist/components/ui/google-map.d.ts +6 -10
  13. package/dist/components/ui/google-map.js +19 -14
  14. package/dist/components/ui/locale-switcher.js +7 -1
  15. package/dist/components/ui/sidebar-layout.js +19 -21
  16. package/dist/components/ui/theme-switcher.js +1 -1
  17. package/dist/lib/docs-core.js +165 -109
  18. package/dist/lib/documentation-toolkit.d.ts +1 -1
  19. package/dist/lib/documentation-toolkit.js +41 -40
  20. package/dist/lib/httpapi-cli.d.ts +6 -6
  21. package/dist/lib/httpapi-cli.js +83 -48
  22. package/dist/lib/httpapi-client.d.ts +11 -2
  23. package/dist/lib/httpapi-client.js +29 -9
  24. package/dist/lib/httpapi-helpers.d.ts +15 -21
  25. package/dist/lib/httpapi-helpers.js +38 -26
  26. package/dist/lib/httpapi-mcp.js +81 -50
  27. package/dist/lib/httpapi-toolkit.d.ts +3 -2
  28. package/dist/lib/httpapi-toolkit.js +101 -65
  29. package/dist/lib/seo.js +29 -17
  30. package/dist/oxlint/anti-slop/index.js +1592 -0
  31. package/dist/services/agent/client/atom.d.ts +7 -7
  32. package/dist/services/agent/client/index.js +100 -62
  33. package/dist/services/agent/index.d.ts +71 -71
  34. package/dist/services/agent/index.js +38 -19
  35. package/dist/services/notification/channels/index.d.ts +11 -9
  36. package/dist/services/notification/channels/ses/index.d.ts +6 -6
  37. package/dist/services/notification/channels/ses/index.js +15 -11
  38. package/dist/services/notification/client/index.js +3 -2
  39. package/dist/services/notification/client/notification-menu.d.ts +9 -9
  40. package/dist/services/notification/index.d.ts +7 -6
  41. package/dist/services/notification/public.js +3 -2
  42. package/dist/services/s3/index.d.ts +2 -16
  43. package/dist/services/s3/index.js +12 -9
  44. package/package.json +7 -1
@@ -1,4 +1,4 @@
1
- import { Effect, Stream } from "effect";
1
+ import { Effect, Option, Stream } from "effect";
2
2
  import { Atom, Reactivity } from "effect/unstable/reactivity";
3
3
  import type { AgentErrorCode, AgentEvent, AgentReference, AgentRequest } from "../schema.js";
4
4
  export type AgentToolStatus = "running" | "approval-required" | "approved" | "denied" | "completed" | "failed";
@@ -37,9 +37,9 @@ export type AgentState<Resource = never> = {
37
37
  };
38
38
  export declare const initialAgentState: AgentState<never>;
39
39
  export declare const reduceAgentEvent: <Resource>(state: AgentState<Resource>, event: AgentEvent) => AgentState<Resource>;
40
- export type AgentAtomsConfig<Resource> = {
41
- readonly stream: (get: Atom.FnContext, request: AgentRequest<Resource>) => Effect.Effect<Stream.Stream<AgentEvent, unknown, Reactivity.Reactivity>, unknown>;
42
- readonly errorCode?: (error: unknown) => AgentErrorCode;
40
+ export type AgentAtomsConfig<Resource, Failure = ErrorOptions["cause"]> = {
41
+ readonly stream: (get: Atom.FnContext, request: AgentRequest<Resource>) => Effect.Effect<Stream.Stream<AgentEvent, Failure, Reactivity.Reactivity>, Failure>;
42
+ readonly errorCode?: (error: Failure) => AgentErrorCode;
43
43
  readonly reactivityKeys?: ReadonlyArray<unknown>;
44
44
  readonly runtime?: Atom.AtomRuntime<never>;
45
45
  };
@@ -48,9 +48,9 @@ export type AgentSubmitInput<Resource> = {
48
48
  readonly context?: AgentConversationContext<Resource>;
49
49
  readonly scope: string;
50
50
  };
51
- export declare const makeAgentAtoms: <Resource>({ errorCode, reactivityKeys, runtime, stream, }: AgentAtomsConfig<Resource>) => {
52
- readonly removeContext: Atom.Writable<import("effect/Option").Option<void>, string>;
53
- readonly reset: Atom.Writable<import("effect/Option").Option<void>, string>;
51
+ export declare const makeAgentAtoms: <Resource, Failure = unknown>({ errorCode, reactivityKeys, runtime, stream, }: AgentAtomsConfig<Resource, Failure>) => {
52
+ readonly removeContext: Atom.Writable<Option.Option<void>, string>;
53
+ readonly reset: Atom.Writable<Option.Option<void>, string>;
54
54
  readonly state: (arg: string) => Atom.Writable<AgentState<Resource>, AgentState<Resource>>;
55
55
  readonly submit: Atom.AtomResultFn<AgentSubmitInput<Resource>, void, never>;
56
56
  };
@@ -1,5 +1,5 @@
1
1
  // ../../src/services/agent/client/atom.ts
2
- import { Effect, Layer, Stream } from "effect";
2
+ import { Effect, Layer, Option, Schema, Stream } from "effect";
3
3
  import { Atom } from "effect/unstable/reactivity";
4
4
  var initialAgentState = {
5
5
  context: undefined,
@@ -64,12 +64,15 @@ var reduceAgentEvent = (state, event) => {
64
64
  return state;
65
65
  }
66
66
  };
67
+ var AgentError = Schema.Struct({
68
+ code: Schema.Literals(["stream-failed", "unavailable"])
69
+ }).annotate({ identifier: "AgentError" });
67
70
  var defaultErrorCode = (error) => {
68
- if (error && typeof error === "object") {
69
- const code = Reflect.get(error, "code");
70
- if (code === "stream-failed" || code === "unavailable")
71
- return code;
72
- }
71
+ const failure = Schema.decodeUnknownOption(AgentError)(error);
72
+ if (Option.isNone(failure))
73
+ return "unavailable";
74
+ if (failure.value.code === "stream-failed")
75
+ return "stream-failed";
73
76
  return "unavailable";
74
77
  };
75
78
  var makeAgentAtoms = ({
@@ -628,8 +631,9 @@ function InputGroupAddon({
628
631
  "data-align": align,
629
632
  className: cn(inputGroupAddonVariants({ align }), className),
630
633
  onClick: (event) => {
631
- if (event.target.closest("button"))
634
+ if (event.target instanceof HTMLElement && event.target.closest("button")) {
632
635
  return;
636
+ }
633
637
  event.currentTarget.parentElement?.querySelector("input")?.focus();
634
638
  },
635
639
  ...props
@@ -1346,7 +1350,7 @@ function isCustomStrategy(strategy2) {
1346
1350
  }
1347
1351
 
1348
1352
  // ../../src/services/agent/schema.ts
1349
- import { Schema } from "effect";
1353
+ import { Schema as Schema2 } from "effect";
1350
1354
  import {
1351
1355
  HttpApiEndpoint,
1352
1356
  HttpApiError,
@@ -1354,63 +1358,63 @@ import {
1354
1358
  HttpApiSchema,
1355
1359
  OpenApi
1356
1360
  } from "effect/unstable/httpapi";
1357
- var AgentMessageText = Schema.String.check(Schema.isLengthBetween(1, 4000)).annotate({
1361
+ var AgentMessageText = Schema2.String.check(Schema2.isLengthBetween(1, 4000)).annotate({
1358
1362
  identifier: "AgentMessageText",
1359
1363
  title: "Agent message",
1360
1364
  description: "A user message sent to the agent."
1361
1365
  });
1362
- var AgentReferenceLabel = Schema.String.check(Schema.isLengthBetween(1, 500));
1366
+ var AgentReferenceLabel = Schema2.String.check(Schema2.isLengthBetween(1, 500));
1363
1367
  var AGENT_REFERENCE_LIMIT = 20;
1364
- var AgentToolMetadata = Schema.Struct({
1365
- title: Schema.optional(Schema.String),
1366
- description: Schema.optional(Schema.String),
1367
- destructive: Schema.Boolean
1368
+ var AgentToolMetadata = Schema2.Struct({
1369
+ title: Schema2.optional(Schema2.String),
1370
+ description: Schema2.optional(Schema2.String),
1371
+ destructive: Schema2.Boolean
1368
1372
  }).annotate({ identifier: "AgentToolMetadata" });
1369
- var AgentEvent = Schema.Union([
1370
- Schema.Struct({
1371
- type: Schema.Literal("message-start"),
1372
- messageId: Schema.String
1373
+ var AgentEvent = Schema2.Union([
1374
+ Schema2.Struct({
1375
+ type: Schema2.Literal("message-start"),
1376
+ messageId: Schema2.String
1373
1377
  }),
1374
- Schema.Struct({
1375
- type: Schema.Literal("text-delta"),
1376
- messageId: Schema.String,
1377
- delta: Schema.String
1378
+ Schema2.Struct({
1379
+ type: Schema2.Literal("text-delta"),
1380
+ messageId: Schema2.String,
1381
+ delta: Schema2.String
1378
1382
  }),
1379
- Schema.Struct({
1380
- type: Schema.Literal("tool-call"),
1381
- messageId: Schema.String,
1382
- toolCallId: Schema.String,
1383
- name: Schema.String,
1384
- input: Schema.Unknown,
1383
+ Schema2.Struct({
1384
+ type: Schema2.Literal("tool-call"),
1385
+ messageId: Schema2.String,
1386
+ toolCallId: Schema2.String,
1387
+ name: Schema2.String,
1388
+ input: Schema2.Unknown,
1385
1389
  metadata: AgentToolMetadata
1386
1390
  }),
1387
- Schema.Struct({
1388
- type: Schema.Literal("tool-result"),
1389
- toolCallId: Schema.String,
1390
- name: Schema.String,
1391
- isFailure: Schema.Boolean
1391
+ Schema2.Struct({
1392
+ type: Schema2.Literal("tool-result"),
1393
+ toolCallId: Schema2.String,
1394
+ name: Schema2.String,
1395
+ isFailure: Schema2.Boolean
1392
1396
  }),
1393
- Schema.Struct({
1394
- type: Schema.Literal("approval-required"),
1395
- approvalId: Schema.String,
1396
- toolCallId: Schema.String
1397
+ Schema2.Struct({
1398
+ type: Schema2.Literal("approval-required"),
1399
+ approvalId: Schema2.String,
1400
+ toolCallId: Schema2.String
1397
1401
  }),
1398
- Schema.Struct({
1399
- type: Schema.Literal("history"),
1400
- value: Schema.String
1402
+ Schema2.Struct({
1403
+ type: Schema2.Literal("history"),
1404
+ value: Schema2.String
1401
1405
  }),
1402
- Schema.Struct({ type: Schema.Literal("finish") }),
1403
- Schema.Struct({
1404
- type: Schema.Literal("error"),
1405
- code: Schema.Literals(["unavailable", "invalid-request", "stream-failed"])
1406
+ Schema2.Struct({ type: Schema2.Literal("finish") }),
1407
+ Schema2.Struct({
1408
+ type: Schema2.Literal("error"),
1409
+ code: Schema2.Literals(["unavailable", "invalid-request", "stream-failed"])
1406
1410
  })
1407
1411
  ]).annotate({
1408
1412
  identifier: "AgentEvent",
1409
1413
  title: "Agent stream event",
1410
1414
  description: "An event emitted by the agent endpoint."
1411
1415
  });
1412
- var AgentStreamError = Schema.Struct({
1413
- code: Schema.Literals(["unavailable", "stream-failed"])
1416
+ var AgentStreamError = Schema2.Struct({
1417
+ code: Schema2.Literals(["unavailable", "stream-failed"])
1414
1418
  }).annotate({
1415
1419
  identifier: "AgentStreamError",
1416
1420
  title: "Agent stream error",
@@ -1523,7 +1527,30 @@ var highlightedInput = (input, references) => {
1523
1527
  children: part
1524
1528
  }, `${part}:${index}`) : part);
1525
1529
  };
1526
- 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
+ };
1527
1554
  var ToolLabel = ({
1528
1555
  description,
1529
1556
  label
@@ -1869,14 +1896,16 @@ function AgentWidget({
1869
1896
  const [maximized, setMaximized] = useState(false);
1870
1897
  const [referencePickerOpen, setReferencePickerOpen] = useState(false);
1871
1898
  const [activeReferenceKey, setActiveReferenceKey] = useState("");
1899
+ const [activeReferenceSearch, setActiveReferenceSearch] = useState();
1872
1900
  const [input, setInput] = useState("");
1901
+ const inputRef = useRef(null);
1873
1902
  const inputOverlayRef = useRef(null);
1874
1903
  const [references, setReferences] = useState([]);
1875
1904
  const activeContext = state.contextLocked ? state.context ? {
1876
1905
  ...state.context,
1877
1906
  icon: availableReferences.find(({ key }) => key === state.context?.key)?.icon
1878
1907
  } : undefined : context;
1879
- const referenceQuery = referenceSearchQuery(input);
1908
+ const referenceQuery = activeReferenceSearch?.query;
1880
1909
  const selectedKeys = new Set(references.map(({ key }) => key));
1881
1910
  const selectedLabels = new Set(references.map(({ label }) => label));
1882
1911
  const selectableReferences = availableReferences.filter((reference) => references.length < AGENT_REFERENCE_LIMIT && reference.key !== activeContext?.key && !selectedKeys.has(reference.key) && !selectedLabels.has(reference.label));
@@ -1890,17 +1919,15 @@ function AgentWidget({
1890
1919
  return;
1891
1920
  setInput("");
1892
1921
  setReferences([]);
1922
+ setActiveReferenceSearch(undefined);
1893
1923
  setReferencePickerOpen(false);
1894
- onSubmit({
1924
+ const messageReferences = references.length > 0 ? references.map(({ label, resource }) => ({ label, resource })) : undefined;
1925
+ const action = {
1895
1926
  type: "message",
1896
1927
  text,
1897
- ...references.length > 0 ? {
1898
- references: references.map(({ label, resource }) => ({
1899
- label,
1900
- resource
1901
- }))
1902
- } : {}
1903
- });
1928
+ references: messageReferences
1929
+ };
1930
+ onSubmit(action);
1904
1931
  };
1905
1932
  const respondToApproval = (tool, approved) => {
1906
1933
  if (!tool.approvalId || state.pending)
@@ -1913,15 +1940,24 @@ function AgentWidget({
1913
1940
  });
1914
1941
  };
1915
1942
  const selectReference = (reference) => {
1943
+ if (!activeReferenceSearch)
1944
+ return;
1945
+ const replacement = insertReferenceMention(input, activeReferenceSearch, reference.label);
1916
1946
  setReferences((current) => [...current, reference]);
1917
- setInput((current) => current.replace(/@[^@\n]*$/, `@${reference.label}`));
1947
+ setInput(replacement.input);
1948
+ setActiveReferenceSearch(undefined);
1918
1949
  setReferencePickerOpen(false);
1950
+ requestAnimationFrame(() => {
1951
+ inputRef.current?.focus();
1952
+ inputRef.current?.setSelectionRange(replacement.cursor, replacement.cursor);
1953
+ });
1919
1954
  };
1920
1955
  const clearConversation = () => {
1921
1956
  onInterrupt();
1922
1957
  onReset();
1923
1958
  setInput("");
1924
1959
  setReferences([]);
1960
+ setActiveReferenceSearch(undefined);
1925
1961
  setReferencePickerOpen(false);
1926
1962
  };
1927
1963
  const handleOpenChange = (nextOpen) => {
@@ -2115,6 +2151,7 @@ function AgentWidget({
2115
2151
  /* @__PURE__ */ jsx17(PopoverTrigger, {
2116
2152
  id: referenceInputId,
2117
2153
  render: /* @__PURE__ */ jsx17(InputGroupTextarea, {
2154
+ ref: inputRef,
2118
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",
2119
2156
  value: input,
2120
2157
  placeholder: labels.placeholder,
@@ -2133,11 +2170,12 @@ function AgentWidget({
2133
2170
  },
2134
2171
  onChange: (event) => {
2135
2172
  const value = event.target.value;
2173
+ const candidate = referenceSearchAtCursor(value, event.currentTarget.selectionStart);
2174
+ const search = candidate && !completesSelectedReference(value, candidate, references) ? candidate : undefined;
2136
2175
  setInput(value);
2176
+ setActiveReferenceSearch(search);
2137
2177
  setReferences((current) => current.filter(({ label }) => hasReferenceMention(value, label)));
2138
- const query = referenceSearchQuery(value);
2139
- const startsReferenceQuery = query !== undefined && value.lastIndexOf("@") > input.lastIndexOf("@");
2140
- setReferencePickerOpen((current) => current || startsReferenceQuery && selectableReferences.length > 0);
2178
+ setReferencePickerOpen(search !== undefined && selectableReferences.length > 0);
2141
2179
  },
2142
2180
  onKeyDown: (event) => {
2143
2181
  if (event.key === "Escape" && referencePickerOpen) {
@@ -2179,7 +2217,7 @@ function AgentWidget({
2179
2217
  /* @__PURE__ */ jsx17(CommandEmpty, {
2180
2218
  children: labels.noReferences
2181
2219
  }),
2182
- /* @__PURE__ */ jsx17(CommandGroup, {
2220
+ matchingReferences.length > 0 ? /* @__PURE__ */ jsx17(CommandGroup, {
2183
2221
  heading: labels.references,
2184
2222
  children: matchingReferences.map((reference, index) => /* @__PURE__ */ jsxs5(CommandItem, {
2185
2223
  id: `${referenceInputId}-reference-${index}`,
@@ -2193,7 +2231,7 @@ function AgentWidget({
2193
2231
  })
2194
2232
  ]
2195
2233
  }, reference.key))
2196
- })
2234
+ }) : null
2197
2235
  ]
2198
2236
  })
2199
2237
  })
@@ -1,4 +1,4 @@
1
- import { Context, Effect, Layer, Stream } from "effect";
1
+ import { Context, Effect, Layer, Schema, Stream } from "effect";
2
2
  import { LanguageModel, Tool, Toolkit } from "effect/unstable/ai";
3
3
  import type { AgentAction } from "./schema.js";
4
4
  export type AgentStreamOptions<Tools extends Record<string, Tool.Any>> = {
@@ -13,41 +13,41 @@ declare const AgentHistoryError_base: new <A extends Record<string, any> = {}>(a
13
13
  declare class AgentHistoryError extends AgentHistoryError_base {
14
14
  }
15
15
  declare const AgentService_base: Context.ServiceClass<AgentService, "AgentService", {
16
- stream: <Tools extends Record<string, Tool.Any>>(args_0: AgentStreamOptions<Tools>) => Effect.Effect<Stream.Stream<import("effect/Schema").Struct.ReadonlySide<{
17
- readonly type: import("effect/Schema").Literal<"message-start">;
18
- readonly messageId: import("effect/Schema").String;
19
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
20
- readonly type: import("effect/Schema").Literal<"text-delta">;
21
- readonly messageId: import("effect/Schema").String;
22
- readonly delta: import("effect/Schema").String;
23
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
24
- readonly type: import("effect/Schema").Literal<"tool-call">;
25
- readonly messageId: import("effect/Schema").String;
26
- readonly toolCallId: import("effect/Schema").String;
27
- readonly name: import("effect/Schema").String;
28
- readonly input: import("effect/Schema").Unknown;
29
- readonly metadata: import("effect/Schema").Struct<{
30
- readonly title: import("effect/Schema").optional<import("effect/Schema").String>;
31
- readonly description: import("effect/Schema").optional<import("effect/Schema").String>;
32
- readonly destructive: import("effect/Schema").Boolean;
16
+ stream: <Tools extends Record<string, Tool.Any>>(args_0: AgentStreamOptions<Tools>) => Effect.Effect<Stream.Stream<Schema.Struct.ReadonlySide<{
17
+ readonly type: Schema.Literal<"message-start">;
18
+ readonly messageId: Schema.String;
19
+ }, "Type"> | Schema.Struct.ReadonlySide<{
20
+ readonly type: Schema.Literal<"text-delta">;
21
+ readonly messageId: Schema.String;
22
+ readonly delta: Schema.String;
23
+ }, "Type"> | Schema.Struct.ReadonlySide<{
24
+ readonly type: Schema.Literal<"tool-call">;
25
+ readonly messageId: Schema.String;
26
+ readonly toolCallId: Schema.String;
27
+ readonly name: Schema.String;
28
+ readonly input: Schema.Unknown;
29
+ readonly metadata: Schema.Struct<{
30
+ readonly title: Schema.optional<Schema.String>;
31
+ readonly description: Schema.optional<Schema.String>;
32
+ readonly destructive: Schema.Boolean;
33
33
  }>;
34
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
35
- readonly type: import("effect/Schema").Literal<"tool-result">;
36
- readonly toolCallId: import("effect/Schema").String;
37
- readonly name: import("effect/Schema").String;
38
- readonly isFailure: import("effect/Schema").Boolean;
39
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
40
- readonly type: import("effect/Schema").Literal<"approval-required">;
41
- readonly approvalId: import("effect/Schema").String;
42
- readonly toolCallId: import("effect/Schema").String;
43
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
44
- readonly type: import("effect/Schema").Literal<"history">;
45
- readonly value: import("effect/Schema").String;
46
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
47
- readonly type: import("effect/Schema").Literal<"finish">;
48
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
49
- readonly type: import("effect/Schema").Literal<"error">;
50
- readonly code: import("effect/Schema").Literals<readonly ["unavailable", "invalid-request", "stream-failed"]>;
34
+ }, "Type"> | Schema.Struct.ReadonlySide<{
35
+ readonly type: Schema.Literal<"tool-result">;
36
+ readonly toolCallId: Schema.String;
37
+ readonly name: Schema.String;
38
+ readonly isFailure: Schema.Boolean;
39
+ }, "Type"> | Schema.Struct.ReadonlySide<{
40
+ readonly type: Schema.Literal<"approval-required">;
41
+ readonly approvalId: Schema.String;
42
+ readonly toolCallId: Schema.String;
43
+ }, "Type"> | Schema.Struct.ReadonlySide<{
44
+ readonly type: Schema.Literal<"history">;
45
+ readonly value: Schema.String;
46
+ }, "Type"> | Schema.Struct.ReadonlySide<{
47
+ readonly type: Schema.Literal<"finish">;
48
+ }, "Type"> | Schema.Struct.ReadonlySide<{
49
+ readonly type: Schema.Literal<"error">;
50
+ readonly code: Schema.Literals<readonly ["unavailable", "invalid-request", "stream-failed"]>;
51
51
  }, "Type"> | {
52
52
  type: "history";
53
53
  value: string;
@@ -56,44 +56,44 @@ declare const AgentService_base: Context.ServiceClass<AgentService, "AgentServic
56
56
  code: "stream-failed";
57
57
  } | {
58
58
  type: "finish";
59
- }, never, Exclude<Tool.HandlerServices<Tools[keyof Tools]>, LanguageModel.LanguageModel> | Exclude<Tool.ResultDecodingServices<Tools[keyof Tools]>, LanguageModel.LanguageModel>>, AgentHistoryError | import("effect/SchemaError").SchemaError, LanguageModel.LanguageModel>;
59
+ }, never, Exclude<Tool.HandlerServices<Tools[keyof Tools]>, LanguageModel.LanguageModel> | Exclude<Tool.ResultDecodingServices<Tools[keyof Tools]>, LanguageModel.LanguageModel>>, AgentHistoryError | Schema.SchemaError, LanguageModel.LanguageModel>;
60
60
  }> & {
61
61
  readonly make: Effect.Effect<{
62
- stream: <Tools extends Record<string, Tool.Any>>(args_0: AgentStreamOptions<Tools>) => Effect.Effect<Stream.Stream<import("effect/Schema").Struct.ReadonlySide<{
63
- readonly type: import("effect/Schema").Literal<"message-start">;
64
- readonly messageId: import("effect/Schema").String;
65
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
66
- readonly type: import("effect/Schema").Literal<"text-delta">;
67
- readonly messageId: import("effect/Schema").String;
68
- readonly delta: import("effect/Schema").String;
69
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
70
- readonly type: import("effect/Schema").Literal<"tool-call">;
71
- readonly messageId: import("effect/Schema").String;
72
- readonly toolCallId: import("effect/Schema").String;
73
- readonly name: import("effect/Schema").String;
74
- readonly input: import("effect/Schema").Unknown;
75
- readonly metadata: import("effect/Schema").Struct<{
76
- readonly title: import("effect/Schema").optional<import("effect/Schema").String>;
77
- readonly description: import("effect/Schema").optional<import("effect/Schema").String>;
78
- readonly destructive: import("effect/Schema").Boolean;
62
+ stream: <Tools extends Record<string, Tool.Any>>(args_0: AgentStreamOptions<Tools>) => Effect.Effect<Stream.Stream<Schema.Struct.ReadonlySide<{
63
+ readonly type: Schema.Literal<"message-start">;
64
+ readonly messageId: Schema.String;
65
+ }, "Type"> | Schema.Struct.ReadonlySide<{
66
+ readonly type: Schema.Literal<"text-delta">;
67
+ readonly messageId: Schema.String;
68
+ readonly delta: Schema.String;
69
+ }, "Type"> | Schema.Struct.ReadonlySide<{
70
+ readonly type: Schema.Literal<"tool-call">;
71
+ readonly messageId: Schema.String;
72
+ readonly toolCallId: Schema.String;
73
+ readonly name: Schema.String;
74
+ readonly input: Schema.Unknown;
75
+ readonly metadata: Schema.Struct<{
76
+ readonly title: Schema.optional<Schema.String>;
77
+ readonly description: Schema.optional<Schema.String>;
78
+ readonly destructive: Schema.Boolean;
79
79
  }>;
80
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
81
- readonly type: import("effect/Schema").Literal<"tool-result">;
82
- readonly toolCallId: import("effect/Schema").String;
83
- readonly name: import("effect/Schema").String;
84
- readonly isFailure: import("effect/Schema").Boolean;
85
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
86
- readonly type: import("effect/Schema").Literal<"approval-required">;
87
- readonly approvalId: import("effect/Schema").String;
88
- readonly toolCallId: import("effect/Schema").String;
89
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
90
- readonly type: import("effect/Schema").Literal<"history">;
91
- readonly value: import("effect/Schema").String;
92
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
93
- readonly type: import("effect/Schema").Literal<"finish">;
94
- }, "Type"> | import("effect/Schema").Struct.ReadonlySide<{
95
- readonly type: import("effect/Schema").Literal<"error">;
96
- readonly code: import("effect/Schema").Literals<readonly ["unavailable", "invalid-request", "stream-failed"]>;
80
+ }, "Type"> | Schema.Struct.ReadonlySide<{
81
+ readonly type: Schema.Literal<"tool-result">;
82
+ readonly toolCallId: Schema.String;
83
+ readonly name: Schema.String;
84
+ readonly isFailure: Schema.Boolean;
85
+ }, "Type"> | Schema.Struct.ReadonlySide<{
86
+ readonly type: Schema.Literal<"approval-required">;
87
+ readonly approvalId: Schema.String;
88
+ readonly toolCallId: Schema.String;
89
+ }, "Type"> | Schema.Struct.ReadonlySide<{
90
+ readonly type: Schema.Literal<"history">;
91
+ readonly value: Schema.String;
92
+ }, "Type"> | Schema.Struct.ReadonlySide<{
93
+ readonly type: Schema.Literal<"finish">;
94
+ }, "Type"> | Schema.Struct.ReadonlySide<{
95
+ readonly type: Schema.Literal<"error">;
96
+ readonly code: Schema.Literals<readonly ["unavailable", "invalid-request", "stream-failed"]>;
97
97
  }, "Type"> | {
98
98
  type: "history";
99
99
  value: string;
@@ -102,7 +102,7 @@ declare const AgentService_base: Context.ServiceClass<AgentService, "AgentServic
102
102
  code: "stream-failed";
103
103
  } | {
104
104
  type: "finish";
105
- }, never, Exclude<Tool.HandlerServices<Tools[keyof Tools]>, LanguageModel.LanguageModel> | Exclude<Tool.ResultDecodingServices<Tools[keyof Tools]>, LanguageModel.LanguageModel>>, AgentHistoryError | import("effect/SchemaError").SchemaError, LanguageModel.LanguageModel>;
105
+ }, never, Exclude<Tool.HandlerServices<Tools[keyof Tools]>, LanguageModel.LanguageModel> | Exclude<Tool.ResultDecodingServices<Tools[keyof Tools]>, LanguageModel.LanguageModel>>, AgentHistoryError | Schema.SchemaError, LanguageModel.LanguageModel>;
106
106
  }, never, never>;
107
107
  };
108
108
  export declare class AgentService extends AgentService_base {
@@ -1,5 +1,14 @@
1
1
  // ../../src/services/agent/index.ts
2
- import { Context, Data, Effect, Layer, Option, Ref, Stream } from "effect";
2
+ import {
3
+ Context,
4
+ Data,
5
+ Effect,
6
+ Layer,
7
+ Option,
8
+ Ref,
9
+ Schema,
10
+ Stream
11
+ } from "effect";
3
12
  import {
4
13
  Chat,
5
14
  LanguageModel,
@@ -9,23 +18,30 @@ import {
9
18
 
10
19
  class AgentHistoryError extends Data.TaggedError("AgentHistoryError") {
11
20
  }
21
+ var AgentStreamErrorDetails = Schema.Struct({
22
+ message: Schema.optional(Schema.String),
23
+ reason: Schema.optional(Schema.String),
24
+ status: Schema.optional(Schema.Number),
25
+ _tag: Schema.optional(Schema.String)
26
+ }).annotate({ identifier: "AgentStreamErrorDetails" });
27
+ var decodeAgentStreamErrorDetails = Schema.decodeUnknownOption(AgentStreamErrorDetails);
12
28
 
13
29
  class AgentService extends Context.Service()("AgentService", {
14
30
  make: Effect.gen(function* () {
15
31
  const streamErrorDetails = (error) => {
16
- if (!error || typeof error !== "object") {
32
+ const details = Option.getOrUndefined(decodeAgentStreamErrorDetails(error));
33
+ if (!details)
17
34
  return { error: String(error) };
18
- }
19
- const message = Reflect.get(error, "message");
20
- const reason = Reflect.get(error, "reason");
21
- const status = Reflect.get(error, "status");
22
- const tag = Reflect.get(error, "_tag");
23
- return {
24
- ...typeof message === "string" ? { message } : {},
25
- ...typeof reason === "string" ? { reason } : {},
26
- ...typeof status === "number" ? { status } : {},
27
- ...typeof tag === "string" ? { tag } : {}
28
- };
35
+ const result = {};
36
+ if (details.message)
37
+ result.message = details.message;
38
+ if (details.reason)
39
+ result.reason = details.reason;
40
+ if (details.status !== undefined)
41
+ result.status = details.status;
42
+ if (details._tag)
43
+ result.tag = details._tag;
44
+ return result;
29
45
  };
30
46
  const eventsForPart = ({
31
47
  messageId,
@@ -45,11 +61,14 @@ class AgentService extends Context.Service()("AgentService", {
45
61
  toolCallId: part.id,
46
62
  name: part.name,
47
63
  input: part.params,
48
- metadata: {
49
- ...title ? { title } : {},
50
- ...tool?.description ? { description: tool.description } : {},
51
- destructive: tool ? Context.get(tool.annotations, Tool.Destructive) : false
52
- }
64
+ metadata: (() => {
65
+ const metadata = {
66
+ destructive: tool ? Context.get(tool.annotations, Tool.Destructive) : false,
67
+ title,
68
+ description: tool?.description
69
+ };
70
+ return metadata;
71
+ })()
53
72
  }
54
73
  ];
55
74
  }
@@ -120,7 +139,7 @@ class AgentService extends Context.Service()("AgentService", {
120
139
  const resolvedToolCallIds = new Set;
121
140
  for (const message of history.content) {
122
141
  for (const part of message.content) {
123
- if (typeof part === "string")
142
+ if (Schema.is(Schema.String)(part))
124
143
  continue;
125
144
  if (part.type === "tool-approval-request" && part.approvalId === action.approvalId) {
126
145
  pendingToolCallId = part.toolCallId;
@@ -1,22 +1,24 @@
1
1
  import { Context, Effect, Layer } from "effect";
2
+ import type { Json } from "effect/Schema";
2
3
  import { NotificationSendError } from "../schema.js";
3
4
  export interface NotificationChannels {
4
5
  }
5
- export type NotificationMessage = keyof NotificationChannels extends never ? Record<string, unknown> : Partial<{
6
+ export type NotificationMessage<FallbackPayload = Json> = keyof NotificationChannels extends never ? Record<string, FallbackPayload> : Partial<{
6
7
  readonly [Key in keyof NotificationChannels]: NotificationChannels[Key];
7
8
  }>;
8
- export interface NotificationChannelShape<Key extends string = string, Payload = unknown> {
9
+ export interface NotificationChannel<Key extends string = string, Payload = Json> {
9
10
  readonly key: Key;
10
- readonly send: (payload: unknown, message: NotificationMessage) => Effect.Effect<void, NotificationSendError>;
11
+ readonly send: (payload: Payload, message: NotificationMessage) => Effect.Effect<void, NotificationSendError>;
11
12
  readonly payload?: Payload;
12
13
  }
13
- export interface NotificationChannelRegistryShape {
14
- readonly channels: ReadonlyArray<NotificationChannelShape>;
14
+ export interface NotificationChannelRegistryService {
15
+ readonly channels: ReadonlyArray<NotificationChannel>;
15
16
  }
16
- declare const NotificationChannelRegistry_base: Context.ServiceClass<NotificationChannelRegistry, "NotificationChannelRegistry", NotificationChannelRegistryShape>;
17
+ /** @deprecated Use the domain-owned names without the Shape suffix. */
18
+ export { type NotificationChannel as NotificationChannelShape, type NotificationChannelRegistryService as NotificationChannelRegistryShape, };
19
+ declare const NotificationChannelRegistry_base: Context.ServiceClass<NotificationChannelRegistry, "NotificationChannelRegistry", NotificationChannelRegistryService>;
17
20
  export declare class NotificationChannelRegistry extends NotificationChannelRegistry_base {
18
- static readonly make: (...channels: ReadonlyArray<NotificationChannelShape>) => NotificationChannelRegistryShape;
19
- static readonly layer: (channels: ReadonlyArray<NotificationChannelShape>) => Layer.Layer<NotificationChannelRegistry, never, never>;
21
+ static readonly make: (...channels: ReadonlyArray<NotificationChannel>) => NotificationChannelRegistryService;
22
+ static readonly layer: (channels: ReadonlyArray<NotificationChannel>) => Layer.Layer<NotificationChannelRegistry, never, never>;
20
23
  static readonly emptyLayer: Layer.Layer<NotificationChannelRegistry, never, never>;
21
24
  }
22
- export {};