@copilotkit/runtime-client-gql 1.50.1 → 1.51.0-next.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +12 -15
  2. package/LICENSE +21 -0
  3. package/dist/{chunk-WUF3XSW5.mjs → chunk-3ETRQN2E.mjs} +2 -2
  4. package/dist/{chunk-WVBWDNR6.mjs → chunk-FVKO3JII.mjs} +4 -4
  5. package/dist/{chunk-WVBWDNR6.mjs.map → chunk-FVKO3JII.mjs.map} +1 -1
  6. package/dist/{chunk-EWRHYLZE.mjs → chunk-KTA7QTTU.mjs} +2 -2
  7. package/dist/{chunk-SVJN2STA.mjs → chunk-L6PM6AT3.mjs} +826 -869
  8. package/dist/chunk-L6PM6AT3.mjs.map +1 -0
  9. package/dist/{chunk-AQ2Y6PF5.mjs → chunk-M5LBGBWO.mjs} +1 -1
  10. package/dist/chunk-M5LBGBWO.mjs.map +1 -0
  11. package/dist/client/CopilotRuntimeClient.js +1 -1
  12. package/dist/client/CopilotRuntimeClient.js.map +1 -1
  13. package/dist/client/CopilotRuntimeClient.mjs +4 -4
  14. package/dist/client/index.js +1 -1
  15. package/dist/client/index.js.map +1 -1
  16. package/dist/client/index.mjs +4 -4
  17. package/dist/graphql/@generated/gql.d.ts +7 -12
  18. package/dist/graphql/@generated/gql.js.map +1 -1
  19. package/dist/graphql/@generated/gql.mjs +1 -1
  20. package/dist/graphql/@generated/index.js.map +1 -1
  21. package/dist/graphql/@generated/index.mjs +1 -1
  22. package/dist/graphql/definitions/mutations.js.map +1 -1
  23. package/dist/graphql/definitions/mutations.mjs +2 -2
  24. package/dist/graphql/definitions/queries.js.map +1 -1
  25. package/dist/graphql/definitions/queries.mjs +2 -2
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +4 -4
  29. package/dist/{magic-string.es-O42ACB6H.mjs → magic-string.es-26DP735G.mjs} +22 -6
  30. package/dist/magic-string.es-26DP735G.mjs.map +1 -0
  31. package/dist/message-conversion/agui-to-gql.mjs +4 -4
  32. package/dist/message-conversion/agui-to-gql.test.js +861 -888
  33. package/dist/message-conversion/agui-to-gql.test.js.map +1 -1
  34. package/dist/message-conversion/agui-to-gql.test.mjs +5 -5
  35. package/dist/message-conversion/gql-to-agui.mjs +4 -4
  36. package/dist/message-conversion/gql-to-agui.test.js +861 -888
  37. package/dist/message-conversion/gql-to-agui.test.js.map +1 -1
  38. package/dist/message-conversion/gql-to-agui.test.mjs +5 -5
  39. package/dist/message-conversion/index.mjs +4 -4
  40. package/dist/message-conversion/roundtrip-conversion.test.js +864 -891
  41. package/dist/message-conversion/roundtrip-conversion.test.js.map +1 -1
  42. package/dist/message-conversion/roundtrip-conversion.test.mjs +5 -5
  43. package/package.json +6 -5
  44. package/src/graphql/@generated/gql.ts +7 -1
  45. package/dist/chunk-AQ2Y6PF5.mjs.map +0 -1
  46. package/dist/chunk-SVJN2STA.mjs.map +0 -1
  47. package/dist/magic-string.es-O42ACB6H.mjs.map +0 -1
  48. /package/dist/{chunk-WUF3XSW5.mjs.map → chunk-3ETRQN2E.mjs.map} +0 -0
  49. /package/dist/{chunk-EWRHYLZE.mjs.map → chunk-KTA7QTTU.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @copilotkit/runtime-client-gql
2
2
 
3
+ ## 1.51.0-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @copilotkit/shared@1.51.0-next.1
8
+
9
+ ## 1.50.2-next.0
10
+
11
+ ### Patch Changes
12
+
13
+ - @copilotkit/shared@1.50.2-next.0
14
+
3
15
  ## 1.50.1
4
16
 
5
17
  ### Patch Changes
@@ -445,7 +457,6 @@
445
457
  - 7bf9dfa: - fix: address issue where catch-all tool renders don't work
446
458
 
447
459
  Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
448
-
449
460
  - @copilotkit/shared@1.10.1
450
461
 
451
462
  ## 1.10.1-next.2
@@ -461,7 +472,6 @@
461
472
  - 76e2603: - fix: make tool call results be structured in generativeUI
462
473
 
463
474
  Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
464
-
465
475
  - @copilotkit/shared@1.10.1-next.1
466
476
 
467
477
  ## 1.10.1-next.0
@@ -471,7 +481,6 @@
471
481
  - 7bf9dfa: - fix: address issue where catch-all tool renders don't work
472
482
 
473
483
  Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
474
-
475
484
  - @copilotkit/shared@1.10.1-next.0
476
485
 
477
486
  ## 1.10.0
@@ -484,14 +493,12 @@
484
493
  agentic runtimes we acquired tech-debt that, with this PR, is being alleviated.
485
494
 
486
495
  As such, the following features have been updated to be completely functional with Headless UI.
487
-
488
496
  - Generative UI
489
497
  - Suggestions
490
498
  - Agentic Generative UI
491
499
  - Interrupts
492
500
 
493
501
  In addition, a variety of QOL changes have been made.
494
-
495
502
  - New AG-UI based message types
496
503
  - Inline code rendering is fixed
497
504
 
@@ -594,14 +601,12 @@
594
601
  agentic runtimes we acquired tech-debt that, with this PR, is being alleviated.
595
602
 
596
603
  As such, the following features have been updated to be completely functional with Headless UI.
597
-
598
604
  - Generative UI
599
605
  - Suggestions
600
606
  - Agentic Generative UI
601
607
  - Interrupts
602
608
 
603
609
  In addition, a variety of QOL changes have been made.
604
-
605
610
  - New AG-UI based message types
606
611
  - Inline code rendering is fixed
607
612
 
@@ -1578,7 +1583,6 @@
1578
1583
  - 0dc0f43: - fix(runtime-client-gql): call controller.close() after suppressing abort errors
1579
1584
 
1580
1585
  Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
1581
-
1582
1586
  - @copilotkit/shared@1.5.15-next.5
1583
1587
 
1584
1588
  ## 1.5.15-next.4
@@ -2010,7 +2014,6 @@
2010
2014
  - e16d95e: New prerelease
2011
2015
  - 1721cbd: Add convertActionsToDynamicStructuredTools to sdk-js
2012
2016
  - CopilotKit Core:
2013
-
2014
2017
  - Improved error messages and overall logs
2015
2018
  - `useCopilotAction.renderAndAwait` renamed to `.renderAndAwaitForResponse` (backwards compatible, will be deprecated in the future)
2016
2019
  - Improved scrolling behavior. It is now possible to scroll up during LLM response generation
@@ -2018,7 +2021,6 @@
2018
2021
  - Updated interfaces for better developer ergonomics
2019
2022
 
2020
2023
  CoAgents:
2021
-
2022
2024
  - Renamed `remoteActions` to `remoteEndpoints` (backwards compatible, will be deprecated in the future)
2023
2025
  - Support for LangGraph Platform in Remote Endpoints
2024
2026
  - LangGraph JS Support for CoAgents (locally via `langgraph dev`, `langgraph up` or deployed to LangGraph Platform)
@@ -2026,7 +2028,6 @@
2026
2028
  - Enhanced state management and message handling
2027
2029
 
2028
2030
  CopilotKid Back-end SDK:
2029
-
2030
2031
  - Released a whole-new `@copilotkit/sdk-js` for building agents with LangGraph JS Support
2031
2032
 
2032
2033
  - 8d0144f: bump
@@ -2393,7 +2394,6 @@ CopilotKid Back-end SDK:
2393
2394
  ### Patch Changes
2394
2395
 
2395
2396
  - inject minified css in bundle
2396
-
2397
2397
  - removes the need to import `styles.css` manually
2398
2398
  - empty `styles.css` included in the build for backwards compatibility
2399
2399
  - uses tsup's `injectStyles` with `postcss` to bundle and minify the CSS, then inject it as a style tag
@@ -2544,7 +2544,6 @@ CopilotKid Back-end SDK:
2544
2544
  ### Major Changes
2545
2545
 
2546
2546
  - b6a4b6eb: V1.0 Release Candidate
2547
-
2548
2547
  - A robust new protocol between the frontend and the Copilot Runtime
2549
2548
  - Support for Copilot Cloud
2550
2549
  - Generative UI
@@ -2552,7 +2551,6 @@ CopilotKid Back-end SDK:
2552
2551
  - OpenAI assistant API streaming
2553
2552
 
2554
2553
  - V1.0 Release
2555
-
2556
2554
  - A robust new protocol between the frontend and the Copilot Runtime
2557
2555
  - Support for Copilot Cloud
2558
2556
  - Generative UI
@@ -2593,7 +2591,6 @@ CopilotKid Back-end SDK:
2593
2591
  ### Major Changes
2594
2592
 
2595
2593
  - V1.0 Release Candidate
2596
-
2597
2594
  - A robust new protocol between the frontend and the Copilot Runtime
2598
2595
  - Support for Copilot Cloud
2599
2596
  - Generative UI
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Atai Barkai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  graphql
3
- } from "./chunk-AQ2Y6PF5.mjs";
3
+ } from "./chunk-M5LBGBWO.mjs";
4
4
 
5
5
  // src/graphql/definitions/queries.ts
6
6
  var getAvailableAgentsQuery = graphql(
@@ -35,4 +35,4 @@ export {
35
35
  getAvailableAgentsQuery,
36
36
  loadAgentStateQuery
37
37
  };
38
- //# sourceMappingURL=chunk-WUF3XSW5.mjs.map
38
+ //# sourceMappingURL=chunk-3ETRQN2E.mjs.map
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  getAvailableAgentsQuery,
3
3
  loadAgentStateQuery
4
- } from "./chunk-WUF3XSW5.mjs";
4
+ } from "./chunk-3ETRQN2E.mjs";
5
5
  import {
6
6
  generateCopilotResponseMutation
7
- } from "./chunk-EWRHYLZE.mjs";
7
+ } from "./chunk-KTA7QTTU.mjs";
8
8
 
9
9
  // src/client/CopilotRuntimeClient.ts
10
10
  import { Client, cacheExchange, fetchExchange } from "@urql/core";
11
11
 
12
12
  // package.json
13
- var version = "1.50.1";
13
+ var version = "1.51.0-next.1";
14
14
 
15
15
  // src/client/CopilotRuntimeClient.ts
16
16
  import {
@@ -162,4 +162,4 @@ var CopilotRuntimeClient = class {
162
162
  export {
163
163
  CopilotRuntimeClient
164
164
  };
165
- //# sourceMappingURL=chunk-WVBWDNR6.mjs.map
165
+ //# sourceMappingURL=chunk-FVKO3JII.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/CopilotRuntimeClient.ts","../package.json"],"sourcesContent":["import { Client, cacheExchange, fetchExchange } from \"@urql/core\";\nimport * as packageJson from \"../../package.json\";\nimport {\n AvailableAgentsQuery,\n GenerateCopilotResponseMutation,\n GenerateCopilotResponseMutationVariables,\n LoadAgentStateQuery,\n} from \"../graphql/@generated/graphql\";\nimport { generateCopilotResponseMutation } from \"../graphql/definitions/mutations\";\nimport { getAvailableAgentsQuery, loadAgentStateQuery } from \"../graphql/definitions/queries\";\nimport { OperationResultSource, OperationResult } from \"urql\";\nimport {\n ResolvedCopilotKitError,\n CopilotKitLowLevelError,\n CopilotKitError,\n CopilotKitVersionMismatchError,\n getPossibleVersionMismatch,\n} from \"@copilotkit/shared\";\n\nconst createFetchFn =\n (signal?: AbortSignal, handleGQLWarning?: (warning: string) => void) =>\n async (...args: Parameters<typeof fetch>) => {\n // @ts-expect-error -- since this is our own header, TS will not recognize\n const publicApiKey = args[1]?.headers?.[\"x-copilotcloud-public-api-key\"];\n try {\n const result = await fetch(args[0], { ...(args[1] ?? {}), signal });\n\n // No mismatch checking if cloud is being used\n const mismatch = publicApiKey\n ? null\n : await getPossibleVersionMismatch({\n runtimeVersion: result.headers.get(\"X-CopilotKit-Runtime-Version\")!,\n runtimeClientGqlVersion: packageJson.version,\n });\n if (result.status !== 200) {\n if (result.status >= 400 && result.status <= 500) {\n if (mismatch) {\n throw new CopilotKitVersionMismatchError(mismatch);\n }\n\n throw new ResolvedCopilotKitError({ status: result.status });\n }\n }\n\n if (mismatch && handleGQLWarning) {\n handleGQLWarning(mismatch.message);\n }\n\n return result;\n } catch (error) {\n // Let abort error pass through. It will be suppressed later\n if (\n (error as Error).message.includes(\"BodyStreamBuffer was aborted\") ||\n (error as Error).message.includes(\"signal is aborted without reason\")\n ) {\n throw error;\n }\n if (error instanceof CopilotKitError) {\n throw error;\n }\n throw new CopilotKitLowLevelError({ error: error as Error, url: args[0] as string });\n }\n };\n\nexport interface CopilotRuntimeClientOptions {\n url: string;\n publicApiKey?: string;\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n handleGQLErrors?: (error: Error) => void;\n handleGQLWarning?: (warning: string) => void;\n}\n\nexport class CopilotRuntimeClient {\n client: Client;\n public handleGQLErrors?: (error: Error) => void;\n public handleGQLWarning?: (warning: string) => void;\n\n constructor(options: CopilotRuntimeClientOptions) {\n const headers: Record<string, string> = {};\n\n this.handleGQLErrors = options.handleGQLErrors;\n this.handleGQLWarning = options.handleGQLWarning;\n\n if (options.headers) {\n Object.assign(headers, options.headers);\n }\n\n if (options.publicApiKey) {\n headers[\"x-copilotcloud-public-api-key\"] = options.publicApiKey;\n }\n\n this.client = new Client({\n url: options.url,\n exchanges: [cacheExchange, fetchExchange],\n fetchOptions: {\n headers: {\n ...headers,\n \"X-CopilotKit-Runtime-Client-GQL-Version\": packageJson.version,\n },\n ...(options.credentials ? { credentials: options.credentials } : {}),\n },\n });\n }\n\n generateCopilotResponse({\n data,\n properties,\n signal,\n }: {\n data: GenerateCopilotResponseMutationVariables[\"data\"];\n properties?: GenerateCopilotResponseMutationVariables[\"properties\"];\n signal?: AbortSignal;\n }) {\n const fetchFn = createFetchFn(signal, this.handleGQLWarning);\n const result = this.client.mutation<\n GenerateCopilotResponseMutation,\n GenerateCopilotResponseMutationVariables\n >(generateCopilotResponseMutation, { data, properties }, { fetch: fetchFn });\n\n return result;\n }\n\n public asStream<S, T>(source: OperationResultSource<OperationResult<S, { data: T }>>) {\n const handleGQLErrors = this.handleGQLErrors;\n return new ReadableStream<S>({\n start(controller) {\n source.subscribe(({ data, hasNext, error }) => {\n if (error) {\n if (\n error.message.includes(\"BodyStreamBuffer was aborted\") ||\n error.message.includes(\"signal is aborted without reason\")\n ) {\n // close the stream if there is no next item\n if (!hasNext) controller.close();\n\n //suppress this specific error\n console.warn(\"Abort error suppressed\");\n return;\n }\n\n // Handle structured errors specially - check if it's a CopilotKitError with visibility\n if ((error as any).extensions?.visibility) {\n // Create a synthetic GraphQL error with the structured error info\n const syntheticError = {\n ...error,\n graphQLErrors: [\n {\n message: error.message,\n extensions: (error as any).extensions,\n },\n ],\n };\n\n if (handleGQLErrors) {\n handleGQLErrors(syntheticError);\n }\n return; // Don't close the stream for structured errors, let the error handler decide\n }\n\n controller.error(error);\n if (handleGQLErrors) {\n handleGQLErrors(error);\n }\n } else {\n controller.enqueue(data);\n if (!hasNext) {\n controller.close();\n }\n }\n });\n },\n });\n }\n\n availableAgents() {\n const fetchFn = createFetchFn();\n return this.client.query<AvailableAgentsQuery>(getAvailableAgentsQuery, {}, { fetch: fetchFn });\n }\n\n loadAgentState(data: { threadId: string; agentName: string }) {\n const fetchFn = createFetchFn();\n const result = this.client.query<LoadAgentStateQuery>(\n loadAgentStateQuery,\n { data },\n { fetch: fetchFn },\n );\n\n // Add error handling for GraphQL errors - similar to generateCopilotResponse\n result\n .toPromise()\n .then(({ error }) => {\n if (error && this.handleGQLErrors) {\n this.handleGQLErrors(error);\n }\n })\n .catch(() => {}); // Suppress promise rejection warnings\n\n return result;\n }\n\n static removeGraphQLTypename(data: any) {\n if (Array.isArray(data)) {\n data.forEach((item) => CopilotRuntimeClient.removeGraphQLTypename(item));\n } else if (typeof data === \"object\" && data !== null) {\n delete data.__typename;\n Object.keys(data).forEach((key) => {\n if (typeof data[key] === \"object\" && data[key] !== null) {\n CopilotRuntimeClient.removeGraphQLTypename(data[key]);\n }\n });\n }\n return data;\n }\n}\n","{\n \"name\": \"@copilotkit/runtime-client-gql\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.50.1\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"pnpm run graphql-codegen && tsup --clean\",\n \"dev\": \"concurrently \\\"pnpm run graphql-codegen:watch\\\" \\\"tsup --watch --no-splitting\\\"\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf ./src/graphql/@generated && rm -rf dist && rm -rf .next\",\n \"graphql-codegen\": \"graphql-codegen -c codegen.ts\",\n \"graphql-codegen:watch\": \"graphql-codegen -c codegen.ts --watch\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"peerDependencies\": {\n \"react\": \"^18 || ^19 || ^19.0.0-rc\"\n },\n \"devDependencies\": {\n \"@copilotkit/runtime\": \"workspace:*\",\n \"@graphql-codegen/cli\": \"^5.0.2\",\n \"@graphql-codegen/client-preset\": \"^4.2.6\",\n \"@graphql-codegen/introspection\": \"^4.0.3\",\n \"@graphql-codegen/typescript\": \"^4.0.7\",\n \"@graphql-codegen/typescript-operations\": \"^4.2.1\",\n \"@graphql-codegen/typescript-urql\": \"^4.0.0\",\n \"@graphql-codegen/urql-introspection\": \"^3.0.0\",\n \"@graphql-typed-document-node/core\": \"^3.2.0\",\n \"@parcel/watcher\": \"^2.4.1\",\n \"@types/node\": \"^20.12.12\",\n \"concurrently\": \"^8.2.2\",\n \"esbuild\": \"^0.23.0\",\n \"graphql\": \"^16.8.1\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"ts-node\": \"^10.9.2\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.4.5\",\n \"vitest\": \"^3.1.3\"\n },\n \"dependencies\": {\n \"@copilotkit/shared\": \"workspace:*\",\n \"@urql/core\": \"^5.0.3\",\n \"untruncate-json\": \"^0.0.1\",\n \"urql\": \"^4.1.0\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,QAAQ,eAAe,qBAAqB;;;ACWnD,cAAW;;;ADAb;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,gBACJ,CAAC,QAAsB,qBACvB,UAAU,SAAmC;AArB/C;AAuBI,QAAM,gBAAe,gBAAK,CAAC,MAAN,mBAAS,YAAT,mBAAmB;AACxC,MAAI;AACF,UAAM,SAAS,MAAM,MAAM,KAAK,CAAC,GAAG,EAAE,GAAI,KAAK,CAAC,KAAK,CAAC,GAAI,OAAO,CAAC;AAGlE,UAAM,WAAW,eACb,OACA,MAAM,2BAA2B;AAAA,MAC/B,gBAAgB,OAAO,QAAQ,IAAI,8BAA8B;AAAA,MACjE,yBAAqC;AAAA,IACvC,CAAC;AACL,QAAI,OAAO,WAAW,KAAK;AACzB,UAAI,OAAO,UAAU,OAAO,OAAO,UAAU,KAAK;AAChD,YAAI,UAAU;AACZ,gBAAM,IAAI,+BAA+B,QAAQ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K,iBAAiB;AACjC,aAAK,gBAAgB,KAAK;AAAA,MAC5B;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AAAA,IAAC,CAAC;AAEjB,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,sBAAsB,MAAW;AACtC,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,QAAQ,CAAC,SAAS,qBAAqB,sBAAsB,IAAI,CAAC;AAAA,IACzE,WAAW,OAAO,SAAS,YAAY,SAAS,MAAM;AACpD,aAAO,KAAK;AACZ,aAAO,KAAK,IAAI,EAAE,QAAQ,CAAC,QAAQ;AACjC,YAAI,OAAO,KAAK,GAAG,MAAM,YAAY,KAAK,GAAG,MAAM,MAAM;AACvD,+BAAqB,sBAAsB,KAAK,GAAG,CAAC;AAAA,QACtD;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/client/CopilotRuntimeClient.ts","../package.json"],"sourcesContent":["import { Client, cacheExchange, fetchExchange } from \"@urql/core\";\nimport * as packageJson from \"../../package.json\";\nimport {\n AvailableAgentsQuery,\n GenerateCopilotResponseMutation,\n GenerateCopilotResponseMutationVariables,\n LoadAgentStateQuery,\n} from \"../graphql/@generated/graphql\";\nimport { generateCopilotResponseMutation } from \"../graphql/definitions/mutations\";\nimport { getAvailableAgentsQuery, loadAgentStateQuery } from \"../graphql/definitions/queries\";\nimport { OperationResultSource, OperationResult } from \"urql\";\nimport {\n ResolvedCopilotKitError,\n CopilotKitLowLevelError,\n CopilotKitError,\n CopilotKitVersionMismatchError,\n getPossibleVersionMismatch,\n} from \"@copilotkit/shared\";\n\nconst createFetchFn =\n (signal?: AbortSignal, handleGQLWarning?: (warning: string) => void) =>\n async (...args: Parameters<typeof fetch>) => {\n // @ts-expect-error -- since this is our own header, TS will not recognize\n const publicApiKey = args[1]?.headers?.[\"x-copilotcloud-public-api-key\"];\n try {\n const result = await fetch(args[0], { ...(args[1] ?? {}), signal });\n\n // No mismatch checking if cloud is being used\n const mismatch = publicApiKey\n ? null\n : await getPossibleVersionMismatch({\n runtimeVersion: result.headers.get(\"X-CopilotKit-Runtime-Version\")!,\n runtimeClientGqlVersion: packageJson.version,\n });\n if (result.status !== 200) {\n if (result.status >= 400 && result.status <= 500) {\n if (mismatch) {\n throw new CopilotKitVersionMismatchError(mismatch);\n }\n\n throw new ResolvedCopilotKitError({ status: result.status });\n }\n }\n\n if (mismatch && handleGQLWarning) {\n handleGQLWarning(mismatch.message);\n }\n\n return result;\n } catch (error) {\n // Let abort error pass through. It will be suppressed later\n if (\n (error as Error).message.includes(\"BodyStreamBuffer was aborted\") ||\n (error as Error).message.includes(\"signal is aborted without reason\")\n ) {\n throw error;\n }\n if (error instanceof CopilotKitError) {\n throw error;\n }\n throw new CopilotKitLowLevelError({ error: error as Error, url: args[0] as string });\n }\n };\n\nexport interface CopilotRuntimeClientOptions {\n url: string;\n publicApiKey?: string;\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n handleGQLErrors?: (error: Error) => void;\n handleGQLWarning?: (warning: string) => void;\n}\n\nexport class CopilotRuntimeClient {\n client: Client;\n public handleGQLErrors?: (error: Error) => void;\n public handleGQLWarning?: (warning: string) => void;\n\n constructor(options: CopilotRuntimeClientOptions) {\n const headers: Record<string, string> = {};\n\n this.handleGQLErrors = options.handleGQLErrors;\n this.handleGQLWarning = options.handleGQLWarning;\n\n if (options.headers) {\n Object.assign(headers, options.headers);\n }\n\n if (options.publicApiKey) {\n headers[\"x-copilotcloud-public-api-key\"] = options.publicApiKey;\n }\n\n this.client = new Client({\n url: options.url,\n exchanges: [cacheExchange, fetchExchange],\n fetchOptions: {\n headers: {\n ...headers,\n \"X-CopilotKit-Runtime-Client-GQL-Version\": packageJson.version,\n },\n ...(options.credentials ? { credentials: options.credentials } : {}),\n },\n });\n }\n\n generateCopilotResponse({\n data,\n properties,\n signal,\n }: {\n data: GenerateCopilotResponseMutationVariables[\"data\"];\n properties?: GenerateCopilotResponseMutationVariables[\"properties\"];\n signal?: AbortSignal;\n }) {\n const fetchFn = createFetchFn(signal, this.handleGQLWarning);\n const result = this.client.mutation<\n GenerateCopilotResponseMutation,\n GenerateCopilotResponseMutationVariables\n >(generateCopilotResponseMutation, { data, properties }, { fetch: fetchFn });\n\n return result;\n }\n\n public asStream<S, T>(source: OperationResultSource<OperationResult<S, { data: T }>>) {\n const handleGQLErrors = this.handleGQLErrors;\n return new ReadableStream<S>({\n start(controller) {\n source.subscribe(({ data, hasNext, error }) => {\n if (error) {\n if (\n error.message.includes(\"BodyStreamBuffer was aborted\") ||\n error.message.includes(\"signal is aborted without reason\")\n ) {\n // close the stream if there is no next item\n if (!hasNext) controller.close();\n\n //suppress this specific error\n console.warn(\"Abort error suppressed\");\n return;\n }\n\n // Handle structured errors specially - check if it's a CopilotKitError with visibility\n if ((error as any).extensions?.visibility) {\n // Create a synthetic GraphQL error with the structured error info\n const syntheticError = {\n ...error,\n graphQLErrors: [\n {\n message: error.message,\n extensions: (error as any).extensions,\n },\n ],\n };\n\n if (handleGQLErrors) {\n handleGQLErrors(syntheticError);\n }\n return; // Don't close the stream for structured errors, let the error handler decide\n }\n\n controller.error(error);\n if (handleGQLErrors) {\n handleGQLErrors(error);\n }\n } else {\n controller.enqueue(data);\n if (!hasNext) {\n controller.close();\n }\n }\n });\n },\n });\n }\n\n availableAgents() {\n const fetchFn = createFetchFn();\n return this.client.query<AvailableAgentsQuery>(getAvailableAgentsQuery, {}, { fetch: fetchFn });\n }\n\n loadAgentState(data: { threadId: string; agentName: string }) {\n const fetchFn = createFetchFn();\n const result = this.client.query<LoadAgentStateQuery>(\n loadAgentStateQuery,\n { data },\n { fetch: fetchFn },\n );\n\n // Add error handling for GraphQL errors - similar to generateCopilotResponse\n result\n .toPromise()\n .then(({ error }) => {\n if (error && this.handleGQLErrors) {\n this.handleGQLErrors(error);\n }\n })\n .catch(() => {}); // Suppress promise rejection warnings\n\n return result;\n }\n\n static removeGraphQLTypename(data: any) {\n if (Array.isArray(data)) {\n data.forEach((item) => CopilotRuntimeClient.removeGraphQLTypename(item));\n } else if (typeof data === \"object\" && data !== null) {\n delete data.__typename;\n Object.keys(data).forEach((key) => {\n if (typeof data[key] === \"object\" && data[key] !== null) {\n CopilotRuntimeClient.removeGraphQLTypename(data[key]);\n }\n });\n }\n return data;\n }\n}\n","{\n \"name\": \"@copilotkit/runtime-client-gql\",\n \"private\": false,\n \"homepage\": \"https://github.com/CopilotKit/CopilotKit\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/CopilotKit/CopilotKit.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"version\": \"1.51.0-next.1\",\n \"sideEffects\": false,\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n }\n },\n \"types\": \"./dist/index.d.ts\",\n \"license\": \"MIT\",\n \"scripts\": {\n \"build\": \"pnpm run graphql-codegen && tsup --clean\",\n \"dev\": \"concurrently \\\"pnpm run graphql-codegen:watch\\\" \\\"tsup --watch --no-splitting\\\"\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"check-types\": \"tsc --noEmit\",\n \"clean\": \"rm -rf .turbo && rm -rf node_modules && rm -rf ./src/graphql/@generated && rm -rf dist && rm -rf .next\",\n \"graphql-codegen\": \"graphql-codegen -c codegen.ts\",\n \"graphql-codegen:watch\": \"graphql-codegen -c codegen.ts --watch\",\n \"link:global\": \"pnpm link --global\",\n \"unlink:global\": \"pnpm unlink --global\"\n },\n \"peerDependencies\": {\n \"@copilotkit/shared\": \"workspace:*\",\n \"react\": \"^18 || ^19 || ^19.0.0-rc\"\n },\n \"devDependencies\": {\n \"@copilotkit/runtime\": \"workspace:*\",\n \"@copilotkit/shared\": \"workspace:*\",\n \"@graphql-codegen/cli\": \"^5.0.2\",\n \"@graphql-codegen/client-preset\": \"^4.2.6\",\n \"@graphql-codegen/introspection\": \"^4.0.3\",\n \"@graphql-codegen/typescript\": \"^4.0.7\",\n \"@graphql-codegen/typescript-operations\": \"^4.2.1\",\n \"@graphql-codegen/typescript-urql\": \"^4.0.0\",\n \"@graphql-codegen/urql-introspection\": \"^3.0.0\",\n \"@graphql-typed-document-node/core\": \"^3.2.0\",\n \"@parcel/watcher\": \"^2.4.1\",\n \"@types/node\": \"^20.12.12\",\n \"concurrently\": \"^8.2.2\",\n \"esbuild\": \"^0.23.0\",\n \"graphql\": \"^16.8.1\",\n \"jest\": \"^29.6.4\",\n \"ts-jest\": \"^29.1.1\",\n \"ts-node\": \"^10.9.2\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.4.5\",\n \"vitest\": \"^3.1.3\"\n },\n \"dependencies\": {\n \"@urql/core\": \"^5.0.3\",\n \"untruncate-json\": \"^0.0.1\",\n \"urql\": \"^4.1.0\"\n },\n \"keywords\": [\n \"copilotkit\",\n \"copilot\",\n \"react\",\n \"nextjs\",\n \"nodejs\",\n \"ai\",\n \"assistant\",\n \"javascript\",\n \"automation\",\n \"textarea\"\n ]\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,QAAQ,eAAe,qBAAqB;;;ACWnD,cAAW;;;ADAb;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,gBACJ,CAAC,QAAsB,qBACvB,UAAU,SAAmC;AArB/C;AAuBI,QAAM,gBAAe,gBAAK,CAAC,MAAN,mBAAS,YAAT,mBAAmB;AACxC,MAAI;AACF,UAAM,SAAS,MAAM,MAAM,KAAK,CAAC,GAAG,EAAE,GAAI,KAAK,CAAC,KAAK,CAAC,GAAI,OAAO,CAAC;AAGlE,UAAM,WAAW,eACb,OACA,MAAM,2BAA2B;AAAA,MAC/B,gBAAgB,OAAO,QAAQ,IAAI,8BAA8B;AAAA,MACjE,yBAAqC;AAAA,IACvC,CAAC;AACL,Q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KAAK;AAAA,MACP,EAAE,OAAO,QAAQ;AAAA,IACnB;AAGA,WACG,UAAU,EACV,KAAK,CAAC,EAAE,MAAM,MAAM;AACnB,UAAI,SAAS,KAAK,iBAAiB;AACjC,aAAK,gBAAgB,KAAK;AAAA,MAC5B;AAAA,IACF,CAAC,EACA,MAAM,MAAM;AAAA,IAAC,CAAC;AAEjB,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,sBAAsB,MAAW;AACtC,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,QAAQ,CAAC,SAAS,qBAAqB,sBAAsB,IAAI,CAAC;AAAA,IACzE,WAAW,OAAO,SAAS,YAAY,SAAS,MAAM;AACpD,aAAO,KAAK;AACZ,aAAO,KAAK,IAAI,EAAE,QAAQ,CAAC,QAAQ;AACjC,YAAI,OAAO,KAAK,GAAG,MAAM,YAAY,KAAK,GAAG,MAAM,MAAM;AACvD,+BAAqB,sBAAsB,KAAK,GAAG,CAAC;AAAA,QACtD;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  graphql
3
- } from "./chunk-AQ2Y6PF5.mjs";
3
+ } from "./chunk-M5LBGBWO.mjs";
4
4
 
5
5
  // src/graphql/definitions/mutations.ts
6
6
  var generateCopilotResponseMutation = graphql(
@@ -138,4 +138,4 @@ var generateCopilotResponseMutation = graphql(
138
138
  export {
139
139
  generateCopilotResponseMutation
140
140
  };
141
- //# sourceMappingURL=chunk-EWRHYLZE.mjs.map
141
+ //# sourceMappingURL=chunk-KTA7QTTU.mjs.map