google-adk 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl

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 (185) hide show
  1. google/adk/agents/run_config.py +4 -0
  2. google/adk/auth/auth_preprocessor.py +19 -16
  3. google/adk/cli/browser/index.html +1 -1
  4. google/adk/cli/browser/{main-SY2WYYGV.js → main-SLIAU2JL.js} +46 -30
  5. google/adk/cli/cli.py +8 -8
  6. google/adk/cli/cli_deploy.py +2 -4
  7. google/adk/cli/cli_tools_click.py +6 -6
  8. google/adk/flows/llm_flows/base_llm_flow.py +1 -1
  9. google/adk/flows/llm_flows/contents.py +21 -1
  10. google/adk/flows/llm_flows/functions.py +3 -1
  11. google/adk/models/google_llm.py +0 -1
  12. google/adk/runners.py +13 -2
  13. google/adk/version.py +1 -1
  14. {google_adk-0.0.3.dist-info → google_adk-0.0.5.dist-info}/METADATA +4 -2
  15. google_adk-0.0.5.dist-info/RECORD +175 -0
  16. {google_adk-0.0.3.dist-info → google_adk-0.0.5.dist-info}/WHEEL +1 -1
  17. google_adk-0.0.5.dist-info/licenses/LICENSE +202 -0
  18. google/adk/._version.py +0 -0
  19. google/adk/docs/Makefile +0 -20
  20. google/adk/docs/build/doctrees/google-adk.doctree +0 -0
  21. google/adk/docs/build/html/_sources/google-adk.rst.txt +0 -98
  22. google/adk/docs/build/html/_sources/index.rst.txt +0 -7
  23. google/adk/docs/build/html/_static/autodoc_pydantic.css +0 -27
  24. google/adk/docs/build/html/_static/basic.css +0 -925
  25. google/adk/docs/build/html/_static/debug.css +0 -85
  26. google/adk/docs/build/html/_static/doctools.js +0 -156
  27. google/adk/docs/build/html/_static/documentation_options.js +0 -29
  28. google/adk/docs/build/html/_static/file.png +0 -0
  29. google/adk/docs/build/html/_static/language_data.js +0 -199
  30. google/adk/docs/build/html/_static/minus.png +0 -0
  31. google/adk/docs/build/html/_static/plus.png +0 -0
  32. google/adk/docs/build/html/_static/pygments.css +0 -274
  33. google/adk/docs/build/html/_static/scripts/furo-extensions.js +0 -16
  34. google/adk/docs/build/html/_static/scripts/furo.js +0 -19
  35. google/adk/docs/build/html/_static/scripts/furo.js.LICENSE.txt +0 -7
  36. google/adk/docs/build/html/_static/scripts/furo.js.map +0 -1
  37. google/adk/docs/build/html/_static/searchtools.js +0 -620
  38. google/adk/docs/build/html/_static/skeleton.css +0 -312
  39. google/adk/docs/build/html/_static/sphinx_highlight.js +0 -170
  40. google/adk/docs/build/html/_static/styles/furo-extensions.css +0 -18
  41. google/adk/docs/build/html/_static/styles/furo-extensions.css.map +0 -1
  42. google/adk/docs/build/html/_static/styles/furo.css +0 -18
  43. google/adk/docs/build/html/_static/styles/furo.css.map +0 -1
  44. google/adk/docs/build/html/genindex.html +0 -861
  45. google/adk/docs/build/html/google-adk.html +0 -5461
  46. google/adk/docs/build/html/index.html +0 -567
  47. google/adk/docs/build/html/objects.inv +0 -0
  48. google/adk/docs/build/html/py-modindex.html +0 -373
  49. google/adk/docs/build/html/search.html +0 -333
  50. google/adk/docs/build/html/searchindex.js +0 -17
  51. google/adk/docs/source/conf.py +0 -133
  52. google/adk/docs/source/google-adk.rst +0 -98
  53. google/adk/docs/source/index.rst +0 -7
  54. google/adk/tests/__init__.py +0 -14
  55. google/adk/tests/integration/.env.example +0 -10
  56. google/adk/tests/integration/__init__.py +0 -18
  57. google/adk/tests/integration/conftest.py +0 -119
  58. google/adk/tests/integration/fixture/__init__.py +0 -14
  59. google/adk/tests/integration/fixture/agent_with_config/__init__.py +0 -15
  60. google/adk/tests/integration/fixture/agent_with_config/agent.py +0 -88
  61. google/adk/tests/integration/fixture/callback_agent/__init__.py +0 -15
  62. google/adk/tests/integration/fixture/callback_agent/agent.py +0 -105
  63. google/adk/tests/integration/fixture/context_update_test/OWNERS +0 -1
  64. google/adk/tests/integration/fixture/context_update_test/__init__.py +0 -15
  65. google/adk/tests/integration/fixture/context_update_test/agent.py +0 -43
  66. google/adk/tests/integration/fixture/context_update_test/successful_test.session.json +0 -582
  67. google/adk/tests/integration/fixture/context_variable_agent/__init__.py +0 -15
  68. google/adk/tests/integration/fixture/context_variable_agent/agent.py +0 -115
  69. google/adk/tests/integration/fixture/customer_support_ma/__init__.py +0 -15
  70. google/adk/tests/integration/fixture/customer_support_ma/agent.py +0 -172
  71. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/__init__.py +0 -15
  72. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/agent.py +0 -338
  73. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/order_query.test.json +0 -69
  74. google/adk/tests/integration/fixture/ecommerce_customer_service_agent/test_config.json +0 -6
  75. google/adk/tests/integration/fixture/flow_complex_spark/__init__.py +0 -15
  76. google/adk/tests/integration/fixture/flow_complex_spark/agent.py +0 -182
  77. google/adk/tests/integration/fixture/flow_complex_spark/sample.session.json +0 -190
  78. google/adk/tests/integration/fixture/hello_world_agent/__init__.py +0 -15
  79. google/adk/tests/integration/fixture/hello_world_agent/agent.py +0 -95
  80. google/adk/tests/integration/fixture/hello_world_agent/roll_die.test.json +0 -24
  81. google/adk/tests/integration/fixture/hello_world_agent/test_config.json +0 -6
  82. google/adk/tests/integration/fixture/home_automation_agent/__init__.py +0 -15
  83. google/adk/tests/integration/fixture/home_automation_agent/agent.py +0 -304
  84. google/adk/tests/integration/fixture/home_automation_agent/simple_test.test.json +0 -5
  85. google/adk/tests/integration/fixture/home_automation_agent/simple_test2.test.json +0 -5
  86. google/adk/tests/integration/fixture/home_automation_agent/test_config.json +0 -5
  87. google/adk/tests/integration/fixture/home_automation_agent/test_files/dependent_tool_calls.test.json +0 -18
  88. google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/eval_data.test.json +0 -17
  89. google/adk/tests/integration/fixture/home_automation_agent/test_files/memorizing_past_events/test_config.json +0 -6
  90. google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_multi_turn_conversation.test.json +0 -18
  91. google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test.test.json +0 -17
  92. google/adk/tests/integration/fixture/home_automation_agent/test_files/simple_test2.test.json +0 -5
  93. google/adk/tests/integration/fixture/home_automation_agent/test_files/test_config.json +0 -5
  94. google/adk/tests/integration/fixture/tool_agent/__init__.py +0 -15
  95. google/adk/tests/integration/fixture/tool_agent/agent.py +0 -218
  96. google/adk/tests/integration/fixture/tool_agent/files/Agent_test_plan.pdf +0 -0
  97. google/adk/tests/integration/fixture/trip_planner_agent/__init__.py +0 -15
  98. google/adk/tests/integration/fixture/trip_planner_agent/agent.py +0 -110
  99. google/adk/tests/integration/fixture/trip_planner_agent/initial.session.json +0 -13
  100. google/adk/tests/integration/fixture/trip_planner_agent/test_config.json +0 -5
  101. google/adk/tests/integration/fixture/trip_planner_agent/test_files/initial.session.json +0 -13
  102. google/adk/tests/integration/fixture/trip_planner_agent/test_files/test_config.json +0 -5
  103. google/adk/tests/integration/fixture/trip_planner_agent/test_files/trip_inquiry_sub_agent.test.json +0 -7
  104. google/adk/tests/integration/fixture/trip_planner_agent/trip_inquiry.test.json +0 -19
  105. google/adk/tests/integration/models/__init__.py +0 -14
  106. google/adk/tests/integration/models/test_google_llm.py +0 -65
  107. google/adk/tests/integration/test_callback.py +0 -70
  108. google/adk/tests/integration/test_context_variable.py +0 -67
  109. google/adk/tests/integration/test_evalute_agent_in_fixture.py +0 -76
  110. google/adk/tests/integration/test_multi_agent.py +0 -28
  111. google/adk/tests/integration/test_multi_turn.py +0 -42
  112. google/adk/tests/integration/test_single_agent.py +0 -23
  113. google/adk/tests/integration/test_sub_agent.py +0 -26
  114. google/adk/tests/integration/test_system_instruction.py +0 -177
  115. google/adk/tests/integration/test_tools.py +0 -287
  116. google/adk/tests/integration/test_with_test_file.py +0 -34
  117. google/adk/tests/integration/tools/__init__.py +0 -14
  118. google/adk/tests/integration/utils/__init__.py +0 -16
  119. google/adk/tests/integration/utils/asserts.py +0 -75
  120. google/adk/tests/integration/utils/test_runner.py +0 -97
  121. google/adk/tests/unittests/__init__.py +0 -14
  122. google/adk/tests/unittests/agents/__init__.py +0 -14
  123. google/adk/tests/unittests/agents/test_base_agent.py +0 -407
  124. google/adk/tests/unittests/agents/test_langgraph_agent.py +0 -191
  125. google/adk/tests/unittests/agents/test_llm_agent_callbacks.py +0 -138
  126. google/adk/tests/unittests/agents/test_llm_agent_fields.py +0 -231
  127. google/adk/tests/unittests/agents/test_loop_agent.py +0 -136
  128. google/adk/tests/unittests/agents/test_parallel_agent.py +0 -92
  129. google/adk/tests/unittests/agents/test_sequential_agent.py +0 -114
  130. google/adk/tests/unittests/artifacts/__init__.py +0 -14
  131. google/adk/tests/unittests/artifacts/test_artifact_service.py +0 -276
  132. google/adk/tests/unittests/auth/test_auth_handler.py +0 -575
  133. google/adk/tests/unittests/conftest.py +0 -73
  134. google/adk/tests/unittests/fast_api/__init__.py +0 -14
  135. google/adk/tests/unittests/fast_api/test_fast_api.py +0 -269
  136. google/adk/tests/unittests/flows/__init__.py +0 -14
  137. google/adk/tests/unittests/flows/llm_flows/__init__.py +0 -14
  138. google/adk/tests/unittests/flows/llm_flows/_test_examples.py +0 -142
  139. google/adk/tests/unittests/flows/llm_flows/test_agent_transfer.py +0 -311
  140. google/adk/tests/unittests/flows/llm_flows/test_functions_long_running.py +0 -244
  141. google/adk/tests/unittests/flows/llm_flows/test_functions_request_euc.py +0 -346
  142. google/adk/tests/unittests/flows/llm_flows/test_functions_sequential.py +0 -93
  143. google/adk/tests/unittests/flows/llm_flows/test_functions_simple.py +0 -258
  144. google/adk/tests/unittests/flows/llm_flows/test_identity.py +0 -66
  145. google/adk/tests/unittests/flows/llm_flows/test_instructions.py +0 -164
  146. google/adk/tests/unittests/flows/llm_flows/test_model_callbacks.py +0 -142
  147. google/adk/tests/unittests/flows/llm_flows/test_other_configs.py +0 -46
  148. google/adk/tests/unittests/flows/llm_flows/test_tool_callbacks.py +0 -269
  149. google/adk/tests/unittests/models/__init__.py +0 -14
  150. google/adk/tests/unittests/models/test_google_llm.py +0 -224
  151. google/adk/tests/unittests/models/test_litellm.py +0 -804
  152. google/adk/tests/unittests/models/test_models.py +0 -60
  153. google/adk/tests/unittests/sessions/__init__.py +0 -14
  154. google/adk/tests/unittests/sessions/test_session_service.py +0 -227
  155. google/adk/tests/unittests/sessions/test_vertex_ai_session_service.py +0 -246
  156. google/adk/tests/unittests/streaming/__init__.py +0 -14
  157. google/adk/tests/unittests/streaming/test_streaming.py +0 -50
  158. google/adk/tests/unittests/tools/__init__.py +0 -14
  159. google/adk/tests/unittests/tools/apihub_tool/clients/test_apihub_client.py +0 -499
  160. google/adk/tests/unittests/tools/apihub_tool/test_apihub_toolset.py +0 -204
  161. google/adk/tests/unittests/tools/application_integration_tool/clients/test_connections_client.py +0 -600
  162. google/adk/tests/unittests/tools/application_integration_tool/clients/test_integration_client.py +0 -630
  163. google/adk/tests/unittests/tools/application_integration_tool/test_application_integration_toolset.py +0 -345
  164. google/adk/tests/unittests/tools/google_api_tool/__init__.py +0 -13
  165. google/adk/tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py +0 -657
  166. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_auto_auth_credential_exchanger.py +0 -145
  167. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_base_auth_credential_exchanger.py +0 -68
  168. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_oauth2_exchanger.py +0 -153
  169. google/adk/tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_service_account_exchanger.py +0 -196
  170. google/adk/tests/unittests/tools/openapi_tool/auth/test_auth_helper.py +0 -573
  171. google/adk/tests/unittests/tools/openapi_tool/common/test_common.py +0 -436
  172. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test.yaml +0 -1367
  173. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_spec_parser.py +0 -628
  174. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_toolset.py +0 -139
  175. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_operation_parser.py +0 -406
  176. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py +0 -966
  177. google/adk/tests/unittests/tools/openapi_tool/openapi_spec_parser/test_tool_auth_handler.py +0 -201
  178. google/adk/tests/unittests/tools/retrieval/__init__.py +0 -14
  179. google/adk/tests/unittests/tools/retrieval/test_vertex_ai_rag_retrieval.py +0 -147
  180. google/adk/tests/unittests/tools/test_agent_tool.py +0 -167
  181. google/adk/tests/unittests/tools/test_base_tool.py +0 -141
  182. google/adk/tests/unittests/tools/test_build_function_declaration.py +0 -277
  183. google/adk/tests/unittests/utils.py +0 -304
  184. google_adk-0.0.3.dist-info/RECORD +0 -340
  185. {google_adk-0.0.3.dist-info → google_adk-0.0.5.dist-info}/entry_points.txt +0 -0
