lex-apollo 0.4.27 → 0.4.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85cccff520bb34332f705695f5193cd55e01bb94fb680bf0a51ad81a04ec3112
4
- data.tar.gz: b3370806ab160e71f3f213fb4401a6a45aa650778a29574b1cc553a9ad34d167
3
+ metadata.gz: d25745968940593d7d1ac3fba3f1ccd1b5d7ce553cca28c1a1fdfa4d3104af11
4
+ data.tar.gz: 96ecdae2a460625d95cbe0e4605f2c60778d035ea3c3f93e19d6560df0a40e70
5
5
  SHA512:
6
- metadata.gz: d45dd95922afbff6cf87391eca84b658359fc3b329f80cfd9404054e2e5fc7cff5b398d2b065f407ab9bff3141ba87b9f3d30e0c980e6c4625231edbf591bc18
7
- data.tar.gz: 47183b00644bae505cd55c1abad707c5c86d901a38472d186bb5601eb3ec4fa0d2452715a667b3f7ebd0081d00ccb3fc3d6d6fabab61e7d146fdb2890deca7f2
6
+ metadata.gz: c788a0ab4bd58e70ef2be2b7be88101bcccf4880fecd0ee4b8cd7a1be05cbe9b9e157c99fc7f5724a62a4d6fcdacf6278e8c902368fcc60324d966b204698b48
7
+ data.tar.gz: 1a51dc48ec715adc969325e82f1c7bd81e23b35f716c0ee6c3ded05a9d38eb0b57261121892658fb8715a969f7ab22f1a06664af17aa990dc0e708272229039e
@@ -85,10 +85,10 @@ module Legion
85
85
  def handle_ingest(content: nil, content_type: nil, tags: [], source_agent: 'unknown', # rubocop:disable Metrics/ParameterLists
86
86
  source_provider: nil, source_channel: nil, knowledge_domain: nil,
87
87
  submitted_by: nil, submitted_from: nil, content_hash: nil, context: {},
88
- skip: false, access_scope: 'global', identity_principal_id: nil,
89
- identity_id: nil, identity_canonical_name: nil, **)
88
+ skip: false, access_scope: 'global', **)
90
89
  return { status: :skipped } if skip
91
90
 
91
+ identity = resolve_process_identity
92
92
  content = normalize_text_input(content)
93
93
  content_type = normalize_content_type(content_type.nil? ? :observation : content_type)
94
94
  log.debug("Apollo Knowledge.handle_ingest content_length=#{content.length} content_type=#{content_type} tags=#{Array(tags).size} source_agent=#{source_agent} source_channel=#{source_channel || 'nil'}") # rubocop:disable Layout/LineLength
@@ -97,7 +97,7 @@ module Legion
97
97
 
98
98
  hash = content_hash || (defined?(Helpers::Writeback) ? Helpers::Writeback.content_hash(content) : nil)
99
99
  existing = active_duplicate_for_hash(hash, access_scope: access_scope,
100
- identity_principal_id: identity_principal_id)
100
+ identity_principal_id: identity[:principal_id])
101
101
  if existing
102
102
  log.info("Apollo Knowledge.handle_ingest deduped entry_id=#{existing.id} source_agent=#{source_agent}")
103
103
  return { success: true, entry_id: existing.id, deduped: true }
@@ -109,9 +109,9 @@ module Legion
109
109
  source_provider: source_provider, source_channel: source_channel,
110
110
  submitted_by: submitted_by, submitted_from: submitted_from,
111
111
  access_scope: access_scope,
112
- identity_principal_id: identity_principal_id,
113
- identity_id: identity_id,
114
- identity_canonical_name: identity_canonical_name)
112
+ identity_principal_id: identity[:principal_id],
113
+ identity_id: identity[:identity_id],
114
+ identity_canonical_name: identity[:canonical_name])
115
115
 
116
116
  corroborated, existing_id = find_corroboration(
117
117
  embedding, content_type_sym, metadata[:source_agent], metadata[:source_channel]
@@ -148,6 +148,7 @@ module Legion
148
148
  requesting_principal_id: nil, **)
149
149
  return { success: false, error: 'apollo_data_not_available' } unless Helpers::DataModels.apollo_entry_available?
150
150
 
151
+ requesting_principal_id = resolve_requesting_principal_id(requesting_principal_id)
151
152
  entry_model = Helpers::DataModels.apollo_entry
152
153
  query = normalize_text_input(query)
153
154
  status_defaulted = status.equal?(UNSET)
@@ -273,6 +274,7 @@ module Legion
273
274
 
274
275
  return { success: false, error: 'apollo_data_not_available' } unless Helpers::DataModels.apollo_entry_available?
275
276
 
277
+ requesting_principal_id = resolve_requesting_principal_id(requesting_principal_id)
276
278
  query = normalize_text_input(query)
