graphmind 0.6.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +39 -0
- data/LICENSE +21 -0
- data/README.md +464 -0
- data/lib/graphmind/api.rb +267 -0
- data/lib/graphmind/clock.rb +49 -0
- data/lib/graphmind/edit_guard.rb +87 -0
- data/lib/graphmind/env.rb +83 -0
- data/lib/graphmind/errors.rb +40 -0
- data/lib/graphmind/gate_engine.rb +282 -0
- data/lib/graphmind/held_ledger.rb +209 -0
- data/lib/graphmind/ids.rb +52 -0
- data/lib/graphmind/integrations/ruby_llm.rb +449 -0
- data/lib/graphmind/integrations/ruby_openai.rb +388 -0
- data/lib/graphmind/integrations/support.rb +459 -0
- data/lib/graphmind/jack.rb +201 -0
- data/lib/graphmind/loop_guard.rb +516 -0
- data/lib/graphmind/protocol.rb +123 -0
- data/lib/graphmind/railtie.rb +66 -0
- data/lib/graphmind/redaction.rb +781 -0
- data/lib/graphmind/ring_buffer.rb +75 -0
- data/lib/graphmind/runtime.rb +50 -0
- data/lib/graphmind/safe.rb +48 -0
- data/lib/graphmind/session.rb +1180 -0
- data/lib/graphmind/shrink.rb +787 -0
- data/lib/graphmind/token_batcher.rb +84 -0
- data/lib/graphmind/transport.rb +331 -0
- data/lib/graphmind/version.rb +5 -0
- data/lib/graphmind/websocket.rb +448 -0
- data/lib/graphmind/wrap.rb +295 -0
- data/lib/graphmind.rb +54 -0
- metadata +83 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/railtie"
|
|
4
|
+
require "active_support/ordered_options"
|
|
5
|
+
|
|
6
|
+
module Graphmind
|
|
7
|
+
# A deliberately small Railtie. It does three things a plain initializer
|
|
8
|
+
# cannot do as well:
|
|
9
|
+
#
|
|
10
|
+
# 1. names the app after the Rails application, so the viewer shows
|
|
11
|
+
# "shopify-support" instead of "ruby";
|
|
12
|
+
# 2. clears the thread's run context when Rails finishes a unit of work.
|
|
13
|
+
# Puma reuses threads, so a run left behind by a request that died
|
|
14
|
+
# mid-flight would otherwise adopt the *next* request's events;
|
|
15
|
+
# 3. releases held gates and closes the socket on shutdown.
|
|
16
|
+
#
|
|
17
|
+
# Configure it from `config/application.rb` or an initializer:
|
|
18
|
+
#
|
|
19
|
+
# config.graphmind.enabled = Rails.env.development?
|
|
20
|
+
# config.graphmind.app = "support-agent"
|
|
21
|
+
# config.graphmind.url = "ws://127.0.0.1:4747/ingest"
|
|
22
|
+
#
|
|
23
|
+
# Every key is passed straight to Graphmind.configure. Setting
|
|
24
|
+
# `config.graphmind.autoconfigure = false` leaves everything to you.
|
|
25
|
+
class Railtie < ::Rails::Railtie
|
|
26
|
+
config.graphmind = ActiveSupport::OrderedOptions.new if defined?(ActiveSupport::OrderedOptions)
|
|
27
|
+
|
|
28
|
+
initializer "graphmind.configure" do |app|
|
|
29
|
+
options = app.config.respond_to?(:graphmind) ? app.config.graphmind : nil
|
|
30
|
+
next if options.nil?
|
|
31
|
+
next if options[:autoconfigure] == false
|
|
32
|
+
|
|
33
|
+
settings = options.to_h.reject { |key, _| key == :autoconfigure }
|
|
34
|
+
settings[:app] ||= app.class.name.to_s.split("::").first.to_s.downcase
|
|
35
|
+
next if Graphmind.configured?
|
|
36
|
+
|
|
37
|
+
begin
|
|
38
|
+
Graphmind.configure(**settings)
|
|
39
|
+
rescue StandardError => e
|
|
40
|
+
# A debugger must never take an application down at boot. A typo in
|
|
41
|
+
# config.graphmind is a warning, not a failed deploy.
|
|
42
|
+
warn "[graphmind] ignoring config.graphmind (#{e.class}: #{e.message}); " \
|
|
43
|
+
"GraphMind will use its defaults"
|
|
44
|
+
Graphmind.configure(app: settings[:app]) unless Graphmind.configured?
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
initializer "graphmind.executor" do |app|
|
|
49
|
+
# `to_complete` runs after every request, job or console block — the
|
|
50
|
+
# right place to drop a thread-local that must not outlive it.
|
|
51
|
+
app.executor.to_complete do
|
|
52
|
+
Graphmind.clear_run_context if Graphmind.configured?
|
|
53
|
+
rescue StandardError
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
config.after_initialize do
|
|
59
|
+
at_exit do
|
|
60
|
+
Graphmind.dispose if Graphmind.configured?
|
|
61
|
+
rescue StandardError
|
|
62
|
+
nil
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|