@meistrari/tela-sdk-js 2.2.1 → 2.3.1

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/dist/index.cjs CHANGED
@@ -24,7 +24,7 @@ const z__default = /*#__PURE__*/_interopDefaultCompat(z);
24
24
  const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
25
25
  const Emittery__default = /*#__PURE__*/_interopDefaultCompat(Emittery);
26
26
 
27
- const version = "2.2.1";
27
+ const version = "2.3.1";
28
28
 
29
29
  var __defProp$7 = Object.defineProperty;
30
30
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -739,6 +739,33 @@ var __publicField$5 = (obj, key, value) => {
739
739
  __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
740
740
  return value;
741
741
  };
742
+ function tryGetResponseHeaders(response) {
743
+ try {
744
+ if (typeof response.headers.toJSON === "function") {
745
+ return response.headers.toJSON();
746
+ }
747
+ if ("entries" in response.headers && typeof response.headers.entries === "function") {
748
+ return Object.fromEntries(response.headers.entries());
749
+ }
750
+ if (typeof response.headers.forEach === "function") {
751
+ const headers = {};
752
+ response.headers.forEach((value, key) => {
753
+ headers[key] = value;
754
+ });
755
+ return headers;
756
+ }
757
+ if (response.headers && typeof response.headers[Symbol.iterator] === "function") {
758
+ const headers = {};
759
+ for (const [key, value] of response.headers) {
760
+ headers[key] = value;
761
+ }
762
+ return headers;
763
+ }
764
+ return {};
765
+ } catch {
766
+ return {};
767
+ }
768
+ }
742
769
  async function defaultParseResponse(props) {
743
770
  const { response } = props;
744
771
  if (props.options.stream) {
@@ -753,7 +780,7 @@ async function defaultParseResponse(props) {
753
780
  if (isJSON) {
754
781
  const json = await response.json();
755
782
  debug("response", response.status, response.url, response.headers, json);
756
- return transformObjectFromSnakeCaseToCamelCase(json, DEFAULT_FIELDS_TRANSFORMATION_EXCLUSIONS);
783
+ return transformObjectFromSnakeCaseToCamelCase({ ...json, headers: tryGetResponseHeaders(response) }, DEFAULT_FIELDS_TRANSFORMATION_EXCLUSIONS);
757
784
  }
758
785
  const text = await response.text();
759
786
  debug("response", response.status, response.url, response.headers, text);
@@ -1939,11 +1966,11 @@ class CanvasExecution extends Emittery__default {
1939
1966
  }).then((response) => {
1940
1967
  this._id = response.id;
1941
1968
  this._rawResultValue = response;
1942
- return getResultFromPollingResponse(response);
1943
- }).then((content) => {
1969
+ return { content: getResultFromPollingResponse(response), response };
1970
+ }).then(({ content, response }) => {
1944
1971
  const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
1945
1972
  this.status = "succeeded";
1946
- this.emit("success", validatedContent);
1973
+ this.emit("success", { ...validatedContent, headers: response?.headers ?? {} });
1947
1974
  return validatedContent;
1948
1975
  }).catch((error) => {
1949
1976
  this.status = "failed";
@@ -1980,7 +2007,8 @@ class CanvasExecution extends Emittery__default {
1980
2007
  id: response.id,
1981
2008
  status: response.status,
1982
2009
  outputContent: response.output_content,
1983
- rawOutput: response.raw_output
2010
+ rawOutput: response.raw_output,
2011
+ headers: response.headers
1984
2012
  });
1985
2013
  return response;
1986
2014
  });
@@ -2045,7 +2073,7 @@ class CanvasExecution extends Emittery__default {
2045
2073
  };
2046
2074
  }
2047
2075
  this._rawResultValue = response;