277
279
  log.debug("Apollo Knowledge.retrieve_relevant query_length=#{query.length} limit=#{limit} min_confidence=#{min_confidence} tags=#{Array(tags).size} domain=#{domain || 'nil'}") # rubocop:disable Layout/LineLength
278
280
  return { success: true, entries: [], count: 0 } if query.nil? || query.to_s.strip.empty?
@@ -720,6 +722,29 @@ module Legion
720
722
  end
721
723
  end
722
724
 
725
+ def resolve_process_identity
726
+ return { principal_id: nil, identity_id: nil, canonical_name: nil } unless defined?(Legion::Identity::Process)
727
+
728
+ {
729
+ principal_id: Legion::Identity::Process.db_principal_id,
730
+ identity_id: Legion::Identity::Process.db_identity_id,
731
+ canonical_name: Legion::Identity::Process.canonical_name
732
+ }
733
+ rescue StandardError => e
734
+ handle_exception(e, level: :warn, operation: 'apollo.knowledge.resolve_process_identity')
735
+ { principal_id: nil, identity_id: nil, canonical_name: nil }
736
+ end
737
+
738
+ def resolve_requesting_principal_id(explicit_value)
739
+ return explicit_value if explicit_value
740
+ return nil unless defined?(Legion::Identity::Process)
741
+
742
+ Legion::Identity::Process.db_principal_id
743
+ rescue StandardError => e
744
+ handle_exception(e, level: :warn, operation: 'apollo.knowledge.resolve_requesting_principal_id')
745
+ nil
746
+ end
747
+
723
748
  include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
724
749
  include Legion::JSON::Helper
725
750
  include Legion::Settings::Helper
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Apollo
6
- VERSION = '0.4.27'
6
+ VERSION = '0.4.28'
7
7
  end
8
8
  end
9
9
  end
@@ -371,7 +371,7 @@ RSpec.describe Legion::Extensions::Apollo::Runners::Knowledge do
371
371
  end
372
372
  end
373
373
 
374
- context 'identity kwargs persistence' do
374
+ context 'identity from Legion::Identity::Process' do
375
375
  let(:mock_entry_class2) { double('ApolloEntry2') }
376
376
  let(:mock_expertise_class2) { double('ApolloExpertise2') }
377
377
  let(:mock_access_log_class2) { double('ApolloAccessLog2') }
@@ -390,18 +390,20 @@ RSpec.describe Legion::Extensions::Apollo::Runners::Knowledge do
390
390
  allow(host).to receive(:embed_text).and_return(nil)
391
391
  allow(host).to receive(:find_corroboration).and_return([false, nil])
392
392
  allow(host).to receive(:detect_contradictions).and_return([])
393
+ stub_const('Legion::Identity::Process', double(
394
+ db_principal_id: 42,
395
+ db_identity_id: 7,
396
+ canonical_name: 'alice'
397
+ ))
393
398
  end
394
399
 
395
- it 'passes identity_principal_id and access_scope through to create_candidate_entry' do
400
+ it 'derives identity from Legion::Identity::Process and persists it' do
396
401
  expect(mock_entry_class2).to receive(:create).with(
397
- hash_including(identity_principal_id: 42, access_scope: 'private')
402
+ hash_including(identity_principal_id: 42, identity_id: 7, identity_canonical_name: 'alice',
403
+ access_scope: 'private')
398
404
  ).and_return(mock_entry2)
399
405
 
400
- host.handle_ingest(
401
- content: 'test fact', tags: [],
402
- identity_principal_id: 42, identity_id: 7, identity_canonical_name: 'alice',
403
- access_scope: 'private'
404
- )
406
+ host.handle_ingest(content: 'test fact', tags: [], access_scope: 'private')
405
407
  end
406
408
 
407
409
  it 'defaults access_scope to global when not provided' do
@@ -412,14 +414,14 @@ RSpec.describe Legion::Extensions::Apollo::Runners::Knowledge do
412
414
  host.handle_ingest(content: 'test fact', tags: [])
413
415
  end
414
416
 
415
- it 'persists identity_id and identity_canonical_name' do
417
+ it 'ignores identity kwargs passed by callers' do
416
418
  expect(mock_entry_class2).to receive(:create).with(
417
- hash_including(identity_id: 7, identity_canonical_name: 'alice')
419
+ hash_including(identity_principal_id: 42, identity_id: 7, identity_canonical_name: 'alice')
418
420
  ).and_return(mock_entry2)
419
421
 
420
422
  host.handle_ingest(
421
423
  content: 'test fact', tags: [],
422
- identity_principal_id: 42, identity_id: 7, identity_canonical_name: 'alice',
424
+ identity_principal_id: 999, identity_id: 888, identity_canonical_name: 'mallory',
423
425
  access_scope: 'private'
424
426
  )
425
427
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-apollo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.27
4
+ version: 0.4.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity