@arcgis/ai-orchestrator 5.1.0-next.7 → 5.1.0-next.71

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.
@@ -0,0 +1 @@
1
+ (function(){"use strict";const h=(a,r)=>{if(a.length!==r.length)throw new Error("Vectors must be the same length");let c=0,t=0,e=0;for(let n=0;n<a.length;++n){const s=a[n],l=r[n];c+=s*l,t+=s*s,e+=l*l}const i=Math.sqrt(t*e);if(i===0)return 0;const m=c/i;return Math.max(-1,Math.min(1,m))},f=(a,r,c=.6)=>{const t=[],e=[...a];for(;t.length<r&&e.length>0;){let i=-1,m=-1/0;for(let n=0;n<e.length;n++){const s=e[n].score,l=t.length===0?0:Math.max(...t.map(o=>h(e[n].vector,o.vector))),d=c*s-(1-c)*l;d>m&&(m=d,i=n)}t.push(e[i]),e.splice(i,1)}return t.map(({name:i,score:m})=>({name:i,score:m}))};let p=[];const u=new Map,v=12,y=10,M=a=>{p=a.layers.map(r=>({id:r.id,vector:r.vector}))},E=a=>{u.clear();for(const r of a.layers){const c=r.fields.map(t=>({name:t.name,vector:t.vector}));u.set(r.id,c)}};globalThis.addEventListener("message",a=>{(async()=>{const{type:r,webmapEmbeddings:c,layerIdForFieldsSearch:t=[],requestId:e,precomputedEmbedding:i,minScore:m=0,topResults:n=v}=a.data;switch(r){case"generateEmbeddings":{c&&(M(c),E(c)),globalThis.postMessage("completed");break}case"layerSearch":{if(p.length>0)try{const s=p.map(o=>({id:o.id,vector:o.vector,score:h(i,o.vector)})),d=f(s.map(o=>({name:o.id,vector:o.vector,score:o.score})),y).map(({name:o,score:b})=>({id:o,score:b}));globalThis.postMessage({requestId:e,results:d})}catch(s){globalThis.postMessage({requestId:e,results:[],error:s instanceof Error?s.message:"Calculation error"})}else globalThis.postMessage({requestId:e,results:[],error:"Layer embeddings not initialized"});break}case"fieldSearch":{if(t.length>0)try{const s=t.map(l=>{const d=u.get(l);if(!d)return{layerId:l,results:[]};const o=d.map(g=>({name:g.name,vector:g.vector,score:h(i,g.vector)})).filter(({score:g})=>g>=m),b=f(o,n);return{layerId:l,results:b}});globalThis.postMessage({requestId:e,results:s})}catch(s){globalThis.postMessage({requestId:e,results:[],error:s instanceof Error?s.message:"Field search calculation error"})}break}default:console.warn("Unknown message type:",r)}})()})})();
@@ -1 +1,2 @@
1
1
  export declare const replaceReducer: <T>(_prev: T, next: T) => T;
2
+ export declare const mergeReducer: <T extends object>(prev: T, next: Partial<T>) => T;
@@ -1,8 +1,8 @@
1
- import { ChatHistory } from '../../types/types';
1
+ import { AgentExecutionContext } from '../../types/types';
2
2
  export declare const DispatcherGraphState: import('@langchain/langgraph').AnnotationRoot<{
3
- userInput: import('@langchain/langgraph').LastValue<string>;
4
- messages: import('@langchain/langgraph').BinaryOperatorAggregate<ChatHistory, ChatHistory>;
5
- pendingIntents: import('@langchain/langgraph').BinaryOperatorAggregate<string[], string[]>;
6
- currentIntent: import('@langchain/langgraph').BinaryOperatorAggregate<string, string>;
3
+ agentExecutionContext: import('@langchain/langgraph').BaseChannel<AgentExecutionContext, AgentExecutionContext | import('@langchain/langgraph').OverwriteValue<AgentExecutionContext>, unknown>;
4
+ currentIntent: import('@langchain/langgraph').BaseChannel<string, string | import('@langchain/langgraph').OverwriteValue<string>, unknown>;
5
+ requiresFollowUp: import('@langchain/langgraph').BaseChannel<boolean, boolean | import('@langchain/langgraph').OverwriteValue<boolean>, unknown>;
6
+ stepCount: import('@langchain/langgraph').BaseChannel<number, number | import('@langchain/langgraph').OverwriteValue<number>, unknown>;
7
7
  }>;
8
8
  export type DispatcherGraphStateType = typeof DispatcherGraphState.State;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Calculates the cosine similarity between two numeric vectors.
3
+ * * This implementation is safeguarded against zero-magnitudes (returns 0)
4
+ * and ensures the result is clamped between -1 and 1 to account for
5
+ * floating-point precision errors.
6
+ *
7
+ * @param a - The first vector array.
8
+ * @param b - The second vector array.
9
+ * @returns A similarity score from -1 (opposite) to 1 (identical).
10
+ * @throws {Error} If the vectors have different lengths.
11
+ */
12
+ export declare const cosineSimilarity: (a: number[], b: number[]) => number;
@@ -0,0 +1,6 @@
1
+ import { LayersAndFieldsRegistry } from '../types/types';
2
+ import { VectorizedLayer } from './webmapEmbeddings';
3
+ import { WebmapEmbedding } from './webmapSchema';
4
+ import { default as ArcGISMap } from '@arcgis/core/Map.js';
5
+ export declare const validateEmbeddingsResponse: (data: unknown) => WebmapEmbedding;
6
+ export declare const restoreRegistryFromVectorsAndValidation: (vectorizedLayers: VectorizedLayer[], arcgisMap: ArcGISMap) => LayersAndFieldsRegistry;
@@ -1 +1,7 @@
1
+ /**
2
+ * Generates vector embeddings for a given array of strings.
3
+ * * @param {string[]} queries - An array of text strings to be embedded.
4
+ * @returns {Promise<number[][]>} A promise that resolves to an array of embedding vectors.
5
+ * @throws {Error} Throws an error if the embedding model fails to initialize or process the request.
6
+ */
1
7
  export declare const getEmbeddings: (queries: string[]) => Promise<number[][]>;
@@ -0,0 +1,6 @@
1
+ import { default as MapView } from '@arcgis/core/views/MapView.js';
2
+ import { WebmapEmbedding } from './webmapSchema';
3
+ /**
4
+ * Fetches and validates embeddings from a WebMap's portal resources.
5
+ */
6
+ export declare const fetchWebMapEmbeddings: (view: MapView) => Promise<WebmapEmbedding>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Maximal Marginal Relevance selection.
3
+ * Balances relevance to the query against redundancy with already-selected items.
4
+ *
5
+ * @param candidates - Scored candidates with their vectors retained
6
+ * @param topK - How many results to return
7
+ * @param lambda - 0 = max diversity, 1 = max relevance
8
+ */
9
+ export declare const maximalMarginalRelevance: (candidates: {
10
+ name: string;
11
+ vector: number[];
12
+ score: number;
13
+ }[], topK: number, lambda?: number) => {
14
+ name: string;
15
+ score: number;
16
+ }[];
@@ -1,10 +1,13 @@
1
1
  import { WebmapEmbedding } from './webmapSchema';
2
+ import { default as MapView } from '@arcgis/core/views/MapView.js';
3
+ export type VectorizedLayer = WebmapEmbedding["layers"][number];
4
+ export type VectorizedField = VectorizedLayer["fields"][number];
2
5
  /**
3
6
  * Generates a structured, vectorized representation of a Webmap's layers and fields.
4
7
  * * Extracts metadata from the MapView, generates embeddings using a batched
5
8
  * API call, and validates the final object against the WebmapEmbeddingSchema.
6
- * * @param {__esri.MapView} mapView - The ArcGIS MapView containing layers to embed.
9
+ * * @param {MapView} mapView - The ArcGIS MapView containing layers to embed.
7
10
  * @returns {Promise<WebmapEmbedding>} The validated and vectorized webmap data.
8
11
  * @throws {Error} If the generated data fails schema validation.
9
12
  */
10
- export declare const createWebmapEmbeddings: (mapView: __esri.MapView) => Promise<WebmapEmbedding>;
13
+ export declare const createWebmapEmbeddings: (mapView: MapView) => Promise<WebmapEmbedding>;
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  export declare const schemaVersion = "0.1";
3
3
  export declare const dimensions = 1536;
4
4
  export declare const modelProvider = "openai";
5
- export declare const model = "text-embedding-ada-002";
5
+ export declare const model: string;
6
6
  export declare const layerTemplate = "Name: {name}\nTitle: {title}\nDescription: {description}";
7
7
  export declare const fieldTemplate = "Name: {name}\nAlias: {alias}\nDescription: {description}";
8
8
  export declare const WebmapEmbeddingSchema: z.ZodObject<{
@@ -10,131 +10,25 @@ export declare const WebmapEmbeddingSchema: z.ZodObject<{
10
10
  modified: z.ZodNumber;
11
11
  embeddings: z.ZodObject<{
12
12
  modelProvider: z.ZodLiteral<"openai">;
13
- model: z.ZodLiteral<"text-embedding-ada-002">;
13
+ model: z.ZodLiteral<string>;
14
14
  dimensions: z.ZodLiteral<1536>;
15
15
  templates: z.ZodObject<{
16
16
  layer: z.ZodDefault<z.ZodString>;
17
17
  field: z.ZodDefault<z.ZodString>;
18
- }, "strip", z.ZodTypeAny, {
19
- layer: string;
20
- field: string;
21
- }, {
22
- layer?: string | undefined;
23
- field?: string | undefined;
24
- }>;
25
- }, "strip", z.ZodTypeAny, {
26
- model: "text-embedding-ada-002";
27
- dimensions: 1536;
28
- modelProvider: "openai";
29
- templates: {
30
- layer: string;
31
- field: string;
32
- };
33
- }, {
34
- model: "text-embedding-ada-002";
35
- dimensions: 1536;
36
- modelProvider: "openai";
37
- templates: {
38
- layer?: string | undefined;
39
- field?: string | undefined;
40
- };
41
- }>;
42
- layers: z.ZodArray<z.ZodObject<{
18
+ }, z.core.$strip>;
19
+ }, z.core.$strip>;
20
+ layers: z.ZodDefault<z.ZodArray<z.ZodObject<{
43
21
  id: z.ZodString;
44
22
  name: z.ZodString;
45
23
  title: z.ZodCatch<z.ZodString>;
46
24
  description: z.ZodCatch<z.ZodString>;
47
- vector: z.ZodArray<z.ZodNumber, "many">;
25
+ vector: z.ZodArray<z.ZodNumber>;
48
26
  fields: z.ZodArray<z.ZodObject<{
49
27
  name: z.ZodString;
50
28
  alias: z.ZodCatch<z.ZodString>;
51
29
  description: z.ZodCatch<z.ZodString>;
52
- vector: z.ZodArray<z.ZodNumber, "many">;
53
- }, "strip", z.ZodTypeAny, {
54
- name: string;
55
- description: string;
56
- alias: string;
57
- vector: number[];
58
- }, {
59
- name: string;
60
- vector: number[];
61
- description?: unknown;
62
- alias?: unknown;
63
- }>, "many">;
64
- }, "strip", z.ZodTypeAny, {
65
- id: string;
66
- name: string;
67
- title: string;
68
- description: string;
69
- fields: {
70
- name: string;
71
- description: string;
72
- alias: string;
73
- vector: number[];
74
- }[];
75
- vector: number[];
76
- }, {
77
- id: string;
78
- name: string;
79
- fields: {
80
- name: string;
81
- vector: number[];
82
- description?: unknown;
83
- alias?: unknown;
84
- }[];
85
- vector: number[];
86
- title?: unknown;
87
- description?: unknown;
88
- }>, "many">;
89
- }, "strip", z.ZodTypeAny, {
90
- schemaVersion: "0.1";
91
- modified: number;
92
- embeddings: {
93
- model: "text-embedding-ada-002";
94
- dimensions: 1536;
95
- modelProvider: "openai";
96
- templates: {
97
- layer: string;
98
- field: string;
99
- };
100
- };
101
- layers: {
102
- id: string;
103
- name: string;
104
- title: string;
105
- description: string;
106
- fields: {
107
- name: string;
108
- description: string;
109
- alias: string;
110
- vector: number[];
111
- }[];
112
- vector: number[];
113
- }[];
114
- }, {
115
- schemaVersion: "0.1";
116
- modified: number;
117
- embeddings: {
118
- model: "text-embedding-ada-002";
119
- dimensions: 1536;
120
- modelProvider: "openai";
121
- templates: {
122
- layer?: string | undefined;
123
- field?: string | undefined;
124
- };
125
- };
126
- layers: {
127
- id: string;
128
- name: string;
129
- fields: {
130
- name: string;
131
- vector: number[];
132
- description?: unknown;
133
- alias?: unknown;
134
- }[];
135
- vector: number[];
136
- title?: unknown;
137
- description?: unknown;
138
- }[];
139
- }>;
30
+ vector: z.ZodArray<z.ZodNumber>;
31
+ }, z.core.$strip>>;
32
+ }, z.core.$strip>>>;
33
+ }, z.core.$strip>;
140
34
  export type WebmapEmbedding = z.infer<typeof WebmapEmbeddingSchema>;
@@ -0,0 +1,24 @@
1
+ const o = `(function(){"use strict";const h=(a,r)=>{if(a.length!==r.length)throw new Error("Vectors must be the same length");let c=0,t=0,e=0;for(let n=0;n<a.length;++n){const s=a[n],l=r[n];c+=s*l,t+=s*s,e+=l*l}const i=Math.sqrt(t*e);if(i===0)return 0;const m=c/i;return Math.max(-1,Math.min(1,m))},f=(a,r,c=.6)=>{const t=[],e=[...a];for(;t.length<r&&e.length>0;){let i=-1,m=-1/0;for(let n=0;n<e.length;n++){const s=e[n].score,l=t.length===0?0:Math.max(...t.map(o=>h(e[n].vector,o.vector))),d=c*s-(1-c)*l;d>m&&(m=d,i=n)}t.push(e[i]),e.splice(i,1)}return t.map(({name:i,score:m})=>({name:i,score:m}))};let p=[];const u=new Map,v=12,y=10,M=a=>{p=a.layers.map(r=>({id:r.id,vector:r.vector}))},E=a=>{u.clear();for(const r of a.layers){const c=r.fields.map(t=>({name:t.name,vector:t.vector}));u.set(r.id,c)}};globalThis.addEventListener("message",a=>{(async()=>{const{type:r,webmapEmbeddings:c,layerIdForFieldsSearch:t=[],requestId:e,precomputedEmbedding:i,minScore:m=0,topResults:n=v}=a.data;switch(r){case"generateEmbeddings":{c&&(M(c),E(c)),globalThis.postMessage("completed");break}case"layerSearch":{if(p.length>0)try{const s=p.map(o=>({id:o.id,vector:o.vector,score:h(i,o.vector)})),d=f(s.map(o=>({name:o.id,vector:o.vector,score:o.score})),y).map(({name:o,score:b})=>({id:o,score:b}));globalThis.postMessage({requestId:e,results:d})}catch(s){globalThis.postMessage({requestId:e,results:[],error:s instanceof Error?s.message:"Calculation error"})}else globalThis.postMessage({requestId:e,results:[],error:"Layer embeddings not initialized"});break}case"fieldSearch":{if(t.length>0)try{const s=t.map(l=>{const d=u.get(l);if(!d)return{layerId:l,results:[]};const o=d.map(g=>({name:g.name,vector:g.vector,score:h(i,g.vector)})).filter(({score:g})=>g>=m),b=f(o,n);return{layerId:l,results:b}});globalThis.postMessage({requestId:e,results:s})}catch(s){globalThis.postMessage({requestId:e,results:[],error:s instanceof Error?s.message:"Field search calculation error"})}break}default:console.warn("Unknown message type:",r)}})()})})();
2
+ `, s = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", o], { type: "text/javascript;charset=utf-8" });
3
+ function a(r) {
4
+ let e;
5
+ try {
6
+ if (e = s && (self.URL || self.webkitURL).createObjectURL(s), !e) throw "";
7
+ const t = new Worker(e, {
8
+ name: r?.name
9
+ });
10
+ return t.addEventListener("error", () => {
11
+ (self.URL || self.webkitURL).revokeObjectURL(e);
12
+ }), t;
13
+ } catch {
14
+ return new Worker(
15
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(o),
16
+ {
17
+ name: r?.name
18
+ }
19
+ );
20
+ }
21
+ }
22
+ export {
23
+ a as default
24
+ };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,9 @@ export { Orchestrator } from './orchestrator/orchestrator';
2
2
  export { sendTraceMessage, sendUXSuggestion } from './signals';
3
3
  export { invokeTextPrompt, invokeStructuredPrompt, invokeToolPrompt } from './providers/arcgis/promptChain';
4
4
  export { createWebmapEmbeddings } from './embeddings/webmapEmbeddings';
5
- export type { CustomConfigurableType, VectorSearchFieldResults, LayersAndFieldsRegistry, Services, FieldInfo, FieldStatistics, ChatHistory, } from './types/types';
5
+ export { getEmbeddings } from './embeddings/embeddingsUtil';
6
+ export { cosineSimilarity } from './embeddings/cosineSimilarity';
7
+ export type { CustomConfigurableType, VectorSearchFieldResults, LayersAndFieldsRegistry, Services, FieldInfo, FieldStatistics, ChatHistory, AgentExecutionContext, AgentStatus, PriorStep, } from './types/types';
8
+ export type { UXSuggestion } from './orchestrator/orchestratorEvents';
6
9
  export type { UiInterrupt } from './hitl/types';
7
10
  export type { AgentRegistration, AgentWithContext } from './registry/agentRegistry';