@fraqjs/fraq 0.9.2 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -5529,7 +5529,7 @@ interface SessionReplyOptions {
5529
5529
  interface Session {
5530
5530
  raw: IncomingMessage;
5531
5531
  reply(
5532
- segments: OutgoingSegment_ZodInput[],
5532
+ textOrSegments: string | OutgoingSegment_ZodInput[],
5533
5533
  options?: SessionReplyOptions,
5534
5534
  ): Promise<{
5535
5535
  messageSeq: number;
package/dist/index.mjs CHANGED
@@ -617,7 +617,7 @@ var Context = class Context {
617
617
  eventBus = mitt();
618
618
  plugins = [];
619
619
  services = /* @__PURE__ */ new Map();
620
- subContexts = [];
620
+ subContexts = /* @__PURE__ */ new Map();
621
621
  parentEventForwarder;
622
622
  timers = /* @__PURE__ */ new Set();
623
623
  initialReconnectDelayMs;
@@ -636,7 +636,7 @@ var Context = class Context {
636
636
  this.maxReconnectDelayMs = options?.reconnect?.maxDelayMs ?? DEFAULT_MAX_RECONNECT_DELAY_MS;
637
637
  this.logHandler = options?.logHandler ?? parent?.logHandler;
638
638
  this.name = name ?? "root";
639
- this.logger = new Logger((message) => this.logHandler?.(message), this.name);
639
+ this.logger = new Logger((message) => this.logHandler?.(message), `context:${this.name}`);
640
640
  this.parent = parent;
641
641
  this.filter = filter;
642
642
  if (parent) {
@@ -700,8 +700,12 @@ and implement the dispose method to clean up resources when the context stops.
700
700
  return this.tryResolve(service) !== void 0;
701
701
  }
702
702
  fork(name, filter) {
703
+ if (this.subContexts.has(name)) {
704
+ if (filter) throw new Error(`Sub context "${name}" already exists, so the provided filter cannot be applied. Please use fork('${name}') without a filter to get the existing subcontext.`);
705
+ return this.subContexts.get(name);
706
+ }
703
707
  const subContext = new Context(this.client, void 0, name, this, filter);
704
- this.subContexts.push(subContext);
708
+ this.subContexts.set(name, subContext);
705
709
  return subContext;
706
710
  }
707
711
  timeout(delayMs, callback) {
@@ -724,8 +728,13 @@ and implement the dispose method to clean up resources when the context stops.
724
728
  createSession(message) {
725
729
  return {
726
730
  raw: message,
727
- reply: async (segments, options) => {
728
- const actualSegments = [...segments];
731
+ reply: async (textOrSegments, options) => {
732
+ const actualSegments = [];
733
+ if (typeof textOrSegments === "string") actualSegments.push({
734
+ type: "text",
735
+ data: { text: textOrSegments }
736
+ });
737
+ else actualSegments.push(...textOrSegments);
729
738
  if (options?.withMention && message.message_scene === "group") actualSegments.unshift(seg.mention(message.sender_id));
730
739
  if (options?.withQuote) actualSegments.unshift(seg.reply(message.message_seq));
731
740
  switch (message.message_scene) {
@@ -809,7 +818,7 @@ and implement the dispose method to clean up resources when the context stops.
809
818
  async stopInternal() {
810
819
  const errors = [];
811
820
  this.clearTimers();
812
- for (const subContext of [...this.subContexts].reverse()) try {
821
+ for (const subContext of [...this.subContexts.values()].reverse()) try {
813
822
  await subContext.stop();
814
823
  } catch (error) {
815
824
  errors.push(error);
@@ -897,7 +906,7 @@ and implement the dispose method to clean up resources when the context stops.
897
906
  context: this,
898
907
  sortedPlugins
899
908
  });
900
- for (const subContext of this.subContexts) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
909
+ for (const subContext of this.subContexts.values()) await subContext.recursiveApplyPlugins(appliedContextPlugins, startingContexts);
901
910
  }
902
911
  async startPlugins(sortedPlugins) {
903
912
  for (const installedPlugin of sortedPlugins) {
@@ -974,7 +983,7 @@ and implement the dispose method to clean up resources when the context stops.
974
983
  return installedPlugin.proxy;
975
984
  }
976
985
  createProxyContextForPlugin(plugin) {
977
- const proxyLogger = new Logger((message) => this.logHandler?.(message), plugin.name);
986
+ const proxyLogger = new Logger((message) => this.logHandler?.(message), `plugin:${this.name ? `${this.name}/` : ""}${plugin.name}`);
978
987
  let proxyInjections;
979
988
  if (plugin.inject) {
980
989
  proxyInjections = {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraqjs/fraq",
3
3
  "type": "module",
4
- "version": "0.9.2",
4
+ "version": "0.10.1",
5
5
  "description": "Milky Bot framework",
6
6
  "files": [
7
7
  "dist"