@ax-llm/ax 9.0.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.
- package/LICENSE +201 -0
- package/README.md +547 -0
- package/build/module/docs/assets/icons.d.ts +1 -0
- package/build/module/docs/assets/icons.js +19 -0
- package/build/module/docs/assets/icons.js.map +1 -0
- package/build/module/docs/assets/main.d.ts +1 -0
- package/build/module/docs/assets/main.js +629 -0
- package/build/module/docs/assets/main.js.map +1 -0
- package/build/module/docs/assets/navigation.d.ts +1 -0
- package/build/module/docs/assets/navigation.js +3 -0
- package/build/module/docs/assets/navigation.js.map +1 -0
- package/build/module/docs/assets/search.d.ts +1 -0
- package/build/module/docs/assets/search.js +3 -0
- package/build/module/docs/assets/search.js.map +1 -0
- package/build/module/src/ai/anthropic/api.d.ts +24 -0
- package/build/module/src/ai/anthropic/api.js +188 -0
- package/build/module/src/ai/anthropic/api.js.map +1 -0
- package/build/module/src/ai/anthropic/index.d.ts +2 -0
- package/build/module/src/ai/anthropic/index.js +3 -0
- package/build/module/src/ai/anthropic/index.js.map +1 -0
- package/build/module/src/ai/anthropic/info.d.ts +2 -0
- package/build/module/src/ai/anthropic/info.js +34 -0
- package/build/module/src/ai/anthropic/info.js.map +1 -0
- package/build/module/src/ai/anthropic/types.d.ts +140 -0
- package/build/module/src/ai/anthropic/types.js +13 -0
- package/build/module/src/ai/anthropic/types.js.map +1 -0
- package/build/module/src/ai/azure-openai/api.d.ts +34 -0
- package/build/module/src/ai/azure-openai/api.js +42 -0
- package/build/module/src/ai/azure-openai/api.js.map +1 -0
- package/build/module/src/ai/azure-openai/index.d.ts +1 -0
- package/build/module/src/ai/azure-openai/index.js +2 -0
- package/build/module/src/ai/azure-openai/index.js.map +1 -0
- package/build/module/src/ai/balance.d.ts +26 -0
- package/build/module/src/ai/balance.js +87 -0
- package/build/module/src/ai/balance.js.map +1 -0
- package/build/module/src/ai/base.d.ts +56 -0
- package/build/module/src/ai/base.js +328 -0
- package/build/module/src/ai/base.js.map +1 -0
- package/build/module/src/ai/cohere/api.d.ts +35 -0
- package/build/module/src/ai/cohere/api.js +214 -0
- package/build/module/src/ai/cohere/api.js.map +1 -0
- package/build/module/src/ai/cohere/index.d.ts +2 -0
- package/build/module/src/ai/cohere/index.js +3 -0
- package/build/module/src/ai/cohere/index.js.map +1 -0
- package/build/module/src/ai/cohere/info.d.ts +2 -0
- package/build/module/src/ai/cohere/info.js +52 -0
- package/build/module/src/ai/cohere/info.js.map +1 -0
- package/build/module/src/ai/cohere/types.d.ts +85 -0
- package/build/module/src/ai/cohere/types.js +23 -0
- package/build/module/src/ai/cohere/types.js.map +1 -0
- package/build/module/src/ai/deepseek/api.d.ts +27 -0
- package/build/module/src/ai/deepseek/api.js +38 -0
- package/build/module/src/ai/deepseek/api.js.map +1 -0
- package/build/module/src/ai/deepseek/index.d.ts +2 -0
- package/build/module/src/ai/deepseek/index.js +3 -0
- package/build/module/src/ai/deepseek/index.js.map +1 -0
- package/build/module/src/ai/deepseek/info.d.ts +2 -0
- package/build/module/src/ai/deepseek/info.js +16 -0
- package/build/module/src/ai/deepseek/info.js.map +1 -0
- package/build/module/src/ai/deepseek/types.d.ts +8 -0
- package/build/module/src/ai/deepseek/types.js +10 -0
- package/build/module/src/ai/deepseek/types.js.map +1 -0
- package/build/module/src/ai/google-gemini/api.d.ts +34 -0
- package/build/module/src/ai/google-gemini/api.js +268 -0
- package/build/module/src/ai/google-gemini/api.js.map +1 -0
- package/build/module/src/ai/google-gemini/index.d.ts +2 -0
- package/build/module/src/ai/google-gemini/index.js +3 -0
- package/build/module/src/ai/google-gemini/index.js.map +1 -0
- package/build/module/src/ai/google-gemini/info.d.ts +6 -0
- package/build/module/src/ai/google-gemini/info.js +29 -0
- package/build/module/src/ai/google-gemini/info.js.map +1 -0
- package/build/module/src/ai/google-gemini/types.d.ts +151 -0
- package/build/module/src/ai/google-gemini/types.js +38 -0
- package/build/module/src/ai/google-gemini/types.js.map +1 -0
- package/build/module/src/ai/groq/api.d.ts +22 -0
- package/build/module/src/ai/groq/api.js +29 -0
- package/build/module/src/ai/groq/api.js.map +1 -0
- package/build/module/src/ai/groq/index.d.ts +1 -0
- package/build/module/src/ai/groq/index.js +2 -0
- package/build/module/src/ai/groq/index.js.map +1 -0
- package/build/module/src/ai/huggingface/api.d.ts +32 -0
- package/build/module/src/ai/huggingface/api.js +99 -0
- package/build/module/src/ai/huggingface/api.js.map +1 -0
- package/build/module/src/ai/huggingface/index.d.ts +2 -0
- package/build/module/src/ai/huggingface/index.js +3 -0
- package/build/module/src/ai/huggingface/index.js.map +1 -0
- package/build/module/src/ai/huggingface/info.d.ts +6 -0
- package/build/module/src/ai/huggingface/info.js +6 -0
- package/build/module/src/ai/huggingface/info.js.map +1 -0
- package/build/module/src/ai/huggingface/types.d.ts +42 -0
- package/build/module/src/ai/huggingface/types.js +9 -0
- package/build/module/src/ai/huggingface/types.js.map +1 -0
- package/build/module/src/ai/index.d.ts +28 -0
- package/build/module/src/ai/index.js +54 -0
- package/build/module/src/ai/index.js.map +1 -0
- package/build/module/src/ai/mistral/api.d.ts +27 -0
- package/build/module/src/ai/mistral/api.js +38 -0
- package/build/module/src/ai/mistral/api.js.map +1 -0
- package/build/module/src/ai/mistral/index.d.ts +2 -0
- package/build/module/src/ai/mistral/index.js +3 -0
- package/build/module/src/ai/mistral/index.js.map +1 -0
- package/build/module/src/ai/mistral/info.d.ts +2 -0
- package/build/module/src/ai/mistral/info.js +34 -0
- package/build/module/src/ai/mistral/info.js.map +1 -0
- package/build/module/src/ai/mistral/types.d.ts +18 -0
- package/build/module/src/ai/mistral/types.js +21 -0
- package/build/module/src/ai/mistral/types.js.map +1 -0
- package/build/module/src/ai/ollama/api.d.ts +24 -0
- package/build/module/src/ai/ollama/api.js +28 -0
- package/build/module/src/ai/ollama/api.js.map +1 -0
- package/build/module/src/ai/ollama/index.d.ts +1 -0
- package/build/module/src/ai/ollama/index.js +2 -0
- package/build/module/src/ai/ollama/index.js.map +1 -0
- package/build/module/src/ai/openai/api.d.ts +49 -0
- package/build/module/src/ai/openai/api.js +333 -0
- package/build/module/src/ai/openai/api.js.map +1 -0
- package/build/module/src/ai/openai/index.d.ts +2 -0
- package/build/module/src/ai/openai/index.js +3 -0
- package/build/module/src/ai/openai/index.js.map +1 -0
- package/build/module/src/ai/openai/info.d.ts +6 -0
- package/build/module/src/ai/openai/info.js +50 -0
- package/build/module/src/ai/openai/info.js.map +1 -0
- package/build/module/src/ai/openai/types.d.ts +192 -0
- package/build/module/src/ai/openai/types.js +35 -0
- package/build/module/src/ai/openai/types.js.map +1 -0
- package/build/module/src/ai/together/api.d.ts +22 -0
- package/build/module/src/ai/together/api.js +29 -0
- package/build/module/src/ai/together/api.js.map +1 -0
- package/build/module/src/ai/together/index.d.ts +1 -0
- package/build/module/src/ai/together/index.js +2 -0
- package/build/module/src/ai/together/index.js.map +1 -0
- package/build/module/src/ai/together/info.d.ts +2 -0
- package/build/module/src/ai/together/info.js +2 -0
- package/build/module/src/ai/together/info.js.map +1 -0
- package/build/module/src/ai/types.d.ts +70 -0
- package/build/module/src/ai/types.js +2 -0
- package/build/module/src/ai/types.js.map +1 -0
- package/build/module/src/ai/util.d.ts +13 -0
- package/build/module/src/ai/util.js +112 -0
- package/build/module/src/ai/util.js.map +1 -0
- package/build/module/src/db/base.d.ts +24 -0
- package/build/module/src/db/base.js +90 -0
- package/build/module/src/db/base.js.map +1 -0
- package/build/module/src/db/cloudflare.d.ts +20 -0
- package/build/module/src/db/cloudflare.js +98 -0
- package/build/module/src/db/cloudflare.js.map +1 -0
- package/build/module/src/db/index.d.ts +12 -0
- package/build/module/src/db/index.js +23 -0
- package/build/module/src/db/index.js.map +1 -0
- package/build/module/src/db/memory.d.ts +23 -0
- package/build/module/src/db/memory.js +125 -0
- package/build/module/src/db/memory.js.map +1 -0
- package/build/module/src/db/pinecone.d.ts +20 -0
- package/build/module/src/db/pinecone.js +71 -0
- package/build/module/src/db/pinecone.js.map +1 -0
- package/build/module/src/db/types.d.ts +35 -0
- package/build/module/src/db/types.js +3 -0
- package/build/module/src/db/types.js.map +1 -0
- package/build/module/src/db/weaviate.d.ts +20 -0
- package/build/module/src/db/weaviate.js +127 -0
- package/build/module/src/db/weaviate.js.map +1 -0
- package/build/module/src/docs/index.d.ts +4 -0
- package/build/module/src/docs/index.js +5 -0
- package/build/module/src/docs/index.js.map +1 -0
- package/build/module/src/docs/manager.d.ts +45 -0
- package/build/module/src/docs/manager.js +159 -0
- package/build/module/src/docs/manager.js.map +1 -0
- package/build/module/src/docs/reranker.d.ts +7 -0
- package/build/module/src/docs/reranker.js +26 -0
- package/build/module/src/docs/reranker.js.map +1 -0
- package/build/module/src/docs/rewriter.d.ts +4 -0
- package/build/module/src/docs/rewriter.js +9 -0
- package/build/module/src/docs/rewriter.js.map +1 -0
- package/build/module/src/docs/tika.d.ts +21 -0
- package/build/module/src/docs/tika.js +46 -0
- package/build/module/src/docs/tika.js.map +1 -0
- package/build/module/src/dsp/asserts.d.ts +32 -0
- package/build/module/src/dsp/asserts.js +88 -0
- package/build/module/src/dsp/asserts.js.map +1 -0
- package/build/module/src/dsp/eval.d.ts +62 -0
- package/build/module/src/dsp/eval.js +120 -0
- package/build/module/src/dsp/eval.js.map +1 -0
- package/build/module/src/dsp/evaluate.d.ts +12 -0
- package/build/module/src/dsp/evaluate.js +32 -0
- package/build/module/src/dsp/evaluate.js.map +1 -0
- package/build/module/src/dsp/extract.d.ts +25 -0
- package/build/module/src/dsp/extract.js +152 -0
- package/build/module/src/dsp/extract.js.map +1 -0
- package/build/module/src/dsp/generate.d.ts +52 -0
- package/build/module/src/dsp/generate.js +335 -0
- package/build/module/src/dsp/generate.js.map +1 -0
- package/build/module/src/dsp/generate.test.d.ts +1 -0
- package/build/module/src/dsp/generate.test.js +41 -0
- package/build/module/src/dsp/generate.test.js.map +1 -0
- package/build/module/src/dsp/index.d.ts +14 -0
- package/build/module/src/dsp/index.js +10 -0
- package/build/module/src/dsp/index.js.map +1 -0
- package/build/module/src/dsp/loader.d.ts +25 -0
- package/build/module/src/dsp/loader.js +87 -0
- package/build/module/src/dsp/loader.js.map +1 -0
- package/build/module/src/dsp/optimize.d.ts +29 -0
- package/build/module/src/dsp/optimize.js +100 -0
- package/build/module/src/dsp/optimize.js.map +1 -0
- package/build/module/src/dsp/parser.d.ts +86 -0
- package/build/module/src/dsp/parser.js +1437 -0
- package/build/module/src/dsp/parser.js.map +1 -0
- package/build/module/src/dsp/program.d.ts +64 -0
- package/build/module/src/dsp/program.js +129 -0
- package/build/module/src/dsp/program.js.map +1 -0
- package/build/module/src/dsp/prompt.d.ts +25 -0
- package/build/module/src/dsp/prompt.js +178 -0
- package/build/module/src/dsp/prompt.js.map +1 -0
- package/build/module/src/dsp/registry.d.ts +6 -0
- package/build/module/src/dsp/registry.js +15 -0
- package/build/module/src/dsp/registry.js.map +1 -0
- package/build/module/src/dsp/router.d.ts +24 -0
- package/build/module/src/dsp/router.js +72 -0
- package/build/module/src/dsp/router.js.map +1 -0
- package/build/module/src/dsp/sig.d.ts +37 -0
- package/build/module/src/dsp/sig.js +160 -0
- package/build/module/src/dsp/sig.js.map +1 -0
- package/build/module/src/dsp/sig.test.d.ts +1 -0
- package/build/module/src/dsp/sig.test.js +25 -0
- package/build/module/src/dsp/sig.test.js.map +1 -0
- package/build/module/src/dsp/stopwords.d.ts +1 -0
- package/build/module/src/dsp/stopwords.js +1163 -0
- package/build/module/src/dsp/stopwords.js.map +1 -0
- package/build/module/src/dsp/strutil.d.ts +9 -0
- package/build/module/src/dsp/strutil.js +52 -0
- package/build/module/src/dsp/strutil.js.map +1 -0
- package/build/module/src/dsp/util.d.ts +1 -0
- package/build/module/src/dsp/util.js +14 -0
- package/build/module/src/dsp/util.js.map +1 -0
- package/build/module/src/examples/agent.d.ts +1 -0
- package/build/module/src/examples/agent.js +24 -0
- package/build/module/src/examples/agent.js.map +1 -0
- package/build/module/src/examples/chain-of-thought.d.ts +1 -0
- package/build/module/src/examples/chain-of-thought.js +18 -0
- package/build/module/src/examples/chain-of-thought.js.map +1 -0
- package/build/module/src/examples/customer-support.d.ts +1 -0
- package/build/module/src/examples/customer-support.js +22 -0
- package/build/module/src/examples/customer-support.js.map +1 -0
- package/build/module/src/examples/fibonacci.d.ts +1 -0
- package/build/module/src/examples/fibonacci.js +9 -0
- package/build/module/src/examples/fibonacci.js.map +1 -0
- package/build/module/src/examples/food-search.d.ts +1 -0
- package/build/module/src/examples/food-search.js +137 -0
- package/build/module/src/examples/food-search.js.map +1 -0
- package/build/module/src/examples/marketing.d.ts +1 -0
- package/build/module/src/examples/marketing.js +26 -0
- package/build/module/src/examples/marketing.js.map +1 -0
- package/build/module/src/examples/meetings.d.ts +1 -0
- package/build/module/src/examples/meetings.js +149 -0
- package/build/module/src/examples/meetings.js.map +1 -0
- package/build/module/src/examples/qna-tune.d.ts +1 -0
- package/build/module/src/examples/qna-tune.js +29 -0
- package/build/module/src/examples/qna-tune.js.map +1 -0
- package/build/module/src/examples/qna-use-tuned.d.ts +1 -0
- package/build/module/src/examples/qna-use-tuned.js +25 -0
- package/build/module/src/examples/qna-use-tuned.js.map +1 -0
- package/build/module/src/examples/rag-docs.d.ts +1 -0
- package/build/module/src/examples/rag-docs.js +14 -0
- package/build/module/src/examples/rag-docs.js.map +1 -0
- package/build/module/src/examples/rag.d.ts +1 -0
- package/build/module/src/examples/rag.js +14 -0
- package/build/module/src/examples/rag.js.map +1 -0
- package/build/module/src/examples/react.d.ts +1 -0
- package/build/module/src/examples/react.js +36 -0
- package/build/module/src/examples/react.js.map +1 -0
- package/build/module/src/examples/routing.d.ts +1 -0
- package/build/module/src/examples/routing.js +48 -0
- package/build/module/src/examples/routing.js.map +1 -0
- package/build/module/src/examples/streaming1.d.ts +1 -0
- package/build/module/src/examples/streaming1.js +15 -0
- package/build/module/src/examples/streaming1.js.map +1 -0
- package/build/module/src/examples/streaming2.d.ts +1 -0
- package/build/module/src/examples/streaming2.js +24 -0
- package/build/module/src/examples/streaming2.js.map +1 -0
- package/build/module/src/examples/summarize.d.ts +1 -0
- package/build/module/src/examples/summarize.js +27 -0
- package/build/module/src/examples/summarize.js.map +1 -0
- package/build/module/src/examples/vectordb.d.ts +1 -0
- package/build/module/src/examples/vectordb.js +14 -0
- package/build/module/src/examples/vectordb.js.map +1 -0
- package/build/module/src/funcs/code.d.ts +10 -0
- package/build/module/src/funcs/code.js +63 -0
- package/build/module/src/funcs/code.js.map +1 -0
- package/build/module/src/funcs/embed.d.ts +8 -0
- package/build/module/src/funcs/embed.js +29 -0
- package/build/module/src/funcs/embed.js.map +1 -0
- package/build/module/src/funcs/index.d.ts +2 -0
- package/build/module/src/funcs/index.js +3 -0
- package/build/module/src/funcs/index.js.map +1 -0
- package/build/module/src/index.d.ts +9 -0
- package/build/module/src/index.js +15 -0
- package/build/module/src/index.js.map +1 -0
- package/build/module/src/prompts/agent.d.ts +24 -0
- package/build/module/src/prompts/agent.js +65 -0
- package/build/module/src/prompts/agent.js.map +1 -0
- package/build/module/src/prompts/cot.d.ts +9 -0
- package/build/module/src/prompts/cot.js +17 -0
- package/build/module/src/prompts/cot.js.map +1 -0
- package/build/module/src/prompts/index.d.ts +4 -0
- package/build/module/src/prompts/index.js +5 -0
- package/build/module/src/prompts/index.js.map +1 -0
- package/build/module/src/prompts/prompts.test.d.ts +1 -0
- package/build/module/src/prompts/prompts.test.js +48 -0
- package/build/module/src/prompts/prompts.test.js.map +1 -0
- package/build/module/src/prompts/rag.d.ts +23 -0
- package/build/module/src/prompts/rag.js +30 -0
- package/build/module/src/prompts/rag.js.map +1 -0
- package/build/module/src/prompts/react.d.ts +8 -0
- package/build/module/src/prompts/react.js +22 -0
- package/build/module/src/prompts/react.js.map +1 -0
- package/build/module/src/text/functions.d.ts +25 -0
- package/build/module/src/text/functions.js +55 -0
- package/build/module/src/text/functions.js.map +1 -0
- package/build/module/src/text/index.d.ts +3 -0
- package/build/module/src/text/index.js +4 -0
- package/build/module/src/text/index.js.map +1 -0
- package/build/module/src/text/jsonschema.d.ts +2 -0
- package/build/module/src/text/jsonschema.js +96 -0
- package/build/module/src/text/jsonschema.js.map +1 -0
- package/build/module/src/text/memory.d.ts +21 -0
- package/build/module/src/text/memory.js +73 -0
- package/build/module/src/text/memory.js.map +1 -0
- package/build/module/src/text/types.d.ts +57 -0
- package/build/module/src/text/types.js +2 -0
- package/build/module/src/text/types.js.map +1 -0
- package/build/module/src/trace/index.d.ts +171 -0
- package/build/module/src/trace/index.js +67 -0
- package/build/module/src/trace/index.js.map +1 -0
- package/build/module/src/types/index.d.ts +81 -0
- package/build/module/src/types/index.js +2 -0
- package/build/module/src/types/index.js.map +1 -0
- package/build/module/src/util/apicall.d.ts +21 -0
- package/build/module/src/util/apicall.js +137 -0
- package/build/module/src/util/apicall.js.map +1 -0
- package/build/module/src/util/log.d.ts +14 -0
- package/build/module/src/util/log.js +30 -0
- package/build/module/src/util/log.js.map +1 -0
- package/build/module/src/util/other.d.ts +1 -0
- package/build/module/src/util/other.js +4 -0
- package/build/module/src/util/other.js.map +1 -0
- package/build/module/src/util/stream.d.ts +10 -0
- package/build/module/src/util/stream.js +28 -0
- package/build/module/src/util/stream.js.map +1 -0
- package/build/module/src/util/transform.d.ts +8 -0
- package/build/module/src/util/transform.js +57 -0
- package/build/module/src/util/transform.js.map +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export declare const SpanAttributes: {
|
|
2
|
+
LLM_SYSTEM: string;
|
|
3
|
+
LLM_REQUEST_MODEL: string;
|
|
4
|
+
LLM_REQUEST_MAX_TOKENS: string;
|
|
5
|
+
LLM_REQUEST_TEMPERATURE: string;
|
|
6
|
+
LLM_REQUEST_TOP_K: string;
|
|
7
|
+
LLM_REQUEST_FREQUENCY_PENALTY: string;
|
|
8
|
+
LLM_REQUEST_PRESENCE_PENALTY: string;
|
|
9
|
+
LLM_REQUEST_STOP_SEQUENCES: string;
|
|
10
|
+
LLM_REQUEST_LLM_IS_STREAMING: string;
|
|
11
|
+
LLM_REQUEST_TOP_P: string;
|
|
12
|
+
LLM_USAGE_PROMPT_TOKENS: string;
|
|
13
|
+
LLM_USAGE_COMPLETION_TOKENS: string;
|
|
14
|
+
DB_SYSTEM: string;
|
|
15
|
+
DB_TABLE: string;
|
|
16
|
+
DB_NAMESPACE: string;
|
|
17
|
+
DB_ID: string;
|
|
18
|
+
DB_QUERY_TEXT: string;
|
|
19
|
+
DB_VECTOR: string;
|
|
20
|
+
DB_OPERATION_NAME: string;
|
|
21
|
+
DB_VECTOR_QUERY_TOP_K: string;
|
|
22
|
+
DB_QUERY_EMBEDDINGS: string;
|
|
23
|
+
DB_QUERY_RESULT: string;
|
|
24
|
+
DB_QUERY_EMBEDDINGS_VECTOR: string;
|
|
25
|
+
DB_QUERY_RESULT_ID: string;
|
|
26
|
+
DB_QUERY_RESULT_SCORE: string;
|
|
27
|
+
DB_QUERY_RESULT_DISTANCE: string;
|
|
28
|
+
DB_QUERY_RESULT_METADATA: string;
|
|
29
|
+
DB_QUERY_RESULT_VECTOR: string;
|
|
30
|
+
DB_QUERY_RESULT_DOCUMENT: string;
|
|
31
|
+
};
|
|
32
|
+
export declare const SpanEvents: {
|
|
33
|
+
LLM_PROMPT: string;
|
|
34
|
+
};
|
|
35
|
+
export declare enum LLMRequestTypeValues {
|
|
36
|
+
COMPLETION = "completion",
|
|
37
|
+
CHAT = "chat",
|
|
38
|
+
RERANK = "rerank",
|
|
39
|
+
UNKNOWN = "unknown"
|
|
40
|
+
}
|
|
41
|
+
export declare enum SpanKindValues {
|
|
42
|
+
WORKFLOW = "workflow",
|
|
43
|
+
TASK = "task",
|
|
44
|
+
AGENT = "agent",
|
|
45
|
+
TOOL = "tool",
|
|
46
|
+
UNKNOWN = "unknown"
|
|
47
|
+
}
|
|
48
|
+
export type AttributeValue = string | number | boolean | undefined | null;
|
|
49
|
+
export interface Attributes {
|
|
50
|
+
[key: string]: AttributeValue;
|
|
51
|
+
}
|
|
52
|
+
export interface TimeInput {
|
|
53
|
+
timestamp: number;
|
|
54
|
+
}
|
|
55
|
+
export interface Exception {
|
|
56
|
+
message: string;
|
|
57
|
+
name: string;
|
|
58
|
+
stack?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface SpanContext {
|
|
61
|
+
traceId: string;
|
|
62
|
+
spanId: string;
|
|
63
|
+
}
|
|
64
|
+
export declare enum SpanStatusCode {
|
|
65
|
+
OK = "OK",
|
|
66
|
+
ERROR = "ERROR"
|
|
67
|
+
}
|
|
68
|
+
export interface SpanStatus {
|
|
69
|
+
code: SpanStatusCode;
|
|
70
|
+
message?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface SpanStatus {
|
|
73
|
+
code: SpanStatusCode;
|
|
74
|
+
description?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface Span {
|
|
77
|
+
addEvent(name: string, attributesOrStartTime?: Readonly<Attributes | TimeInput>, startTime?: Readonly<TimeInput>): Span;
|
|
78
|
+
end(endTime?: Readonly<TimeInput>): void;
|
|
79
|
+
isRecording(): boolean;
|
|
80
|
+
recordException(exception: Readonly<Exception>, time?: Readonly<TimeInput>): void;
|
|
81
|
+
setAttribute(key: string, value: AttributeValue): Span;
|
|
82
|
+
setAttributes(attributes: Attributes): Span;
|
|
83
|
+
setStatus(status: Readonly<SpanStatus>): Span;
|
|
84
|
+
spanContext(): SpanContext;
|
|
85
|
+
updateName(name: string): Span;
|
|
86
|
+
}
|
|
87
|
+
export interface Context {
|
|
88
|
+
/**
|
|
89
|
+
* Deletes a value associated with a key from the context.
|
|
90
|
+
* Returns a new context that inherits from the current context but does not contain the value for the specified key.
|
|
91
|
+
* @param key The symbol key for which to clear the value.
|
|
92
|
+
* @returns A new Context instance without the specified key.
|
|
93
|
+
*/
|
|
94
|
+
deleteValue(key: symbol): Context;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves a value from the context using a symbol as the key.
|
|
97
|
+
* @param key The symbol key which identifies a context value.
|
|
98
|
+
* @returns The value associated with the key, if any; otherwise, undefined.
|
|
99
|
+
*/
|
|
100
|
+
getValue(key: symbol): unknown;
|
|
101
|
+
/**
|
|
102
|
+
* Sets a value in the context for the specified key.
|
|
103
|
+
* Returns a new context that inherits from the current context with the new key-value pair added.
|
|
104
|
+
* @param key The symbol key for which to set the value.
|
|
105
|
+
* @param value The value to set for the given key.
|
|
106
|
+
* @returns A new Context instance with the updated key-value pair.
|
|
107
|
+
*/
|
|
108
|
+
setValue(key: symbol, value: unknown): Context;
|
|
109
|
+
}
|
|
110
|
+
export declare enum SpanKind {
|
|
111
|
+
INTERNAL = "INTERNAL",
|
|
112
|
+
SERVER = "SERVER",
|
|
113
|
+
CLIENT = "CLIENT",
|
|
114
|
+
PRODUCER = "PRODUCER",
|
|
115
|
+
CONSUMER = "CONSUMER"
|
|
116
|
+
}
|
|
117
|
+
export interface Link {
|
|
118
|
+
context: SpanContext;
|
|
119
|
+
attributes?: Attributes;
|
|
120
|
+
}
|
|
121
|
+
export interface SpanOptions {
|
|
122
|
+
/**
|
|
123
|
+
* Optional attributes that can be attached to the Span.
|
|
124
|
+
* @optional
|
|
125
|
+
*/
|
|
126
|
+
attributes?: Attributes;
|
|
127
|
+
/**
|
|
128
|
+
* The kind of span, defaults to SpanKind.INTERNAL if not specified.
|
|
129
|
+
* @optional
|
|
130
|
+
*/
|
|
131
|
+
kind?: SpanKind;
|
|
132
|
+
/**
|
|
133
|
+
* Links that associate this new Span with other Spans.
|
|
134
|
+
* @optional
|
|
135
|
+
*/
|
|
136
|
+
links?: Link[];
|
|
137
|
+
/**
|
|
138
|
+
* Indicates whether the span should be a root span, ignoring any parent span from the context.
|
|
139
|
+
* @optional
|
|
140
|
+
*/
|
|
141
|
+
root?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* A manually specified start time for the span, if required.
|
|
144
|
+
* @optional
|
|
145
|
+
*/
|
|
146
|
+
startTime?: TimeInput;
|
|
147
|
+
}
|
|
148
|
+
export interface Span {
|
|
149
|
+
setStatus(status: Readonly<SpanStatus>): void;
|
|
150
|
+
end(): void;
|
|
151
|
+
}
|
|
152
|
+
export interface Tracer {
|
|
153
|
+
/**
|
|
154
|
+
* Starts a new Span with the specified options and executes the provided function. The span is automatically closed after the function executes.
|
|
155
|
+
* @param name The name of the span.
|
|
156
|
+
* @param options Span options to apply to the span.
|
|
157
|
+
* @param fn The function to execute within the span's context.
|
|
158
|
+
* @returns The return value of the function.
|
|
159
|
+
*/
|
|
160
|
+
startActiveSpan<F extends (span: Span) => unknown>(name: string, options: Readonly<SpanOptions>, fn: F): ReturnType<F>;
|
|
161
|
+
/**
|
|
162
|
+
* Starts a new Span with the specified options and context, then executes the provided function. The span is automatically closed after the function executes.
|
|
163
|
+
* @param name The name of the span.
|
|
164
|
+
* @param options Span options to apply to the span.
|
|
165
|
+
* @param context Context to be used for the span.
|
|
166
|
+
* @param fn The function to execute within the span's context.
|
|
167
|
+
* @returns The return value of the function.
|
|
168
|
+
*/
|
|
169
|
+
startActiveSpan<F extends (span: Span) => unknown>(name: string, options: Readonly<SpanOptions>, context: Context, fn: F): ReturnType<F>;
|
|
170
|
+
startSpan(name: string, options?: Readonly<SpanOptions>, context?: Context): Span;
|
|
171
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export const SpanAttributes = {
|
|
2
|
+
// LLM
|
|
3
|
+
LLM_SYSTEM: 'gen_ai.system',
|
|
4
|
+
LLM_REQUEST_MODEL: 'gen_ai.request.model',
|
|
5
|
+
LLM_REQUEST_MAX_TOKENS: 'gen_ai.request.max_tokens',
|
|
6
|
+
LLM_REQUEST_TEMPERATURE: 'gen_ai.request.temperature',
|
|
7
|
+
LLM_REQUEST_TOP_K: 'gen_ai.request.top_k',
|
|
8
|
+
LLM_REQUEST_FREQUENCY_PENALTY: 'gen_ai.request.frequency_penalty',
|
|
9
|
+
LLM_REQUEST_PRESENCE_PENALTY: 'gen_ai.request.presence_penalty',
|
|
10
|
+
LLM_REQUEST_STOP_SEQUENCES: 'gen_ai.request.stop_sequences',
|
|
11
|
+
LLM_REQUEST_LLM_IS_STREAMING: 'gen_ai.request.llm_is_streaming',
|
|
12
|
+
LLM_REQUEST_TOP_P: 'gen_ai.request.top_p',
|
|
13
|
+
LLM_USAGE_PROMPT_TOKENS: 'gen_ai.usage.prompt_tokens',
|
|
14
|
+
LLM_USAGE_COMPLETION_TOKENS: 'gen_ai.usage.completion_tokens',
|
|
15
|
+
// Vector DB
|
|
16
|
+
DB_SYSTEM: 'db.system',
|
|
17
|
+
DB_TABLE: 'db.table',
|
|
18
|
+
DB_NAMESPACE: 'db.namespace',
|
|
19
|
+
DB_ID: 'db.id',
|
|
20
|
+
DB_QUERY_TEXT: 'db.query.text',
|
|
21
|
+
DB_VECTOR: 'db.vector',
|
|
22
|
+
DB_OPERATION_NAME: 'db.operation.name',
|
|
23
|
+
DB_VECTOR_QUERY_TOP_K: 'db.vector.query.top_k',
|
|
24
|
+
DB_QUERY_EMBEDDINGS: 'db.query.embeddings',
|
|
25
|
+
DB_QUERY_RESULT: 'db.query.result',
|
|
26
|
+
// Query Embeddings
|
|
27
|
+
DB_QUERY_EMBEDDINGS_VECTOR: 'db.query.embeddings.vector',
|
|
28
|
+
// Query Result (canonical format)
|
|
29
|
+
DB_QUERY_RESULT_ID: 'db.query.result.id',
|
|
30
|
+
DB_QUERY_RESULT_SCORE: 'db.query.result.score',
|
|
31
|
+
DB_QUERY_RESULT_DISTANCE: 'db.query.result.distance',
|
|
32
|
+
DB_QUERY_RESULT_METADATA: 'db.query.result.metadata',
|
|
33
|
+
DB_QUERY_RESULT_VECTOR: 'db.query.result.vector',
|
|
34
|
+
DB_QUERY_RESULT_DOCUMENT: 'db.query.result.document'
|
|
35
|
+
};
|
|
36
|
+
export const SpanEvents = {
|
|
37
|
+
LLM_PROMPT: 'gen_ai.prompt'
|
|
38
|
+
};
|
|
39
|
+
export var LLMRequestTypeValues;
|
|
40
|
+
(function (LLMRequestTypeValues) {
|
|
41
|
+
LLMRequestTypeValues["COMPLETION"] = "completion";
|
|
42
|
+
LLMRequestTypeValues["CHAT"] = "chat";
|
|
43
|
+
LLMRequestTypeValues["RERANK"] = "rerank";
|
|
44
|
+
LLMRequestTypeValues["UNKNOWN"] = "unknown";
|
|
45
|
+
})(LLMRequestTypeValues || (LLMRequestTypeValues = {}));
|
|
46
|
+
export var SpanKindValues;
|
|
47
|
+
(function (SpanKindValues) {
|
|
48
|
+
SpanKindValues["WORKFLOW"] = "workflow";
|
|
49
|
+
SpanKindValues["TASK"] = "task";
|
|
50
|
+
SpanKindValues["AGENT"] = "agent";
|
|
51
|
+
SpanKindValues["TOOL"] = "tool";
|
|
52
|
+
SpanKindValues["UNKNOWN"] = "unknown";
|
|
53
|
+
})(SpanKindValues || (SpanKindValues = {}));
|
|
54
|
+
export var SpanStatusCode;
|
|
55
|
+
(function (SpanStatusCode) {
|
|
56
|
+
SpanStatusCode["OK"] = "OK";
|
|
57
|
+
SpanStatusCode["ERROR"] = "ERROR";
|
|
58
|
+
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
59
|
+
export var SpanKind;
|
|
60
|
+
(function (SpanKind) {
|
|
61
|
+
SpanKind["INTERNAL"] = "INTERNAL";
|
|
62
|
+
SpanKind["SERVER"] = "SERVER";
|
|
63
|
+
SpanKind["CLIENT"] = "CLIENT";
|
|
64
|
+
SpanKind["PRODUCER"] = "PRODUCER";
|
|
65
|
+
SpanKind["CONSUMER"] = "CONSUMER";
|
|
66
|
+
})(SpanKind || (SpanKind = {}));
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/trace/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,MAAM;IACN,UAAU,EAAE,eAAe;IAC3B,iBAAiB,EAAE,sBAAsB;IACzC,sBAAsB,EAAE,2BAA2B;IACnD,uBAAuB,EAAE,4BAA4B;IACrD,iBAAiB,EAAE,sBAAsB;IACzC,6BAA6B,EAAE,kCAAkC;IACjE,4BAA4B,EAAE,iCAAiC;IAC/D,0BAA0B,EAAE,+BAA+B;IAC3D,4BAA4B,EAAE,iCAAiC;IAC/D,iBAAiB,EAAE,sBAAsB;IAEzC,uBAAuB,EAAE,4BAA4B;IACrD,2BAA2B,EAAE,gCAAgC;IAE7D,YAAY;IACZ,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;IACpB,YAAY,EAAE,cAAc;IAC5B,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,iBAAiB,EAAE,mBAAmB;IACtC,qBAAqB,EAAE,uBAAuB;IAE9C,mBAAmB,EAAE,qBAAqB;IAC1C,eAAe,EAAE,iBAAiB;IAElC,mBAAmB;IACnB,0BAA0B,EAAE,4BAA4B;IAExD,kCAAkC;IAClC,kBAAkB,EAAE,oBAAoB;IACxC,qBAAqB,EAAE,uBAAuB;IAC9C,wBAAwB,EAAE,0BAA0B;IACpD,wBAAwB,EAAE,0BAA0B;IACpD,sBAAsB,EAAE,wBAAwB;IAChD,wBAAwB,EAAE,0BAA0B;CACrD,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,UAAU,EAAE,eAAe;CAC5B,CAAC;AAEF,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,iDAAyB,CAAA;IACzB,qCAAa,CAAA;IACb,yCAAiB,CAAA;IACjB,2CAAmB,CAAA;AACrB,CAAC,EALW,oBAAoB,KAApB,oBAAoB,QAK/B;AAED,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,uCAAqB,CAAA;IACrB,+BAAa,CAAA;IACb,iCAAe,CAAA;IACf,+BAAa,CAAA;IACb,qCAAmB,CAAA;AACrB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB;AAuBD,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,2BAAS,CAAA;IACT,iCAAe,CAAA;AACjB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AA2DD,MAAM,CAAN,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,iCAAqB,CAAA;IACrB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;AACvB,CAAC,EANW,QAAQ,KAAR,QAAQ,QAMnB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { TextModelConfig, TextModelInfo, TextResponse } from '../ai/types.js';
|
|
2
|
+
import { type FunctionJSONSchema } from '../text/functions.js';
|
|
3
|
+
export type APIError = {
|
|
4
|
+
pathname: string;
|
|
5
|
+
statusCode: number;
|
|
6
|
+
statusMessage?: string;
|
|
7
|
+
headers?: any;
|
|
8
|
+
request: any;
|
|
9
|
+
response: any;
|
|
10
|
+
};
|
|
11
|
+
export type ParsingError = {
|
|
12
|
+
message: string;
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
export type TextModelInfoWithProvider = TextModelInfo & {
|
|
16
|
+
provider: string;
|
|
17
|
+
};
|
|
18
|
+
export type AITextRequestIdentity = {
|
|
19
|
+
user?: string;
|
|
20
|
+
organization?: string;
|
|
21
|
+
};
|
|
22
|
+
export type AITextBaseRequest = {
|
|
23
|
+
identity?: Readonly<AITextRequestIdentity>;
|
|
24
|
+
};
|
|
25
|
+
export type AITextChatRequest = {
|
|
26
|
+
chatPrompt: Readonly<{
|
|
27
|
+
role: 'system';
|
|
28
|
+
content: string;
|
|
29
|
+
} | {
|
|
30
|
+
role: 'user';
|
|
31
|
+
content: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
} | {
|
|
34
|
+
role: 'assistant';
|
|
35
|
+
content: string | null;
|
|
36
|
+
name?: string;
|
|
37
|
+
functionCalls?: {
|
|
38
|
+
id: string;
|
|
39
|
+
type: 'function';
|
|
40
|
+
function: {
|
|
41
|
+
name: string;
|
|
42
|
+
arguments?: string | object;
|
|
43
|
+
};
|
|
44
|
+
}[];
|
|
45
|
+
} | {
|
|
46
|
+
role: 'function';
|
|
47
|
+
content: string;
|
|
48
|
+
functionId: string;
|
|
49
|
+
}>[];
|
|
50
|
+
functions?: Readonly<{
|
|
51
|
+
name: string;
|
|
52
|
+
description: string;
|
|
53
|
+
parameters?: FunctionJSONSchema;
|
|
54
|
+
}>[];
|
|
55
|
+
functionCall?: 'none' | 'auto' | 'required' | {
|
|
56
|
+
type: 'function';
|
|
57
|
+
function: {
|
|
58
|
+
name: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
modelConfig?: Readonly<TextModelConfig>;
|
|
62
|
+
modelInfo?: Readonly<TextModelInfoWithProvider>;
|
|
63
|
+
} & AITextBaseRequest;
|
|
64
|
+
export type AITextEmbedRequest = {
|
|
65
|
+
texts?: readonly string[];
|
|
66
|
+
embedModelInfo?: Readonly<TextModelInfoWithProvider>;
|
|
67
|
+
} & AITextBaseRequest;
|
|
68
|
+
export type AITextTraceStepRequest = AITextChatRequest | AITextEmbedRequest;
|
|
69
|
+
export type AITextTraceStepResponse = Omit<TextResponse, 'sessionId'> & {
|
|
70
|
+
modelResponseTime?: number;
|
|
71
|
+
embedModelResponseTime?: number;
|
|
72
|
+
parsingError?: Readonly<ParsingError>;
|
|
73
|
+
apiError?: Readonly<APIError>;
|
|
74
|
+
};
|
|
75
|
+
export type AITextTraceStep = {
|
|
76
|
+
traceId: string;
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
request: AITextTraceStepRequest;
|
|
79
|
+
response: AITextTraceStepResponse;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import { type ReadableStream } from 'stream/web';
|
|
5
|
+
import type { Span } from '../trace/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Util: API details
|
|
8
|
+
* @export
|
|
9
|
+
*/
|
|
10
|
+
export type API = {
|
|
11
|
+
name?: string;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
put?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const apiCall: <TRequest = unknown, TResponse = unknown>(api: Readonly<API & {
|
|
16
|
+
url: string | URL;
|
|
17
|
+
stream?: boolean;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
fetch?: typeof fetch;
|
|
20
|
+
span?: Span;
|
|
21
|
+
}>, json: TRequest) => Promise<TResponse | ReadableStream<TResponse>>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { TextDecoderStream as TextDecoderStreamNative } from 'stream/web';
|
|
3
|
+
import { TextDecoderStreamPolyfill } from './stream.js';
|
|
4
|
+
import { JSONStringifyStream } from './transform.js';
|
|
5
|
+
const TextDecoderStream = TextDecoderStreamNative ?? TextDecoderStreamPolyfill;
|
|
6
|
+
export const apiCall = async (api, json) => {
|
|
7
|
+
const baseUrl = new URL(process.env.PROXY ?? api.url);
|
|
8
|
+
const apiPath = path.join(baseUrl.pathname, api.name ?? '/', baseUrl.search);
|
|
9
|
+
const apiUrl = new URL(apiPath, baseUrl);
|
|
10
|
+
if (api.span?.isRecording()) {
|
|
11
|
+
api.span.setAttributes({
|
|
12
|
+
'http.request.method': api.put ? 'PUT' : 'POST',
|
|
13
|
+
'url.full': apiUrl.href
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
let res;
|
|
17
|
+
try {
|
|
18
|
+
res = await (api.fetch ?? fetch)(apiUrl, {
|
|
19
|
+
method: api.put ? 'PUT' : 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...api.headers
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify(json)
|
|
25
|
+
});
|
|
26
|
+
if (res.status >= 400) {
|
|
27
|
+
const body = JSON.stringify(await res.json(), null, 2);
|
|
28
|
+
throw new Error(`API Error: ${apiUrl.href}, ${res.status}, ${res.statusText}\n${body}`);
|
|
29
|
+
}
|
|
30
|
+
if (!res.body) {
|
|
31
|
+
throw new Error('Response body is null');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (api.span?.isRecording()) {
|
|
36
|
+
api.span.recordException(e);
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`API Error: ${apiUrl.href}, ${e}`);
|
|
39
|
+
}
|
|
40
|
+
if (!api.stream) {
|
|
41
|
+
return (await res.json());
|
|
42
|
+
}
|
|
43
|
+
const st = res.body
|
|
44
|
+
.pipeThrough(new TextDecoderStream())
|
|
45
|
+
.pipeThrough(new JSONStringifyStream());
|
|
46
|
+
return st;
|
|
47
|
+
};
|
|
48
|
+
// for await (const chunk of res.body as unknown as AsyncIterable<Uint8Array>) {
|
|
49
|
+
// console.log('CHUNK', decoder.decode(chunk));
|
|
50
|
+
// }
|
|
51
|
+
// const res = await axios.post(apiUrl, json, {
|
|
52
|
+
// headers: api.headers,
|
|
53
|
+
// responseType: 'stream'
|
|
54
|
+
// // responseType: api.stream ? 'stream' : 'json'
|
|
55
|
+
// });
|
|
56
|
+
// const res = await request
|
|
57
|
+
// .send(json as object)
|
|
58
|
+
// .set(headers ?? {})
|
|
59
|
+
// .type('json')
|
|
60
|
+
// .accept('json')
|
|
61
|
+
// .retry(3);
|
|
62
|
+
// return res.body;
|
|
63
|
+
// } catch (e) {
|
|
64
|
+
// const err = e as SuperAgentError;
|
|
65
|
+
// throw httpError(`apiCall:`, apiUrl, json, err);
|
|
66
|
+
// }
|
|
67
|
+
/*
|
|
68
|
+
export const apiCallWithUpload = async <
|
|
69
|
+
Request,
|
|
70
|
+
Response,
|
|
71
|
+
APIType extends API & { url: string }
|
|
72
|
+
>(
|
|
73
|
+
api: Readonly<APIType>,
|
|
74
|
+
json: Request,
|
|
75
|
+
file: string
|
|
76
|
+
): Promise<Response> => {
|
|
77
|
+
if (!file) {
|
|
78
|
+
throw new Error('File is required');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const headers = api.headers;
|
|
82
|
+
const baseUrl = api.url;
|
|
83
|
+
const apiPath = api.name ?? '/';
|
|
84
|
+
const apiUrl = new URL(apiPath, baseUrl).toString();
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const data = await superagent
|
|
88
|
+
.post(apiUrl)
|
|
89
|
+
.retry(3)
|
|
90
|
+
.attach('file', file)
|
|
91
|
+
.set(headers ?? {})
|
|
92
|
+
.field(json as { [fieldName: string]: string });
|
|
93
|
+
|
|
94
|
+
return data.body;
|
|
95
|
+
} catch (e) {
|
|
96
|
+
throw httpError('apiCallWithUpload', apiUrl, null, e as SuperAgentError);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
*/
|
|
100
|
+
// export type SuperAgentError = {
|
|
101
|
+
// response: superagent.Response;
|
|
102
|
+
// code: unknown;
|
|
103
|
+
// syscall: unknown;
|
|
104
|
+
// address: unknown;
|
|
105
|
+
// port: unknown;
|
|
106
|
+
// request: unknown;
|
|
107
|
+
// };
|
|
108
|
+
// export const httpError = (
|
|
109
|
+
// message: string,
|
|
110
|
+
// apiUrl: string,
|
|
111
|
+
// json: unknown,
|
|
112
|
+
// { response, code, syscall, address, port }: Readonly<SuperAgentError>
|
|
113
|
+
// ) => {
|
|
114
|
+
// const err = new Error(message) as Error & { data: unknown };
|
|
115
|
+
// if (!response) {
|
|
116
|
+
// err.data = {
|
|
117
|
+
// apiUrl,
|
|
118
|
+
// code,
|
|
119
|
+
// syscall,
|
|
120
|
+
// address,
|
|
121
|
+
// port,
|
|
122
|
+
// request: json
|
|
123
|
+
// };
|
|
124
|
+
// return err;
|
|
125
|
+
// }
|
|
126
|
+
// const { headers, status, body } = response;
|
|
127
|
+
// err.data = {
|
|
128
|
+
// apiUrl,
|
|
129
|
+
// statusCode: status,
|
|
130
|
+
// headers,
|
|
131
|
+
// request: json,
|
|
132
|
+
// response: body,
|
|
133
|
+
// error: body.error
|
|
134
|
+
// };
|
|
135
|
+
// return err;
|
|
136
|
+
// };
|
|
137
|
+
//# sourceMappingURL=apicall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apicall.js","sourceRoot":"","sources":["../../../../src/util/apicall.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class ColorLog {
|
|
2
|
+
private readonly ANSI_WHITE_BRIGHT;
|
|
3
|
+
private readonly ANSI_GREEN_BRIGHT;
|
|
4
|
+
private readonly ANSI_BLUE_BRIGHT;
|
|
5
|
+
private readonly ANSI_YELLOW;
|
|
6
|
+
private readonly ANSI_RED;
|
|
7
|
+
private readonly ANSI_RESET;
|
|
8
|
+
private colorize;
|
|
9
|
+
whiteBright(text: string): string;
|
|
10
|
+
greenBright(text: string): string;
|
|
11
|
+
blueBright(text: string): string;
|
|
12
|
+
yellow(text: string): string;
|
|
13
|
+
red(text: string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class ColorLog {
|
|
2
|
+
// ANSI escape codes for different colors
|
|
3
|
+
ANSI_WHITE_BRIGHT = '\x1b[97m';
|
|
4
|
+
ANSI_GREEN_BRIGHT = '\x1b[92m';
|
|
5
|
+
ANSI_BLUE_BRIGHT = '\x1b[94m';
|
|
6
|
+
ANSI_YELLOW = '\x1b[93m';
|
|
7
|
+
ANSI_RED = '\x1b[91m';
|
|
8
|
+
ANSI_RESET = '\x1b[0m';
|
|
9
|
+
// Method to wrap text with the specified ANSI color code
|
|
10
|
+
colorize(text, colorCode) {
|
|
11
|
+
return `${colorCode}${text}${this.ANSI_RESET}`;
|
|
12
|
+
}
|
|
13
|
+
// Public methods to colorize text in various colors
|
|
14
|
+
whiteBright(text) {
|
|
15
|
+
return this.colorize(text, this.ANSI_WHITE_BRIGHT);
|
|
16
|
+
}
|
|
17
|
+
greenBright(text) {
|
|
18
|
+
return this.colorize(text, this.ANSI_GREEN_BRIGHT);
|
|
19
|
+
}
|
|
20
|
+
blueBright(text) {
|
|
21
|
+
return this.colorize(text, this.ANSI_BLUE_BRIGHT);
|
|
22
|
+
}
|
|
23
|
+
yellow(text) {
|
|
24
|
+
return this.colorize(text, this.ANSI_YELLOW);
|
|
25
|
+
}
|
|
26
|
+
red(text) {
|
|
27
|
+
return this.colorize(text, this.ANSI_RED);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../../src/util/log.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAQ;IACnB,yCAAyC;IACxB,iBAAiB,GAAG,UAAU,CAAC;IAC/B,iBAAiB,GAAG,UAAU,CAAC;IAC/B,gBAAgB,GAAG,UAAU,CAAC;IAC9B,WAAW,GAAG,UAAU,CAAC;IACzB,QAAQ,GAAG,UAAU,CAAC;IACtB,UAAU,GAAG,SAAS,CAAC;IAExC,yDAAyD;IACjD,QAAQ,CAAC,IAAY,EAAE,SAAiB;QAC9C,OAAO,GAAG,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjD,CAAC;IAED,oDAAoD;IAC7C,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACrD,CAAC;IAEM,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACrD,CAAC;IAEM,UAAU,CAAC,IAAY;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACpD,CAAC;IAEM,MAAM,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAEM,GAAG,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"other.js","sourceRoot":"","sources":["../../../../src/util/other.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,EAAU;IACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TransformStream } from 'stream/web';
|
|
3
|
+
export interface TextDecoderCommon {
|
|
4
|
+
readonly encoding: string;
|
|
5
|
+
readonly fatal: boolean;
|
|
6
|
+
readonly ignoreBOM: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class TextDecoderStreamPolyfill extends TransformStream<ArrayBuffer | Uint8Array, string> {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TransformStream } from 'stream/web';
|
|
2
|
+
class TextDecodeTransformer {
|
|
3
|
+
decoder;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.decoder = new TextDecoder();
|
|
6
|
+
}
|
|
7
|
+
transform(chunk, controller) {
|
|
8
|
+
if (!(chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk))) {
|
|
9
|
+
throw new TypeError('Input data must be a BufferSource');
|
|
10
|
+
}
|
|
11
|
+
const text = this.decoder.decode(chunk, { stream: true });
|
|
12
|
+
if (text.length !== 0) {
|
|
13
|
+
controller.enqueue(text);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
flush(controller) {
|
|
17
|
+
const text = this.decoder.decode();
|
|
18
|
+
if (text.length !== 0) {
|
|
19
|
+
controller.enqueue(text);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class TextDecoderStreamPolyfill extends TransformStream {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(new TextDecodeTransformer());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../src/util/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEhB,MAAM,YAAY,CAAC;AAQpB,MAAM,qBAAqB;IAGjB,OAAO,CAAC;IAEhB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IACnC,CAAC;IAED,SAAS,CACP,KAA+B,EAC/B,UAAoD;QAEpD,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACjE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;QAC3D,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAoD;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,eAG9C;IACC;QACE,KAAK,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TransformStream } from 'stream/web';
|
|
3
|
+
export declare class JSONStringifyStream<O> extends TransformStream<string, O> {
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
6
|
+
export declare class RespTransformStream<I, O> extends TransformStream<I, O> {
|
|
7
|
+
constructor(transformFn: (arg0: I) => O, doneCallback?: (args0: readonly O[]) => Promise<void>);
|
|
8
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { TransformStream } from 'stream/web';
|
|
2
|
+
class JSONTransformer {
|
|
3
|
+
async transform(obj, controller) {
|
|
4
|
+
(obj.split('\n') ?? [])
|
|
5
|
+
.map(extractJson)
|
|
6
|
+
.map((v) => {
|
|
7
|
+
try {
|
|
8
|
+
return v && v.length > 0 ? JSON.parse(v) : null;
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
.filter((v) => v)
|
|
15
|
+
.forEach((v) => v && controller.enqueue(v));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class JSONStringifyStream extends TransformStream {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(new JSONTransformer());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class TypeTransformer {
|
|
24
|
+
buffer;
|
|
25
|
+
doneCallback;
|
|
26
|
+
transformFn;
|
|
27
|
+
constructor(transformFn, doneCallback) {
|
|
28
|
+
this.transformFn = transformFn;
|
|
29
|
+
this.doneCallback = doneCallback;
|
|
30
|
+
this.buffer = doneCallback ? [] : undefined;
|
|
31
|
+
}
|
|
32
|
+
async transform(obj, controller) {
|
|
33
|
+
const val = this.transformFn(obj);
|
|
34
|
+
if (val) {
|
|
35
|
+
controller.enqueue(val);
|
|
36
|
+
this.buffer?.push(val);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async flush(controller) {
|
|
40
|
+
await this.doneCallback?.(this.buffer ?? []);
|
|
41
|
+
controller.terminate();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class RespTransformStream extends TransformStream {
|
|
45
|
+
constructor(transformFn, doneCallback) {
|
|
46
|
+
super(new TypeTransformer(transformFn, doneCallback));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const extractJson = (str) => {
|
|
50
|
+
const startIndex = str.indexOf('{');
|
|
51
|
+
const endIndex = str.lastIndexOf('}');
|
|
52
|
+
if (startIndex !== -1 && endIndex !== -1) {
|
|
53
|
+
return str.substring(startIndex, endIndex + 1);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=transform.js.map
|