liminal 0.9.0 → 0.11.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 (100) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/L.ts +14 -81
  3. package/LEvent.ts +23 -0
  4. package/Sequence.ts +14 -0
  5. package/Strand.ts +19 -41
  6. package/append.ts +13 -0
  7. package/assistant.ts +23 -0
  8. package/assistantStruct.ts +34 -0
  9. package/branch.ts +26 -0
  10. package/clear.ts +15 -0
  11. package/dist/L.d.ts +14 -15
  12. package/dist/L.js +14 -56
  13. package/dist/L.js.map +1 -1
  14. package/dist/LEvent.d.ts +26 -0
  15. package/dist/LEvent.js +16 -0
  16. package/dist/LEvent.js.map +1 -0
  17. package/dist/Sequence.d.ts +2 -0
  18. package/dist/Sequence.js +2 -0
  19. package/dist/Sequence.js.map +1 -0
  20. package/dist/Strand.d.ts +20 -20
  21. package/dist/Strand.js +3 -19
  22. package/dist/Strand.js.map +1 -1
  23. package/dist/append.d.ts +5 -0
  24. package/dist/append.js +11 -0
  25. package/dist/append.js.map +1 -0
  26. package/dist/assistant.d.ts +6 -0
  27. package/dist/assistant.js +20 -0
  28. package/dist/assistant.js.map +1 -0
  29. package/dist/assistantStruct.d.ts +12 -0
  30. package/dist/assistantStruct.js +22 -0
  31. package/dist/assistantStruct.js.map +1 -0
  32. package/dist/branch.d.ts +4 -0
  33. package/dist/branch.js +18 -0
  34. package/dist/branch.js.map +1 -0
  35. package/dist/clear.d.ts +5 -0
  36. package/dist/clear.js +15 -0
  37. package/dist/clear.js.map +1 -0
  38. package/dist/events.d.ts +5 -0
  39. package/dist/events.js +6 -0
  40. package/dist/events.js.map +1 -0
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.js +3 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/internal/JsonValue.d.ts +5 -0
  45. package/dist/internal/JsonValue.js +2 -0
  46. package/dist/internal/JsonValue.js.map +1 -0
  47. package/dist/internal/Taggable.d.ts +11 -0
  48. package/dist/internal/Taggable.js +2 -0
  49. package/dist/internal/Taggable.js.map +1 -0
  50. package/dist/messages.d.ts +5 -0
  51. package/dist/messages.js +5 -0
  52. package/dist/messages.js.map +1 -0
  53. package/dist/pretty.d.ts +2 -0
  54. package/dist/pretty.js +37 -0
  55. package/dist/pretty.js.map +1 -0
  56. package/dist/reduce.d.ts +4 -0
  57. package/dist/reduce.js +20 -0
  58. package/dist/reduce.js.map +1 -0
  59. package/dist/sequence_.d.ts +2 -0
  60. package/dist/sequence_.js +5 -0
  61. package/dist/sequence_.js.map +1 -0
  62. package/dist/strand_.d.ts +4 -0
  63. package/dist/strand_.js +18 -0
  64. package/dist/strand_.js.map +1 -0
  65. package/dist/system.d.ts +5 -0
  66. package/dist/system.js +11 -0
  67. package/dist/system.js.map +1 -0
  68. package/dist/tsconfig.tsbuildinfo +1 -1
  69. package/dist/user.d.ts +5 -0
  70. package/dist/user.js +14 -0
  71. package/dist/user.js.map +1 -0
  72. package/dist/userJson.d.ts +6 -0
  73. package/dist/userJson.js +8 -0
  74. package/dist/userJson.js.map +1 -0
  75. package/events.ts +9 -0
  76. package/index.ts +3 -1
  77. package/internal/JsonValue.ts +5 -0
  78. package/internal/Taggable.ts +17 -0
  79. package/messages.ts +9 -0
  80. package/package.json +10 -6
  81. package/pretty.ts +41 -0
  82. package/reduce.ts +32 -0
  83. package/sequence_.ts +9 -0
  84. package/strand_.ts +25 -0
  85. package/system.ts +13 -0
  86. package/tsconfig.json +11 -1
  87. package/user.ts +17 -0
  88. package/userJson.ts +12 -0
  89. package/dist/util/JSONValue.d.ts +0 -5
  90. package/dist/util/JSONValue.js +0 -2
  91. package/dist/util/JSONValue.js.map +0 -1
  92. package/dist/util/fixTemplateStrings.d.ts +0 -11
  93. package/dist/util/fixTemplateStrings.js +0 -83
  94. package/dist/util/fixTemplateStrings.js.map +0 -1
  95. package/dist/util/isTemplateStringsArray.d.ts +0 -1
  96. package/dist/util/isTemplateStringsArray.js +0 -4
  97. package/dist/util/isTemplateStringsArray.js.map +0 -1
  98. package/util/JSONValue.ts +0 -5
  99. package/util/fixTemplateStrings.ts +0 -99
  100. package/util/isTemplateStringsArray.ts +0 -3