2048
- this.emit("success", getResultFromPollingResponse(response));
2076
+ this.emit("success", { ...getResultFromPollingResponse(response), headers: response?.headers ?? {} });
2049
2077
  return {
2050
2078
  done: response.status === "succeeded",
2051
2079
  value: getResultFromPollingResponse(response)
package/dist/index.d.cts CHANGED
@@ -663,8 +663,12 @@ type ExecutionParams = AsyncExecutionParams | StreamExecutionParams | SyncExecut
663
663
  */
664
664
  type CanvasExecutionResult<TParams, TOutput = unknown> = TParams extends StreamExecutionParams ? AsyncGenerator<Partial<TOutput>> : Promise<TOutput>;
665
665
  type CanvasExecutionEvents<TOutput> = {
666
- poll: AsyncCompletionPollingResult<TOutput>;
667
- success: TOutput;
666
+ poll: AsyncCompletionPollingResult<TOutput> & {
667
+ headers: Record<string, string>;
668
+ };
669
+ success: TOutput & {
670
+ headers: Record<string, string>;
671
+ };
668
672
  error: ExecutionFailedError;
669
673
  statusChange: ExecutionStatus;
670
674
  };
@@ -867,7 +871,9 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
867
871
  *
868
872
  * @returns A promise or async generator depending on execution mode.
869
873
  */
870
- start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult>;
874
+ start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult & {
875
+ headers: Record<string, string>;
876
+ }>;
871
877
  /**
872
878
  * Gets the execution result. For async executions, automatically starts polling.
873
879
  * For sync executions, returns the result promise. For streams, returns the generator.
package/dist/index.d.mts CHANGED
@@ -663,8 +663,12 @@ type ExecutionParams = AsyncExecutionParams | StreamExecutionParams | SyncExecut
663
663
  */
664
664
  type CanvasExecutionResult<TParams, TOutput = unknown> = TParams extends StreamExecutionParams ? AsyncGenerator<Partial<TOutput>> : Promise<TOutput>;
665
665
  type CanvasExecutionEvents<TOutput> = {
666
- poll: AsyncCompletionPollingResult<TOutput>;
667
- success: TOutput;
666
+ poll: AsyncCompletionPollingResult<TOutput> & {
667
+ headers: Record<string, string>;
668
+ };
669
+ success: TOutput & {
670
+ headers: Record<string, string>;
671
+ };
668
672
  error: ExecutionFailedError;
669
673
  statusChange: ExecutionStatus;
670
674
  };
@@ -867,7 +871,9 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
867
871
  *
868
872
  * @returns A promise or async generator depending on execution mode.
869
873
  */
870
- start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult>;
874
+ start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult & {
875
+ headers: Record<string, string>;
876
+ }>;
871
877
  /**
872
878
  * Gets the execution result. For async executions, automatically starts polling.
873
879
  * For sync executions, returns the result promise. For streams, returns the generator.
package/dist/index.d.ts CHANGED
@@ -663,8 +663,12 @@ type ExecutionParams = AsyncExecutionParams | StreamExecutionParams | SyncExecut
663
663
  */
664
664
  type CanvasExecutionResult<TParams, TOutput = unknown> = TParams extends StreamExecutionParams ? AsyncGenerator<Partial<TOutput>> : Promise<TOutput>;
665
665
  type CanvasExecutionEvents<TOutput> = {
666
- poll: AsyncCompletionPollingResult<TOutput>;
667
- success: TOutput;
666
+ poll: AsyncCompletionPollingResult<TOutput> & {
667
+ headers: Record<string, string>;
668
+ };
669
+ success: TOutput & {
670
+ headers: Record<string, string>;
671
+ };
668
672
  error: ExecutionFailedError;
669
673
  statusChange: ExecutionStatus;
670
674
  };
@@ -867,7 +871,9 @@ declare class CanvasExecution<TParams extends ExecutionParams = SyncExecutionPar
867
871
  *
868
872
  * @returns A promise or async generator depending on execution mode.
869
873
  */
870
- start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult>;
874
+ start(): Promise<CanvasExecutionResult<TParams, TOutput>> | AsyncGenerator<Partial<TOutput>, any, any> | Promise<AsyncGenerator<Partial<TOutput>, any, any>> | Promise<AsyncCompletionCreateResult & {
875
+ headers: Record<string, string>;
876
+ }>;
871
877
  /**
872
878
  * Gets the execution result. For async executions, automatically starts polling.
873
879
  * For sync executions, returns the result promise. For streams, returns the generator.
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import * as z from 'zod';
4
4
  import z__default, { z as z$1, ZodError } from 'zod';
5
5
  import Emittery from 'emittery';
6
6
 
7
- const version = "2.2.1";
7
+ const version = "2.3.1";
8
8
 
9
9
  var __defProp$7 = Object.defineProperty;
10
10
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -719,6 +719,33 @@ var __publicField$5 = (obj, key, value) => {
719
719
  __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
720
720
  return value;
721
721
  };
722
+ function tryGetResponseHeaders(response) {
723
+ try {
724
+ if (typeof response.headers.toJSON === "function") {
725
+ return response.headers.toJSON();
726
+ }
727
+ if ("entries" in response.headers && typeof response.headers.entries === "function") {
728
+ return Object.fromEntries(response.headers.entries());
729
+ }
730
+ if (typeof response.headers.forEach === "function") {
731
+ const headers = {};
732
+ response.headers.forEach((value, key) => {
733
+ headers[key] = value;
734
+ });
735
+ return headers;
736
+ }
737
+ if (response.headers && typeof response.headers[Symbol.iterator] === "function") {
738
+ const headers = {};
739
+ for (const [key, value] of response.headers) {
740
+ headers[key] = value;
741
+ }
742
+ return headers;
743
+ }
744
+ return {};
745
+ } catch {
746
+ return {};
747
+ }
748
+ }
722
749
  async function defaultParseResponse(props) {
723
750
  const { response } = props;
724
751
  if (props.options.stream) {
@@ -733,7 +760,7 @@ async function defaultParseResponse(props) {
733
760
  if (isJSON) {
734
761
  const json = await response.json();
735
762
  debug("response", response.status, response.url, response.headers, json);
736
- return transformObjectFromSnakeCaseToCamelCase(json, DEFAULT_FIELDS_TRANSFORMATION_EXCLUSIONS);
763
+ return transformObjectFromSnakeCaseToCamelCase({ ...json, headers: tryGetResponseHeaders(response) }, DEFAULT_FIELDS_TRANSFORMATION_EXCLUSIONS);
737
764
  }
738
765
  const text = await response.text();
739
766
  debug("response", response.status, response.url, response.headers, text);
@@ -1919,11 +1946,11 @@ class CanvasExecution extends Emittery {
1919
1946
  }).then((response) => {
1920
1947
  this._id = response.id;
1921
1948
  this._rawResultValue = response;
1922
- return getResultFromPollingResponse(response);
1923
- }).then((content) => {
1949
+ return { content: getResultFromPollingResponse(response), response };
1950
+ }).then(({ content, response }) => {
1924
1951
  const validatedContent = this._skipResultValidation || !(this._outputSchema instanceof z__default.ZodType) ? content : this._outputSchema.parse(content);
1925
1952
  this.status = "succeeded";
1926
- this.emit("success", validatedContent);
1953
+ this.emit("success", { ...validatedContent, headers: response?.headers ?? {} });
1927
1954
  return validatedContent;
1928
1955
  }).catch((error) => {
1929
1956
  this.status = "failed";
@@ -1960,7 +1987,8 @@ class CanvasExecution extends Emittery {
1960
1987
  id: response.id,
1961
1988
  status: response.status,
1962
1989
  outputContent: response.output_content,
1963
- rawOutput: response.raw_output
1990
+ rawOutput: response.raw_output,
1991
+ headers: response.headers
1964
1992
  });
1965
1993
  return response;
1966
1994
  });
@@ -2025,7 +2053,7 @@ class CanvasExecution extends Emittery {
2025
2053
  };
2026
2054
  }
2027
2055
  this._rawResultValue = response;
2028
- this.emit("success", getResultFromPollingResponse(response));
2056
+ this.emit("success", { ...getResultFromPollingResponse(response), headers: response?.headers ?? {} });
2029
2057
  return {
2030
2058
  done: response.status === "succeeded",
2031
2059
  value: getResultFromPollingResponse(response)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/tela-sdk-js",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/meistrari/tela-sdk-js.git"