prescient 0.6.0 → 0.8.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +21 -268
  3. data/CHANGELOG.md +59 -0
  4. data/INTEGRATION_GUIDE.md +19 -1
  5. data/README.md +369 -21
  6. data/Steepfile +12 -12
  7. data/db/migrate/001_create_prescient_tables.rb +15 -16
  8. data/docker-compose.yml +22 -0
  9. data/examples/README.md +36 -1
  10. data/examples/custom_contexts.rb +4 -4
  11. data/examples/web_search.rb +34 -0
  12. data/exe/prescient +2 -2
  13. data/exe/prescient-mcp +7 -0
  14. data/lib/prescient/agent/audit_log.rb +37 -0
  15. data/lib/prescient/agent/cli_adapter.rb +29 -0
  16. data/lib/prescient/agent/configuration.rb +57 -0
  17. data/lib/prescient/agent/context.rb +56 -0
  18. data/lib/prescient/agent/error_serializer.rb +47 -0
  19. data/lib/prescient/agent/errors.rb +25 -0
  20. data/lib/prescient/agent/parser.rb +49 -0
  21. data/lib/prescient/agent/prompt_builder.rb +31 -0
  22. data/lib/prescient/agent/result.rb +36 -0
  23. data/lib/prescient/agent/runtime.rb +175 -0
  24. data/lib/prescient/agent/schema_validator.rb +215 -0
  25. data/lib/prescient/agent/tool_registry.rb +89 -0
  26. data/lib/prescient/agent.rb +22 -0
  27. data/lib/prescient/api.rb +346 -231
  28. data/lib/prescient/base.rb +370 -372
  29. data/lib/prescient/cli.rb +591 -402
  30. data/lib/prescient/client.rb +31 -4
  31. data/lib/prescient/configuration_loader.rb +511 -336
  32. data/lib/prescient/document_source.rb +114 -0
  33. data/lib/prescient/errors.rb +13 -3
  34. data/lib/prescient/mcp/authentication.rb +39 -0
  35. data/lib/prescient/mcp/configuration.rb +38 -0
  36. data/lib/prescient/mcp/rack.rb +243 -0
  37. data/lib/prescient/mcp/server.rb +202 -0
  38. data/lib/prescient/mcp/stdio.rb +42 -0
  39. data/lib/prescient/mcp.rb +8 -0
  40. data/lib/prescient/pgvector.rb +193 -189
  41. data/lib/prescient/provider/anthropic.rb +129 -125
  42. data/lib/prescient/provider/deepseek.rb +122 -118
  43. data/lib/prescient/provider/gemini.rb +153 -149
  44. data/lib/prescient/provider/huggingface.rb +191 -187
  45. data/lib/prescient/provider/mistral.rb +151 -147
  46. data/lib/prescient/provider/ollama.rb +168 -165
  47. data/lib/prescient/provider/openai.rb +174 -171
  48. data/lib/prescient/provider/xai.rb +122 -118
  49. data/lib/prescient/tool/search_api.rb +130 -0
  50. data/lib/prescient/tool/searxng.rb +128 -0
  51. data/lib/prescient/tool.rb +125 -0
  52. data/lib/prescient/version.rb +1 -1
  53. data/lib/prescient.rb +129 -55
  54. data/schema/prescient.configuration.schema.json +119 -0
  55. data/searxng/settings.yml +18 -0
  56. data/sig/prescient.rbs +228 -1
  57. metadata +33 -5
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Main Prescient module for AI provider abstraction
3
4
  module Prescient
4
5
  # Client class for interacting with AI providers
5
6
  #
@@ -104,10 +105,10 @@ module Prescient
104
105
  # and recursively sanitized :options
105
106
  def provider_info
106
107
  {
107
- name: @provider_name,
108
- class: @provider.class.name.split('::').last,
108
+ name: @provider_name,
109
+ class: @provider.class.name.split("::").last,
109
110
  available: available?,
110
- options: sanitize_options(@provider.options),
111
+ options: sanitize_options(@provider.options)
111
112
  }
112
113
  end
113
114
 
@@ -210,7 +211,7 @@ module Prescient
210
211
  Prescient::ConnectionError,
211
212
  Prescient::RateLimitError,
212
213
  Prescient::ModelNotAvailableError,
213
- Prescient::ProviderError,
214
+ Prescient::ProviderError
214
215
  ].any? { |error_class| error.is_a?(error_class) }
215
216
  end
216
217
  end
@@ -247,6 +248,32 @@ module Prescient
247
248
  client(provider, enable_fallback: enable_fallback).generate_response(prompt, context_items, **options)
248
249
  end
249
250
 
251
+ # Search with an explicit external tool and optionally use the normalized
252
+ # results as context for a configured AI provider.
253
+ #
254
+ # @param query [String] Search query and generation prompt
255
+ # @param tool [Symbol, String] Configured external tool name
256
+ # @param provider [Symbol, nil] Provider to use for generation
257
+ # @param limit [Integer, nil] Maximum number of search results
258
+ # @param enable_fallback [Boolean] Whether provider fallback is enabled
259
+ # @param provider_options [Hash] Temporary provider configuration overrides
260
+ # @return [Hash] Normalized provider response
261
+ def self.search_and_generate(query, tool: :web_search, provider: nil, limit: nil,
262
+ enable_fallback: true, provider_options: {}, **options)
263
+ search_tool = self.tool(tool)
264
+ raise Prescient::ToolConfigurationError, "tool not configured: #{tool}" unless search_tool
265
+
266
+ search_result = search_tool.search(query, limit: limit)
267
+ context_items = search_result[:results]
268
+ raise Prescient::ToolInvalidResponseError, "tool results must be an array" unless context_items.is_a?(Array)
269
+
270
+ client(provider, enable_fallback:, provider_options:).generate_response(
271
+ query,
272
+ context_items,
273
+ **options
274
+ )
275
+ end
276
+
250
277
  # Return the health status of a configured provider.
251
278
  #
252
279
  # @param provider [Symbol, nil] Provider to check