@@ -1,620 +0,0 @@
1
- /*
2
- * searchtools.js
3
- * ~~~~~~~~~~~~~~~~
4
- *
5
- * Sphinx JavaScript utilities for the full-text search.
6
- *
7
- * :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS.
8
- * :license: BSD, see LICENSE for details.
9
- *
10
- */
11
- "use strict";
12
-
13
- /**
14
- * Simple result scoring code.
15
- */
16
- if (typeof Scorer === "undefined") {
17
- var Scorer = {
18
- // Implement the following function to further tweak the score for each result
19
- // The function takes a result array [docname, title, anchor, descr, score, filename]
20
- // and returns the new score.
21
- /*
22
- score: result => {
23
- const [docname, title, anchor, descr, score, filename] = result
24
- return score
25
- },
26
- */
27
-
28
- // query matches the full name of an object
29
- objNameMatch: 11,
30
- // or matches in the last dotted part of the object name
31
- objPartialMatch: 6,
32
- // Additive scores depending on the priority of the object
33
- objPrio: {
34
- 0: 15, // used to be importantResults
35
- 1: 5, // used to be objectResults
36
- 2: -5, // used to be unimportantResults
37
- },
38
- // Used when the priority is not in the mapping.
39
- objPrioDefault: 0,
40
-
41
- // query found in title
42
- title: 15,
43
- partialTitle: 7,
44
- // query found in terms
45
- term: 5,
46
- partialTerm: 2,
47
- };
48
- }
49
-
50
- const _removeChildren = (element) => {
51
- while (element && element.lastChild) element.removeChild(element.lastChild);
52
- };
53
-
54
- /**
55
- * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
56
- */
57
- const _escapeRegExp = (string) =>
58
- string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
59
-
60
- const _displayItem = (item, searchTerms, highlightTerms) => {
61
- const docBuilder = DOCUMENTATION_OPTIONS.BUILDER;
62
- const docFileSuffix = DOCUMENTATION_OPTIONS.FILE_SUFFIX;
63
- const docLinkSuffix = DOCUMENTATION_OPTIONS.LINK_SUFFIX;
64
- const showSearchSummary = DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY;
65
- const contentRoot = document.documentElement.dataset.content_root;
66
-
67
- const [docName, title, anchor, descr, score, _filename] = item;
68
-
69
- let listItem = document.createElement("li");
70
- let requestUrl;
71
- let linkUrl;
72
- if (docBuilder === "dirhtml") {
73
- // dirhtml builder
74
- let dirname = docName + "/";
75
- if (dirname.match(/\/index\/$/))
76
- dirname = dirname.substring(0, dirname.length - 6);
77
- else if (dirname === "index/") dirname = "";
78
- requestUrl = contentRoot + dirname;
79
- linkUrl = requestUrl;
80
- } else {
81
- // normal html builders
82
- requestUrl = contentRoot + docName + docFileSuffix;
83
- linkUrl = docName + docLinkSuffix;
84
- }
85
- let linkEl = listItem.appendChild(document.createElement("a"));
86
- linkEl.href = linkUrl + anchor;
87
- linkEl.dataset.score = score;
88
- linkEl.innerHTML = title;
89
- if (descr) {
90
- listItem.appendChild(document.createElement("span")).innerHTML =
91
- " (" + descr + ")";
92
- // highlight search terms in the description
93
- if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
94
- highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
95
- }
96
- else if (showSearchSummary)
97
- fetch(requestUrl)
98
- .then((responseData) => responseData.text())
99
- .then((data) => {
100
- if (data)
101
- listItem.appendChild(
102
- Search.makeSearchSummary(data, searchTerms, anchor)
103
- );
104
- // highlight search terms in the summary
105
- if (SPHINX_HIGHLIGHT_ENABLED) // set in sphinx_highlight.js
106
- highlightTerms.forEach((term) => _highlightText(listItem, term, "highlighted"));
107
- });
108
- Search.output.appendChild(listItem);
109
- };
110
- const _finishSearch = (resultCount) => {
111
- Search.stopPulse();
112
- Search.title.innerText = _("Search Results");
113
- if (!resultCount)
114
- Search.status.innerText = Documentation.gettext(
115
- "Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories."
116
- );
117
- else
118
- Search.status.innerText = _(
119
- "Search finished, found ${resultCount} page(s) matching the search query."
120
- ).replace('${resultCount}', resultCount);
121
- };
122
- const _displayNextItem = (
123
- results,
124
- resultCount,
125
- searchTerms,
126
- highlightTerms,
127
- ) => {
128
- // results left, load the summary and display it
129
- // this is intended to be dynamic (don't sub resultsCount)
130
- if (results.length) {
131
- _displayItem(results.pop(), searchTerms, highlightTerms);
132
- setTimeout(
133
- () => _displayNextItem(results, resultCount, searchTerms, highlightTerms),
134
- 5
135
- );
136
- }
137
- // search finished, update title and status message
138
- else _finishSearch(resultCount);
139
- };
140
- // Helper function used by query() to order search results.
141
- // Each input is an array of [docname, title, anchor, descr, score, filename].
142
- // Order the results by score (in opposite order of appearance, since the
143
- // `_displayNextItem` function uses pop() to retrieve items) and then alphabetically.
144
- const _orderResultsByScoreThenName = (a, b) => {
145
- const leftScore = a[4];
146
- const rightScore = b[4];
147
- if (leftScore === rightScore) {
148
- // same score: sort alphabetically
149
- const leftTitle = a[1].toLowerCase();
150
- const rightTitle = b[1].toLowerCase();
151
- if (leftTitle === rightTitle) return 0;
152
- return leftTitle > rightTitle ? -1 : 1; // inverted is intentional
153
- }
154
- return leftScore > rightScore ? 1 : -1;
155
- };
156
-
157
- /**
158
- * Default splitQuery function. Can be overridden in ``sphinx.search`` with a
159
- * custom function per language.
160
- *
161
- * The regular expression works by splitting the string on consecutive characters
162
- * that are not Unicode letters, numbers, underscores, or emoji characters.
163
- * This is the same as ``\W+`` in Python, preserving the surrogate pair area.
164
- */
165
- if (typeof splitQuery === "undefined") {
166
- var splitQuery = (query) => query
167
- .split(/[^\p{Letter}\p{Number}_\p{Emoji_Presentation}]+/gu)
168
- .filter(term => term) // remove remaining empty strings
169
- }
170
-
171
- /**
172
- * Search Module
173
- */
174
- const Search = {
175
- _index: null,
176
- _queued_query: null,
177
- _pulse_status: -1,
178
-
179
- htmlToText: (htmlString, anchor) => {
180
- const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
181
- for (const removalQuery of [".headerlink", "script", "style"]) {
182
- htmlElement.querySelectorAll(removalQuery).forEach((el) => { el.remove() });
183
- }
184
- if (anchor) {
185
- const anchorContent = htmlElement.querySelector(`[role="main"] ${anchor}`);
186
- if (anchorContent) return anchorContent.textContent;
187
-
188
- console.warn(
189
- `Anchored content block not found. Sphinx search tries to obtain it via DOM query '[role=main] ${anchor}'. Check your theme or template.`
190
- );
191
- }
192
-
193
- // if anchor not specified or not found, fall back to main content
194
- const docContent = htmlElement.querySelector('[role="main"]');
195
- if (docContent) return docContent.textContent;
196
-
197
- console.warn(
198
- "Content block not found. Sphinx search tries to obtain it via DOM query '[role=main]'. Check your theme or template."
199
- );
200
- return "";
201
- },
202
-
203
- init: () => {
204
- const query = new URLSearchParams(window.location.search).get("q");
205
- document
206
- .querySelectorAll('input[name="q"]')
207
- .forEach((el) => (el.value = query));
208
- if (query) Search.performSearch(query);
209
- },
210
-
211
- loadIndex: (url) =>
212
- (document.body.appendChild(document.createElement("script")).src = url),
213
-
214
- setIndex: (index) => {
215
- Search._index = index;
216
- if (Search._queued_query !== null) {
217
- const query = Search._queued_query;
218
- Search._queued_query = null;
219
- Search.query(query);
220
- }
221
- },
222
-
223
- hasIndex: () => Search._index !== null,
224
-
225
- deferQuery: (query) => (Search._queued_query = query),
226
-
227
- stopPulse: () => (Search._pulse_status = -1),
228
-
229
- startPulse: () => {
230
- if (Search._pulse_status >= 0) return;
231
-
232
- const pulse = () => {
233
- Search._pulse_status = (Search._pulse_status + 1) % 4;
234
- Search.dots.innerText = ".".repeat(Search._pulse_status);
235
- if (Search._pulse_status >= 0) window.setTimeout(pulse, 500);
236
- };
237
- pulse();
238
- },
239
-
240
- /**
241
- * perform a search for something (or wait until index is loaded)
242
- */
243
- performSearch: (query) => {
244
- // create the required interface elements
245
- const searchText = document.createElement("h2");
246
- searchText.textContent = _("Searching");
247
- const searchSummary = document.createElement("p");
248
- searchSummary.classList.add("search-summary");
249
- searchSummary.innerText = "";
250
- const searchList = document.createElement("ul");
251
- searchList.classList.add("search");
252
-
253
- const out = document.getElementById("search-results");
254
- Search.title = out.appendChild(searchText);
255
- Search.dots = Search.title.appendChild(document.createElement("span"));
256
- Search.status = out.appendChild(searchSummary);
257
- Search.output = out.appendChild(searchList);
258
-
259
- const searchProgress = document.getElementById("search-progress");
260
- // Some themes don't use the search progress node
261
- if (searchProgress) {
262
- searchProgress.innerText = _("Preparing search...");
263
- }
264
- Search.startPulse();
265
-
266
- // index already loaded, the browser was quick!
267
- if (Search.hasIndex()) Search.query(query);
268
- else Search.deferQuery(query);
269
- },
270
-
271
- _parseQuery: (query) => {
272
- // stem the search terms and add them to the correct list
273
- const stemmer = new Stemmer();
274
- const searchTerms = new Set();
275
- const excludedTerms = new Set();
276
- const highlightTerms = new Set();
277
- const objectTerms = new Set(splitQuery(query.toLowerCase().trim()));
278
- splitQuery(query.trim()).forEach((queryTerm) => {
279
- const queryTermLower = queryTerm.toLowerCase();
280
-
281
- // maybe skip this "word"
282
- // stopwords array is from language_data.js
283
- if (
284
- stopwords.indexOf(queryTermLower) !== -1 ||
285
- queryTerm.match(/^\d+$/)
286
- )
287
- return;
288
-
289
- // stem the word
290
- let word = stemmer.stemWord(queryTermLower);
291
- // select the correct list
292
- if (word[0] === "-") excludedTerms.add(word.substr(1));
293
- else {
294
- searchTerms.add(word);
295
- highlightTerms.add(queryTermLower);
296
- }
297
- });
298
-
299
- if (SPHINX_HIGHLIGHT_ENABLED) { // set in sphinx_highlight.js
300
- localStorage.setItem("sphinx_highlight_terms", [...highlightTerms].join(" "))
301
- }
302
-
303
- // console.debug("SEARCH: searching for:");
304
- // console.info("required: ", [...searchTerms]);
305
- // console.info("excluded: ", [...excludedTerms]);
306
-
307
- return [query, searchTerms, excludedTerms, highlightTerms, objectTerms];
308
- },
309
-
310
- /**
311
- * execute search (requires search index to be loaded)
312
- */
313
- _performSearch: (query, searchTerms, excludedTerms, highlightTerms, objectTerms) => {
314
- const filenames = Search._index.filenames;
315
- const docNames = Search._index.docnames;
316
- const titles = Search._index.titles;
317
- const allTitles = Search._index.alltitles;
318
- const indexEntries = Search._index.indexentries;
319
-
320
- // Collect multiple result groups to be sorted separately and then ordered.
321
- // Each is an array of [docname, title, anchor, descr, score, filename].
322
- const normalResults = [];
323
- const nonMainIndexResults = [];
324
-
325
- _removeChildren(document.getElementById("search-progress"));
326
-
327
- const queryLower = query.toLowerCase().trim();
328
- for (const [title, foundTitles] of Object.entries(allTitles)) {
329
- if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
330
- for (const [file, id] of foundTitles) {
331
- const score = Math.round(Scorer.title * queryLower.length / title.length);
332
- const boost = titles[file] === title ? 1 : 0; // add a boost for document titles
333
- normalResults.push([
334
- docNames[file],
335
- titles[file] !== title ? `${titles[file]} > ${title}` : title,
336
- id !== null ? "#" + id : "",
337
- null,
338
- score + boost,
339
- filenames[file],
340
- ]);
341
- }
342
- }
343
- }
344
-
345
- // search for explicit entries in index directives
346
- for (const [entry, foundEntries] of Object.entries(indexEntries)) {
347
- if (entry.includes(queryLower) && (queryLower.length >= entry.length/2)) {
348
- for (const [file, id, isMain] of foundEntries) {
349
- const score = Math.round(100 * queryLower.length / entry.length);
350
- const result = [
351
- docNames[file],
352
- titles[file],
353
- id ? "#" + id : "",
354
- null,
355
- score,
356
- filenames[file],
357
- ];
358
- if (isMain) {
359
- normalResults.push(result);
360
- } else {
361
- nonMainIndexResults.push(result);
362
- }
363
- }
364
- }
365
- }
366
-
367
- // lookup as object
368
- objectTerms.forEach((term) =>
369
- normalResults.push(...Search.performObjectSearch(term, objectTerms))
370
- );
371
-
372
- // lookup as search terms in fulltext
373
- normalResults.push(...Search.performTermsSearch(searchTerms, excludedTerms));
374
-
375
- // let the scorer override scores with a custom scoring function
376
- if (Scorer.score) {
377
- normalResults.forEach((item) => (item[4] = Scorer.score(item)));
378
- nonMainIndexResults.forEach((item) => (item[4] = Scorer.score(item)));
379
- }
380
-
381
- // Sort each group of results by score and then alphabetically by name.
382
- normalResults.sort(_orderResultsByScoreThenName);
383
- nonMainIndexResults.sort(_orderResultsByScoreThenName);
384
-
385
- // Combine the result groups in (reverse) order.
386
- // Non-main index entries are typically arbitrary cross-references,
387
- // so display them after other results.
388
- let results = [...nonMainIndexResults, ...normalResults];
389
-
390
- // remove duplicate search results
391
- // note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
392
- let seen = new Set();
393
- results = results.reverse().reduce((acc, result) => {
394
- let resultStr = result.slice(0, 4).concat([result[5]]).map(v => String(v)).join(',');
395
- if (!seen.has(resultStr)) {
396
- acc.push(result);
397
- seen.add(resultStr);
398
- }
399
- return acc;
400
- }, []);
401
-
402
- return results.reverse();
403
- },
404
-
405
- query: (query) => {
406
- const [searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms] = Search._parseQuery(query);
407
- const results = Search._performSearch(searchQuery, searchTerms, excludedTerms, highlightTerms, objectTerms);
408
-
409
- // for debugging
410
- //Search.lastresults = results.slice(); // a copy
411
- // console.info("search results:", Search.lastresults);
412
-
413
- // print the results
414
- _displayNextItem(results, results.length, searchTerms, highlightTerms);
415
- },
416
-
417
- /**
418
- * search for object names
419
- */
420
- performObjectSearch: (object, objectTerms) => {
421
- const filenames = Search._index.filenames;
422
- const docNames = Search._index.docnames;
423
- const objects = Search._index.objects;
424
- const objNames = Search._index.objnames;
425
- const titles = Search._index.titles;
426
-
427
- const results = [];
428
-
429
- const objectSearchCallback = (prefix, match) => {
430
- const name = match[4]
431
- const fullname = (prefix ? prefix + "." : "") + name;
432
- const fullnameLower = fullname.toLowerCase();
433
- if (fullnameLower.indexOf(object) < 0) return;
434
-
435
- let score = 0;
436
- const parts = fullnameLower.split(".");
437
-
438
- // check for different match types: exact matches of full name or
439
- // "last name" (i.e. last dotted part)
440
- if (fullnameLower === object || parts.slice(-1)[0] === object)
441
- score += Scorer.objNameMatch;
442
- else if (parts.slice(-1)[0].indexOf(object) > -1)
443
- score += Scorer.objPartialMatch; // matches in last name
444
-
445
- const objName = objNames[match[1]][2];
446
- const title = titles[match[0]];
447
-
448
- // If more than one term searched for, we require other words to be
449
- // found in the name/title/description
450
- const otherTerms = new Set(objectTerms);
451
- otherTerms.delete(object);
452
- if (otherTerms.size > 0) {
453
- const haystack = `${prefix} ${name} ${objName} ${title}`.toLowerCase();
454
- if (
455
- [...otherTerms].some((otherTerm) => haystack.indexOf(otherTerm) < 0)
456
- )
457
- return;
458
- }
459
-
460
- let anchor = match[3];
461
- if (anchor === "") anchor = fullname;
462
- else if (anchor === "-") anchor = objNames[match[1]][1] + "-" + fullname;
463
-
464
- const descr = objName + _(", in ") + title;
465
-
466
- // add custom score for some objects according to scorer
467
- if (Scorer.objPrio.hasOwnProperty(match[2]))
468
- score += Scorer.objPrio[match[2]];
469
- else score += Scorer.objPrioDefault;
470
-
471
- results.push([
472
- docNames[match[0]],
473
- fullname,
474
- "#" + anchor,
475
- descr,
476
- score,
477
- filenames[match[0]],
478
- ]);
479
- };
480
- Object.keys(objects).forEach((prefix) =>
481
- objects[prefix].forEach((array) =>
482
- objectSearchCallback(prefix, array)
483
- )
484
- );
485
- return results;
486
- },
487
-
488
- /**
489
- * search for full-text terms in the index
490
- */
491
- performTermsSearch: (searchTerms, excludedTerms) => {
492
- // prepare search
493
- const terms = Search._index.terms;
494
- const titleTerms = Search._index.titleterms;
495
- const filenames = Search._index.filenames;
496
- const docNames = Search._index.docnames;
497
- const titles = Search._index.titles;
498
-
499
- const scoreMap = new Map();
500
- const fileMap = new Map();
501
-
502
- // perform the search on the required terms
503
- searchTerms.forEach((word) => {
504
- const files = [];
505
- const arr = [
506
- { files: terms[word], score: Scorer.term },
507
- { files: titleTerms[word], score: Scorer.title },
508
- ];
509
- // add support for partial matches
510
- if (word.length > 2) {
511
- const escapedWord = _escapeRegExp(word);
512
- if (!terms.hasOwnProperty(word)) {
513
- Object.keys(terms).forEach((term) => {
514
- if (term.match(escapedWord))
515
- arr.push({ files: terms[term], score: Scorer.partialTerm });
516
- });
517
- }
518
- if (!titleTerms.hasOwnProperty(word)) {
519
- Object.keys(titleTerms).forEach((term) => {
520
- if (term.match(escapedWord))
521
- arr.push({ files: titleTerms[term], score: Scorer.partialTitle });
522
- });
523
- }
524
- }
525
-
526
- // no match but word was a required one
527
- if (arr.every((record) => record.files === undefined)) return;
528
-
529
- // found search word in contents
530
- arr.forEach((record) => {
531
- if (record.files === undefined) return;
532
-
533
- let recordFiles = record.files;
534
- if (recordFiles.length === undefined) recordFiles = [recordFiles];
535
- files.push(...recordFiles);
536
-
537
- // set score for the word in each file
538
- recordFiles.forEach((file) => {
539
- if (!scoreMap.has(file)) scoreMap.set(file, {});
540
- scoreMap.get(file)[word] = record.score;
541
- });
542
- });
543
-
544
- // create the mapping
545
- files.forEach((file) => {
546
- if (!fileMap.has(file)) fileMap.set(file, [word]);
547
- else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word);
548
- });
549
- });
550
-
551
- // now check if the files don't contain excluded terms
552
- const results = [];
553
- for (const [file, wordList] of fileMap) {
554
- // check if all requirements are matched
555
-
556
- // as search terms with length < 3 are discarded
557
- const filteredTermCount = [...searchTerms].filter(
558
- (term) => term.length > 2
559
- ).length;
560
- if (
561
- wordList.length !== searchTerms.size &&
562
- wordList.length !== filteredTermCount
563
- )
564
- continue;
565
-
566
- // ensure that none of the excluded terms is in the search result
567
- if (
568
- [...excludedTerms].some(
569
- (term) =>
570
- terms[term] === file ||
571
- titleTerms[term] === file ||
572
- (terms[term] || []).includes(file) ||
573
- (titleTerms[term] || []).includes(file)
574
- )
575
- )
576
- break;
577
-
578
- // select one (max) score for the file.
579
- const score = Math.max(...wordList.map((w) => scoreMap.get(file)[w]));
580
- // add result to the result list
581
- results.push([
582
- docNames[file],
583
- titles[file],
584
- "",
585
- null,
586
- score,
587
- filenames[file],
588
- ]);
589
- }
590
- return results;
591
- },
592
-
593
- /**
594
- * helper function to return a node containing the
595
- * search summary for a given text. keywords is a list
596
- * of stemmed words.
597
- */
598
- makeSearchSummary: (htmlText, keywords, anchor) => {
599
- const text = Search.htmlToText(htmlText, anchor);
600
- if (text === "") return null;
601
-
602
- const textLower = text.toLowerCase();
603
- const actualStartPosition = [...keywords]
604
- .map((k) => textLower.indexOf(k.toLowerCase()))
605
- .filter((i) => i > -1)
606
- .slice(-1)[0];
607
- const startWithContext = Math.max(actualStartPosition - 120, 0);
608
-
609
- const top = startWithContext === 0 ? "" : "...";
610
- const tail = startWithContext + 240 < text.length ? "..." : "";
611
-
612
- let summary = document.createElement("p");
613
- summary.classList.add("context");
614
- summary.textContent = top + text.substr(startWithContext, 240).trim() + tail;
615
-
616
- return summary;
617
- },
618
- };
619
-
620
- _ready(Search.init);