diff --git a/js/genkit/src/tracing.ts b/js/genkit/src/tracing.ts index 10cdc4a3b..252c8df96 100644 --- a/js/genkit/src/tracing.ts +++ b/js/genkit/src/tracing.ts @@ -18,19 +18,14 @@ export { GenkitSpanProcessorWrapper, InstrumentationLibrarySchema, LinkSchema, - PathMetadata, PathMetadataSchema, SPAN_TYPE_ATTR, SpanContextSchema, - SpanData, SpanDataSchema, - SpanMetadata, SpanMetadataSchema, SpanStatusSchema, TimeEventSchema, - TraceData, TraceDataSchema, - TraceMetadata, TraceMetadataSchema, TraceServerExporter, appendSpan, @@ -46,4 +41,9 @@ export { spanMetadataAls, toDisplayPath, traceMetadataAls, + type PathMetadata, + type SpanData, + type SpanMetadata, + type TraceData, + type TraceMetadata, } from '@genkit-ai/core/tracing'; diff --git a/js/package.json b/js/package.json index 93391cc86..c85bab7cb 100644 --- a/js/package.json +++ b/js/package.json @@ -15,7 +15,8 @@ "pack:ai": "cd ai && pnpm pack --pack-destination ../../dist", "pack:genkit": "cd genkit && pnpm pack --pack-destination ../../dist", "pack:plugins": "for i in plugins/*/; do cd $i && pnpm pack --pack-destination ../../../dist && cd ../..; done", - "test:all": "pnpm -r --workspace-concurrency 0 -F \"./(ai|core|plugins|genkit)/**\" test", + "test:all": "pnpm -r --workspace-concurrency 0 -F \"./(ai|core|plugins|genkit)/**\" test && pnpm test:esm", + "test:esm": "cd testapps/esm && pnpm test", "gendocs": "pnpm build && pnpm typedoc", "typedoc-html": "typedoc --options typedoc.json" }, diff --git a/js/plugins/google-cloud/package.json b/js/plugins/google-cloud/package.json index 03756ebab..4db95bedc 100644 --- a/js/plugins/google-cloud/package.json +++ b/js/plugins/google-cloud/package.json @@ -50,7 +50,6 @@ "winston": "^3.12.0" }, "peerDependencies": { - "@genkit-ai/core": "workspace:*", "genkit": "workspace:*" }, "devDependencies": { diff --git a/js/plugins/google-cloud/src/auth.ts b/js/plugins/google-cloud/src/auth.ts index a75c94fa0..04b3a07d9 100644 --- a/js/plugins/google-cloud/src/auth.ts +++ b/js/plugins/google-cloud/src/auth.ts @@ -15,7 +15,7 @@ */ import { logger } from 'genkit/logging'; import { auth, GoogleAuth } from 'google-auth-library'; -import { GcpPrincipal, GcpTelemetryConfig } from './types'; +import { GcpPrincipal, GcpTelemetryConfig } from './types.js'; /** * Allows Google Cloud credentials to be to passed in "raw" as an environment diff --git a/js/plugins/google-cloud/src/gcpLogger.ts b/js/plugins/google-cloud/src/gcpLogger.ts index 392e4df41..496156eb5 100644 --- a/js/plugins/google-cloud/src/gcpLogger.ts +++ b/js/plugins/google-cloud/src/gcpLogger.ts @@ -18,8 +18,8 @@ import { LoggingWinston } from '@google-cloud/logging-winston'; import { getCurrentEnv } from 'genkit'; import { logger } from 'genkit/logging'; import { Writable } from 'stream'; -import { GcpTelemetryConfig } from './types'; -import { loggingDenied, loggingDeniedHelpText } from './utils'; +import { GcpTelemetryConfig } from './types.js'; +import { loggingDenied, loggingDeniedHelpText } from './utils.js'; /** * Additional streams for writing log data to. Useful for unit testing. diff --git a/js/plugins/google-cloud/src/gcpOpenTelemetry.ts b/js/plugins/google-cloud/src/gcpOpenTelemetry.ts index fd725fc67..38029ef3d 100644 --- a/js/plugins/google-cloud/src/gcpOpenTelemetry.ts +++ b/js/plugins/google-cloud/src/gcpOpenTelemetry.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { logger } from '@genkit-ai/core/logging'; import { ExporterOptions, MetricExporter, @@ -50,20 +49,21 @@ import { SpanExporter, } from '@opentelemetry/sdk-trace-base'; import { GENKIT_VERSION } from 'genkit'; +import { logger } from 'genkit/logging'; import { PathMetadata } from 'genkit/tracing'; import { actionTelemetry } from './telemetry/action.js'; import { engagementTelemetry } from './telemetry/engagement.js'; import { featuresTelemetry } from './telemetry/feature.js'; import { generateTelemetry } from './telemetry/generate.js'; import { pathsTelemetry } from './telemetry/path.js'; -import { GcpTelemetryConfig } from './types'; +import { GcpTelemetryConfig } from './types.js'; import { extractErrorName, metricsDenied, metricsDeniedHelpText, tracingDenied, tracingDeniedHelpText, -} from './utils'; +} from './utils.js'; let metricExporter: PushMetricExporter; let spanProcessor: BatchSpanProcessor; diff --git a/js/plugins/google-cloud/src/index.ts b/js/plugins/google-cloud/src/index.ts index 4c67643c2..856cbd188 100644 --- a/js/plugins/google-cloud/src/index.ts +++ b/js/plugins/google-cloud/src/index.ts @@ -51,4 +51,4 @@ async function configureGcpPlugin( export * from './gcpLogger.js'; export * from './gcpOpenTelemetry.js'; -export { GcpTelemetryConfigOptions } from './types.js'; +export { type GcpTelemetryConfigOptions } from './types.js'; diff --git a/js/plugins/google-cloud/src/telemetry/action.ts b/js/plugins/google-cloud/src/telemetry/action.ts index 2355e6049..5499ae386 100644 --- a/js/plugins/google-cloud/src/telemetry/action.ts +++ b/js/plugins/google-cloud/src/telemetry/action.ts @@ -30,7 +30,7 @@ import { createCommonLogAttributes, extractErrorName, extractOuterFeatureNameFromPath, -} from '../utils'; +} from '../utils.js'; class ActionTelemetry implements Telemetry { /** diff --git a/js/plugins/google-cloud/src/telemetry/defaults.ts b/js/plugins/google-cloud/src/telemetry/defaults.ts index cf0c5604e..4683fc9ae 100644 --- a/js/plugins/google-cloud/src/telemetry/defaults.ts +++ b/js/plugins/google-cloud/src/telemetry/defaults.ts @@ -16,7 +16,7 @@ import { AlwaysOnSampler } from '@opentelemetry/sdk-trace-base'; import { isDevEnv } from 'genkit'; -import { GcpTelemetryConfig, GcpTelemetryConfigOptions } from '../types'; +import { GcpTelemetryConfig, GcpTelemetryConfigOptions } from '../types.js'; /** Consolidated defaults for telemetry configuration. */ diff --git a/js/plugins/google-cloud/src/telemetry/engagement.ts b/js/plugins/google-cloud/src/telemetry/engagement.ts index 467e74dd4..ce3664682 100644 --- a/js/plugins/google-cloud/src/telemetry/engagement.ts +++ b/js/plugins/google-cloud/src/telemetry/engagement.ts @@ -23,8 +23,8 @@ import { MetricCounter, Telemetry, internalMetricNamespaceWrap, -} from '../metrics'; -import { createCommonLogAttributes } from '../utils'; +} from '../metrics.js'; +import { createCommonLogAttributes } from '../utils.js'; class EngagementTelemetry implements Telemetry { /** diff --git a/js/plugins/google-cloud/src/telemetry/feature.ts b/js/plugins/google-cloud/src/telemetry/feature.ts index d8625944c..0763c2437 100644 --- a/js/plugins/google-cloud/src/telemetry/feature.ts +++ b/js/plugins/google-cloud/src/telemetry/feature.ts @@ -25,8 +25,8 @@ import { MetricHistogram, Telemetry, internalMetricNamespaceWrap, -} from '../metrics'; -import { createCommonLogAttributes, extractErrorName } from '../utils'; +} from '../metrics.js'; +import { createCommonLogAttributes, extractErrorName } from '../utils.js'; class FeaturesTelemetry implements Telemetry { /** diff --git a/js/plugins/google-cloud/src/telemetry/generate.ts b/js/plugins/google-cloud/src/telemetry/generate.ts index d7d2f7a51..8b82bb868 100644 --- a/js/plugins/google-cloud/src/telemetry/generate.ts +++ b/js/plugins/google-cloud/src/telemetry/generate.ts @@ -34,12 +34,12 @@ import { MetricCounter, MetricHistogram, Telemetry, -} from '../metrics'; +} from '../metrics.js'; import { createCommonLogAttributes, extractErrorName, extractOuterFeatureNameFromPath, -} from '../utils'; +} from '../utils.js'; type SharedDimensions = { modelName?: string; diff --git a/js/plugins/google-cloud/src/telemetry/path.ts b/js/plugins/google-cloud/src/telemetry/path.ts index a58574475..8c71810e9 100644 --- a/js/plugins/google-cloud/src/telemetry/path.ts +++ b/js/plugins/google-cloud/src/telemetry/path.ts @@ -25,13 +25,13 @@ import { MetricHistogram, Telemetry, internalMetricNamespaceWrap, -} from '../metrics'; +} from '../metrics.js'; import { createCommonLogAttributes, extractErrorMessage, extractErrorName, extractErrorStack, -} from '../utils'; +} from '../utils.js'; class PathsTelemetry implements Telemetry { /** diff --git a/js/plugins/google-cloud/src/utils.ts b/js/plugins/google-cloud/src/utils.ts index 2d9c85f77..bd3f63983 100644 --- a/js/plugins/google-cloud/src/utils.ts +++ b/js/plugins/google-cloud/src/utils.ts @@ -16,7 +16,7 @@ import { TraceFlags } from '@opentelemetry/api'; import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base'; -import { resolveCurrentPrincipal } from './auth'; +import { resolveCurrentPrincipal } from './auth.js'; export function extractOuterFlowNameFromPath(path: string) { if (!path || path === '') { diff --git a/js/plugins/ollama/src/index.ts b/js/plugins/ollama/src/index.ts index 63c998b15..1a934a700 100644 --- a/js/plugins/ollama/src/index.ts +++ b/js/plugins/ollama/src/index.ts @@ -24,13 +24,13 @@ import { MessageData, } from 'genkit/model'; import { GenkitPlugin, genkitPlugin } from 'genkit/plugin'; -import { defineOllamaEmbedder } from './embeddings'; +import { defineOllamaEmbedder } from './embeddings.js'; import { ApiType, ModelDefinition, OllamaPluginParams, RequestHeaders, -} from './types'; +} from './types.js'; export { defineOllamaEmbedder }; diff --git a/js/plugins/vertexai/src/evaluation/index.ts b/js/plugins/vertexai/src/evaluation/index.ts index cba719362..a1f5aba47 100644 --- a/js/plugins/vertexai/src/evaluation/index.ts +++ b/js/plugins/vertexai/src/evaluation/index.ts @@ -20,7 +20,7 @@ import { getDerivedParams } from '../common/index.js'; import { vertexEvaluators } from './evaluation.js'; import { PluginOptions } from './types.js'; export { VertexAIEvaluationMetricType } from './types.js'; -export { PluginOptions }; +export { type PluginOptions }; /** * Add Google Cloud Vertex AI Rerankers API to Genkit. diff --git a/js/plugins/vertexai/src/index.ts b/js/plugins/vertexai/src/index.ts index 1f02101b1..688be3f82 100644 --- a/js/plugins/vertexai/src/index.ts +++ b/js/plugins/vertexai/src/index.ts @@ -40,7 +40,7 @@ import { imagen3Fast, imagenModel, } from './imagen.js'; -export type { PluginOptions } from './common/types.js'; +export { type PluginOptions } from './common/types.js'; export { gemini10Pro, gemini15Flash, @@ -53,6 +53,7 @@ export { textEmbeddingGeckoMultilingual001, textMultilingualEmbedding002, }; + /** * Add Google Cloud Vertex AI to Genkit. Includes Gemini and Imagen models and text embedder. */ diff --git a/js/pnpm-lock.yaml b/js/pnpm-lock.yaml index 0c608e157..aecef0b9b 100644 --- a/js/pnpm-lock.yaml +++ b/js/pnpm-lock.yaml @@ -450,9 +450,6 @@ importers: plugins/google-cloud: dependencies: - '@genkit-ai/core': - specifier: workspace:* - version: link:../../core '@google-cloud/logging-winston': specifier: ^6.0.0 version: 6.0.0(encoding@0.1.13)(winston@3.13.0) @@ -896,6 +893,64 @@ importers: specifier: ^5.3.3 version: 5.4.5 + testapps/esm: + dependencies: + '@genkit-ai/checks': + specifier: workspace:* + version: link:../../plugins/checks + '@genkit-ai/dev-local-vectorstore': + specifier: workspace:* + version: link:../../plugins/dev-local-vectorstore + '@genkit-ai/evaluator': + specifier: workspace:* + version: link:../../plugins/evaluators + '@genkit-ai/firebase': + specifier: workspace:* + version: link:../../plugins/firebase + '@genkit-ai/google-cloud': + specifier: workspace:* + version: link:../../plugins/google-cloud + '@genkit-ai/googleai': + specifier: workspace:* + version: link:../../plugins/googleai + '@genkit-ai/vertexai': + specifier: workspace:* + version: link:../../plugins/vertexai + firebase-admin: + specifier: '>=12.2' + version: 12.3.1(encoding@0.1.13) + genkit: + specifier: workspace:* + version: link:../../genkit + genkitx-chromadb: + specifier: workspace:* + version: link:../../plugins/chroma + genkitx-ollama: + specifier: workspace:* + version: link:../../plugins/ollama + genkitx-pinecone: + specifier: workspace:* + version: link:../../plugins/pinecone + google-auth-library: + specifier: ^9.6.3 + version: 9.14.2(encoding@0.1.13) + devDependencies: + '@types/pdf-parse': + specifier: ^1.1.4 + version: 1.1.4 + cross-env: + specifier: ^7.0.3 + version: 7.0.3 + rimraf: + specifier: ^6.0.1 + version: 6.0.1 + tsx: + specifier: ^4.19.1 + version: 4.19.2 + typescript: + specifier: ^5.3.3 + version: 5.6.3 + testapps/evals: dependencies: '@genkit-ai/dev-local-vectorstore': diff --git a/js/testapps/esm/.gitignore b/js/testapps/esm/.gitignore new file mode 100644 index 000000000..968c2e92b --- /dev/null +++ b/js/testapps/esm/.gitignore @@ -0,0 +1 @@ +.genkit \ No newline at end of file diff --git a/js/testapps/esm/docs/flume-java.pdf b/js/testapps/esm/docs/flume-java.pdf new file mode 100644 index 000000000..131526cb5 Binary files /dev/null and b/js/testapps/esm/docs/flume-java.pdf differ diff --git a/js/testapps/esm/package.json b/js/testapps/esm/package.json new file mode 100644 index 000000000..26c62e330 --- /dev/null +++ b/js/testapps/esm/package.json @@ -0,0 +1,42 @@ +{ + "name": "rag", + "version": "1.0.0", + "description": "", + "main": "lib/index.js", + "type": "module", + "scripts": { + "start": "node lib/index.js", + "dev": "tsx --watch src/index.ts", + "genkit:dev": "cross-env GENKIT_ENV=dev pnpm dev", + "compile": "tsc", + "build": "pnpm build:clean && pnpm compile", + "build:clean": "rimraf ./lib", + "build:watch": "tsc --watch", + "test": "pnpm build && node lib/index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@genkit-ai/checks": "workspace:*", + "@genkit-ai/dev-local-vectorstore": "workspace:*", + "@genkit-ai/evaluator": "workspace:*", + "@genkit-ai/firebase": "workspace:*", + "@genkit-ai/google-cloud": "workspace:*", + "@genkit-ai/googleai": "workspace:*", + "@genkit-ai/vertexai": "workspace:*", + "firebase-admin": ">=12.2", + "genkit": "workspace:*", + "genkitx-chromadb": "workspace:*", + "genkitx-ollama": "workspace:*", + "genkitx-pinecone": "workspace:*", + "google-auth-library": "^9.6.3" + }, + "devDependencies": { + "@types/pdf-parse": "^1.1.4", + "cross-env": "^7.0.3", + "rimraf": "^6.0.1", + "tsx": "^4.19.1", + "typescript": "^5.3.3" + } +} diff --git a/js/testapps/esm/prompts/myPrompt.prompt b/js/testapps/esm/prompts/myPrompt.prompt new file mode 100644 index 000000000..c6ffa8db4 --- /dev/null +++ b/js/testapps/esm/prompts/myPrompt.prompt @@ -0,0 +1 @@ +{{ role "system" }} your name is {{ @state.userName }}, always introduce yourself) \ No newline at end of file diff --git a/js/testapps/esm/src/index.ts b/js/testapps/esm/src/index.ts new file mode 100644 index 000000000..bf46617be --- /dev/null +++ b/js/testapps/esm/src/index.ts @@ -0,0 +1,46 @@ +/** + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { checks } from '@genkit-ai/checks'; +import { devLocalVectorstore } from '@genkit-ai/dev-local-vectorstore'; +import { genkitEval } from '@genkit-ai/evaluator'; +import { enableFirebaseTelemetry } from '@genkit-ai/firebase'; +import { enableGoogleCloudTelemetry } from '@genkit-ai/google-cloud'; +import { googleAI } from '@genkit-ai/googleai'; +import { vertexAI } from '@genkit-ai/vertexai'; +import { vertexAIEvaluation } from '@genkit-ai/vertexai/evaluation'; +import { vertexAIModelGarden } from '@genkit-ai/vertexai/modelgarden'; +import { vertexAIRerankers } from '@genkit-ai/vertexai/rerankers'; +import { genkit } from 'genkit'; +import { chroma } from 'genkitx-chromadb'; +import { ollama } from 'genkitx-ollama'; +import { pinecone } from 'genkitx-pinecone'; + +enableFirebaseTelemetry; +enableGoogleCloudTelemetry; +checks; +googleAI; +vertexAI; +vertexAIModelGarden; +vertexAIEvaluation; +vertexAIRerankers; +ollama; +pinecone; +chroma; +devLocalVectorstore; +genkitEval; + +export const ai = genkit({}); diff --git a/js/testapps/esm/tsconfig.json b/js/testapps/esm/tsconfig.json new file mode 100644 index 000000000..ca7f67edc --- /dev/null +++ b/js/testapps/esm/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "es2022", + "moduleResolution": "bundler", + "noImplicitReturns": true, + "noUnusedLocals": false, + "outDir": "lib", + "sourceMap": true, + "strict": true, + "skipLibCheck": true + }, + "compileOnSave": true, + "include": ["src"] +}