@@ -0,0 +1,20 @@
1
+ import { AssistantMessage, TextPart } from "@effect/ai/AiInput";
2
+ import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Option from "effect/Option";
5
+ import { append } from "./append.js";
6
+ import { Strand } from "./Strand.js";
7
+ /** Infer an assistant message and append it to the conversation. */
8
+ export const assistant = Effect.gen(function* () {
9
+ const model = yield* AiLanguageModel;
10
+ const { system, messages } = yield* Strand;
11
+ const { text } = yield* model.generateText({
12
+ system: Option.getOrUndefined(system),
13
+ prompt: messages,
14
+ });
15
+ yield* append(new AssistantMessage({
16
+ parts: [new TextPart({ text })],
17
+ }));
18
+ return text;
19
+ });
20
+ //# sourceMappingURL=assistant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant.js","sourceRoot":"","sources":["../assistant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,oEAAoE;AACpE,MAAM,CAAC,MAAM,SAAS,GAA6D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrG,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,eAAe,CAAA;IACpC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC1C,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC;QACzC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;QACrC,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAA;IACF,KAAK,CAAC,CAAC,MAAM,CACX,IAAI,gBAAgB,CAAC;QACnB,KAAK,EAAE,CAAC,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KAChC,CAAC,CACH,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { AiError } from "@effect/ai/AiError";
2
+ import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
5
+ import { Strand } from "./Strand.ts";
6
+ /** Infer a structured assistant message and append its JSON representation to the conversation. */
7
+ export declare const assistantStruct: {
8
+ <F extends Record<string, Schema.Schema.AnyNoContext>>(fields: F): Effect.Effect<{
9
+ [K in keyof F]: Schema.Schema.Type<F[K]>;
10
+ }, AiError, AiLanguageModel | Strand>;
11
+ <O, I extends Record<string, unknown>>(schema: Schema.Schema<O, I, never>): Effect.Effect<O, AiError, AiLanguageModel | Strand>;
12
+ };
@@ -0,0 +1,22 @@
1
+ import { AssistantMessage, TextPart } from "@effect/ai/AiInput";
2
+ import { AiLanguageModel } from "@effect/ai/AiLanguageModel";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Option from "effect/Option";
5
+ import * as Schema from "effect/Schema";
6
+ import { append } from "./append.js";
7
+ import { Strand } from "./Strand.js";
8
+ /** Infer a structured assistant message and append its JSON representation to the conversation. */
9
+ export const assistantStruct = Effect.fnUntraced(function* (schema) {
10
+ const model = yield* AiLanguageModel;
11
+ const { system, messages } = yield* Strand;
12
+ const { value, text } = yield* model.generateObject({
13
+ system: Option.getOrUndefined(system),
14
+ schema: Schema.isSchema(schema) ? schema : Schema.Struct(schema),
15
+ prompt: messages,
16
+ });
17
+ yield* append(new AssistantMessage({
18
+ parts: [new TextPart({ text })],
19
+ }));
20
+ return value;
21
+ });
22
+ //# sourceMappingURL=assistantStruct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistantStruct.js","sourceRoot":"","sources":["../assistantStruct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,mGAAmG;AACnG,MAAM,CAAC,MAAM,eAAe,GAOxB,MAAM,CAAC,UAAU,CACnB,QAAQ,CAAC,EAAC,MAAM;IACd,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,eAAe,CAAA;IACpC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC1C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;QAClD,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;QACrC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAoC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9F,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAA;IACF,KAAK,CAAC,CAAC,MAAM,CACX,IAAI,gBAAgB,CAAC;QACnB,KAAK,EAAE,CAAC,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KAChC,CAAC,CACH,CAAA;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CACF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Sequence } from "./Sequence.ts";
2
+ import { Strand } from "./Strand.ts";
3
+ /** Isolate the effect with a new strand in context. */
4
+ export declare const branch: Sequence<never, Strand>;
package/dist/branch.js ADDED
@@ -0,0 +1,18 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { flow, identity } from "effect/Function";
3
+ import * as Option from "effect/Option";
4
+ import * as PubSub from "effect/PubSub";
5
+ import { sequence } from "./sequence_.js";
6
+ import { Strand } from "./Strand.js";
7
+ /** Isolate the effect with a new strand in context. */
8
+ export const branch = flow(sequence, Effect.provideServiceEffect(Strand, Effect.gen(function* () {
9
+ const parent = yield* Strand;
10
+ return Strand.of({
11
+ parent: Option.some(parent),
12
+ system: Option.map(parent.system, identity),
13
+ events: yield* PubSub.unbounded(),
14
+ messages: parent.messages.slice(),
15
+ tools: parent.tools.slice(),
16
+ });
17
+ })));
18
+ //# sourceMappingURL=branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branch.js","sourceRoot":"","sources":["../branch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,uDAAuD;AACvD,MAAM,CAAC,MAAM,MAAM,GAA4B,IAAI,CACjD,QAAQ,EACR,MAAM,CAAC,oBAAoB,CACzB,MAAM,EACN,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC5B,OAAO,MAAM,CAAC,EAAE,CAAC;QACf,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;QAC3C,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,EAAU;QACzC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE;QACjC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;KAC5B,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CACF,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { Message } from "@effect/ai/AiInput";
2
+ import * as Effect from "effect/Effect";
3
+ import { Strand } from "./Strand.ts";
4
+ /** Clear the strand's conversation. */
5
+ export declare const clear: Effect.Effect<Array<Message>, never, Strand>;
package/dist/clear.js ADDED
@@ -0,0 +1,15 @@
1
+ import { Message } from "@effect/ai/AiInput";
2
+ import * as Effect from "effect/Effect";
3
+ import { MessagesCleared } from "./LEvent.js";
4
+ import { Strand } from "./Strand.js";
5
+ /** Clear the strand's conversation. */
6
+ export const clear = Effect.gen(function* () {
7
+ const strand = yield* Strand;
8
+ const { messages, events } = strand;
9
+ strand.messages = [];
10
+ yield* events.publish(MessagesCleared.make({
11
+ cleared: messages,
12
+ }));
13
+ return messages;
14
+ });
15
+ //# sourceMappingURL=clear.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clear.js","sourceRoot":"","sources":["../clear.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,uCAAuC;AACvC,MAAM,CAAC,MAAM,KAAK,GAAiD,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrF,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC5B,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACnC,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAA;IACpB,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC;QACzC,OAAO,EAAE,QAAQ;KAClB,CAAC,CAAC,CAAA;IACH,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import * as Stream from "effect/Stream";
2
+ import type { LEvent } from "./LEvent";
3
+ import { Strand } from "./Strand.ts";
4
+ /** Get a new event stream of the events of the current strand. */
5
+ export declare const events: Stream.Stream<LEvent, never, Strand>;
package/dist/events.js ADDED
@@ -0,0 +1,6 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Stream from "effect/Stream";
3
+ import { Strand } from "./Strand.js";
4
+ /** Get a new event stream of the events of the current strand. */
5
+ export const events = Stream.unwrap(Effect.map(Strand, ({ events }) => Stream.fromPubSub(events)));
6
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,kEAAkE;AAClE,MAAM,CAAC,MAAM,MAAM,GAAyC,MAAM,CAAC,MAAM,CACvE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAC9D,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * as L from "./L.ts";
2
- export * as Strand from "./Strand.ts";
2
+ export * from "./LEvent.ts";
3
+ export * from "./pretty.ts";
4
+ export * from "./Strand.ts";
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export * as L from "./L.js";
2
- export * as Strand from "./Strand.js";
2
+ export * from "./LEvent.js";
3
+ export * from "./pretty.js";
4
+ export * from "./Strand.js";
3
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAA;AAC3B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,5 @@
1
+ export type JsonValue = null | boolean | number | string | JsonValueArray | JsonValueObject;
2
+ export type JsonValueArray = Array<JsonValue> | ReadonlyArray<JsonValue>;
3
+ export type JsonValueObject = {
4
+ [key: string]: JsonValue;
5
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=JsonValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonValue.js","sourceRoot":"","sources":["../../internal/JsonValue.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ export type Taggable<T> = {
2
+ (value: string): T;
3
+ (template: TemplateStringsArray, ...substitutions: Array<unknown>): T;
4
+ (template: string | TemplateStringsArray, ...substitutions: Array<unknown>): T;
5
+ };
6
+ export type TaggableNullable<T> = {
7
+ (value?: string | undefined): T;
8
+ (template: TemplateStringsArray, ...substitutions: Array<unknown>): T;
9
+ (template?: string | TemplateStringsArray | undefined, ...substitutions: Array<unknown>): T;
10
+ };
11
+ export declare const normalize: <A0 extends string | TemplateStringsArray | undefined>(a0: A0, aRest?: Array<unknown>) => string | (undefined extends A0 ? undefined : never);
@@ -0,0 +1,2 @@
1
+ export const normalize = (a0, aRest = []) => a0 ? typeof a0 === "string" ? a0 : String.raw(a0, aRest) : undefined;
2
+ //# sourceMappingURL=Taggable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Taggable.js","sourceRoot":"","sources":["../../internal/Taggable.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,EAAM,EACN,QAAwB,EAAE,EAC2B,EAAE,CACvD,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAkB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { Message } from "@effect/ai/AiInput";
2
+ import * as Effect from "effect/Effect";
3
+ import { Strand } from "./Strand.ts";
4
+ /** Get a copy of the current list of messages. */
5
+ export declare const messages: Effect.Effect<Array<Message>, never, Strand>;
@@ -0,0 +1,5 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { Strand } from "./Strand.js";
3
+ /** Get a copy of the current list of messages. */
4
+ export const messages = Effect.map(Strand, ({ messages: [...messages] }) => messages);
5
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,kDAAkD;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAiD,MAAM,CAAC,GAAG,CAC9E,MAAM,EACN,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAC1C,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { LEvent } from "./LEvent.ts";
2
+ export declare const pretty: (event: typeof LEvent["Type"]) => string;
package/dist/pretty.js ADDED
@@ -0,0 +1,37 @@
1
+ const GRAY = "\x1b[90m";
2
+ const RESET = "\x1b[0m";
3
+ const BOLD = "\x1b[1m";
4
+ const GRAY_BG = "\x1b[47m";
5
+ export const pretty = (event) => {
6
+ let text = `${GRAY}${event._tag}${RESET}`;
7
+ switch (event._tag) {
8
+ case "MessagesAppended": {
9
+ text += event.messages.map(formatMessage).join("\n");
10
+ break;
11
+ }
12
+ case "MessagesCleared": {
13
+ text += `\n${event.cleared.length} messages cleared.`;
14
+ break;
15
+ }
16
+ }
17
+ return text;
18
+ };
19
+ const formatMessage = ({ _tag, parts }) => {
20
+ let value = "";
21
+ for (const part of parts) {
22
+ value += `\n${BOLD}${_tag}\n${GRAY_BG}`;
23
+ switch (part._tag) {
24
+ case "TextPart": {
25
+ value += `${part.text}`;
26
+ break;
27
+ }
28
+ default: {
29
+ value += `${JSON.stringify(part, null, 2)}`;
30
+ break;
31
+ }
32
+ }
33
+ value += RESET;
34
+ }
35
+ return value;
36
+ };
37
+ //# sourceMappingURL=pretty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pretty.js","sourceRoot":"","sources":["../pretty.ts"],"names":[],"mappings":"AAGA,MAAM,IAAI,GAAG,UAAU,CAAA;AACvB,MAAM,KAAK,GAAG,SAAS,CAAA;AACvB,MAAM,IAAI,GAAG,SAAS,CAAA;AACtB,MAAM,OAAO,GAAG,UAAU,CAAA;AAE1B,MAAM,CAAC,MAAM,MAAM,GAA6C,CAAC,KAAK,EAAE,EAAE;IACxE,IAAI,IAAI,GAAG,GAAG,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,EAAE,CAAA;IACzC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACpD,MAAK;QACP,CAAC;QACD,KAAK,iBAAiB,CAAC,CAAC,CAAC;YACvB,IAAI,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,MAAM,oBAAoB,CAAA;YACrD,MAAK;QACP,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAW,EAAU,EAAE;IACzD,IAAI,KAAK,GAAG,EAAE,CAAA;IACd,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,OAAO,EAAE,CAAA;QACvC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,UAAU,CAAC,CAAC,CAAC;gBAChB,KAAK,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;gBACvB,MAAK;YACP,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,KAAK,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAA;gBAC3C,MAAK;YACP,CAAC;QACH,CAAC;QACD,KAAK,IAAI,KAAK,CAAA;IAChB,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { Strand } from "./Strand.ts";
3
+ /** Sequentially reduce the current strand's messages in chronological order. */
4
+ export declare const reduce: <E, R, E1, R1>(reducer: Effect.Effect<Effect.Effect<void, E1, R1>, E, R>) => Effect.Effect<void, E | E1, R | R1 | Strand>;
package/dist/reduce.js ADDED
@@ -0,0 +1,20 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { append } from "./append.js";
3
+ import { clear } from "./clear.js";
4
+ import { Strand } from "./Strand.js";
5
+ import { strand } from "./strand_.js";
6
+ /** Sequentially reduce the current strand's messages in chronological order. */
7
+ export const reduce = Effect.fnUntraced(function* (reducer) {
8
+ const parent = yield* Strand;
9
+ if (!parent.messages.length || parent.messages.length === 1)
10
+ return;
11
+ const [m0, m1, ...mRest] = parent.messages;
12
+ let acc = yield* strand(append(m0, m1), reducer);
13
+ while (mRest.length) {
14
+ acc = yield* strand(acc, append(mRest.pop()), reducer);
15
+ }
16
+ yield* clear;
17
+ yield* acc;
18
+ return;
19
+ });
20
+ //# sourceMappingURL=reduce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduce.js","sourceRoot":"","sources":["../reduce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,gFAAgF;AAChF,MAAM,CAAC,MAAM,MAAM,GAMf,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAC,OAAO;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAC5B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAM;IACnE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAA;IAC1C,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CACrB,MAAM,CAAC,EAAG,EAAE,EAAG,CAAC,EAChB,OAAO,CACR,CAAA;IACD,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QACpB,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CACjB,GAAG,EACH,MAAM,CAAC,KAAK,CAAC,GAAG,EAAG,CAAC,EACpB,OAAO,CACR,CAAA;IACH,CAAC;IACD,KAAK,CAAC,CAAC,KAAK,CAAA;IACZ,KAAK,CAAC,CAAC,GAAG,CAAA;IACV,OAAM;AACR,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { Sequence } from "./Sequence";
2
+ export declare const sequence: Sequence;
@@ -0,0 +1,5 @@
1
+ import * as Effect from "effect/Effect";
2
+ export const sequence = (...steps) => Effect.all(steps, {
3
+ concurrency: 1,
4
+ }).pipe(Effect.map((v) => v.pop()));
5
+ //# sourceMappingURL=sequence_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequence_.js","sourceRoot":"","sources":["../sequence_.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,MAAM,CAAC,MAAM,QAAQ,GAAa,CAAC,GAAG,KAAK,EAAE,EAAE,CAC7C,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE;IAChB,WAAW,EAAE,CAAC;CACf,CAAC,CAAC,IAAI,CACL,MAAM,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAG,CAAU,CACnD,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { type Sequence } from "./Sequence.ts";
2
+ import { Strand } from "./Strand.ts";
3
+ /** Isolate the effect with a new strand in context. */
4
+ export declare const strand: Sequence<Strand>;
@@ -0,0 +1,18 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { flow } from "effect/Function";
3
+ import * as Option from "effect/Option";
4
+ import * as PubSub from "effect/PubSub";
5
+ import {} from "./Sequence.js";
6
+ import { sequence } from "./sequence_.js";
7
+ import { Strand } from "./Strand.js";
8
+ /** Isolate the effect with a new strand in context. */
9
+ export const strand = flow(sequence, Effect.provideServiceEffect(Strand, Effect.gen(function* () {
10
+ return Strand.of({
11
+ parent: yield* Effect.serviceOption(Strand),
12
+ events: yield* PubSub.unbounded(),
13
+ system: Option.none(),
14
+ messages: [],
15
+ tools: [],
16
+ });
17
+ })));
18
+ //# sourceMappingURL=strand_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strand_.js","sourceRoot":"","sources":["../strand_.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAiB,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,uDAAuD;AACvD,MAAM,CAAC,MAAM,MAAM,GAAqB,IAAI,CAC1C,QAAQ,EACR,MAAM,CAAC,oBAAoB,CACzB,MAAM,EACN,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,OAAO,MAAM,CAAC,EAAE,CAAC;QACf,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC;QAC3C,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,EAAU;QACzC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE;QACrB,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;KACV,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CACF,CAAA"}
@@ -0,0 +1,5 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Option from "effect/Option";
3
+ import { type TaggableNullable } from "./internal/Taggable.ts";
4
+ import { Strand } from "./Strand.ts";
5
+ export declare const system: TaggableNullable<Effect.Effect<Option.Option<string>, never, Strand>>;
package/dist/system.js ADDED
@@ -0,0 +1,11 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Option from "effect/Option";
3
+ import { normalize } from "./internal/Taggable.js";
4
+ import { Strand } from "./Strand.js";
5
+ export const system = Effect.fnUntraced(function* (a0, ...aRest) {
6
+ const conversation = yield* Strand;
7
+ const { system } = conversation;
8
+ conversation.system = a0 ? Option.some(normalize(a0, aRest)) : Option.none();
9
+ return system;
10
+ });
11
+ //# sourceMappingURL=system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.js","sourceRoot":"","sources":["../system.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAyB,MAAM,wBAAwB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,CAAC,MAAM,MAAM,GAA0E,MAAM,CAAC,UAAU,CAC5G,QAAQ,CAAC,EAAC,EAAE,EAAE,GAAG,KAAK;IACpB,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,MAAM,CAAA;IAClC,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,CAAA;IAC/B,YAAY,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC5E,OAAO,MAAM,CAAA;AACf,CAAC,CACF,CAAA"}