Skip to content

Latest commit

 

History

History

codewhisperer-streaming

@amzn/codewhisperer-streaming

Description

AWS SDK for JavaScript CodeWhispererStreaming Client for Node.js, Browser and React Native.

Installing

To install this package, simply type add or install @amzn/codewhisperer-streaming using your favorite package manager:

  • npm install @amzn/codewhisperer-streaming
  • yarn add @amzn/codewhisperer-streaming
  • pnpm add @amzn/codewhisperer-streaming

Getting Started

Import

The AWS SDK is modulized by clients and commands. To send a request, you only need to import the CodeWhispererStreamingClient and the commands you need, for example SendMessageCommand:

// ES5 example
const { CodeWhispererStreamingClient, SendMessageCommand } = require("@amzn/codewhisperer-streaming");
// ES6+ example
import { CodeWhispererStreamingClient, SendMessageCommand } from "@amzn/codewhisperer-streaming";

Usage

To send a request, you:

  • Initiate client with configuration (e.g. credentials, region).
  • Initiate command with input parameters.
  • Call send operation on client with command object as input.
  • If you are using a custom http handler, you may call destroy() to close open connections.
// a client can be shared by different commands.
const client = new CodeWhispererStreamingClient({ region: "REGION" });

const params = { /** input parameters */ };
const command = new SendMessageCommand(params);

Async/await

We recommend using await operator to wait for the promise returned by send operation as follows:

// async/await.
try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  // error handling.
} finally {
  // finally.
}

Async-await is clean, concise, intuitive, easy to debug and has better error handling as compared to using Promise chains or callbacks.

Promises

You can also use Promise chaining to execute send operation.

client.send(command).then(
  (data) => {
    // process data.
  },
  (error) => {
    // error handling.
  }
);

Promises can also be called using .catch() and .finally() as follows:

client
  .send(command)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  })
  .finally(() => {
    // finally.
  });

Callbacks

We do not recommend using callbacks because of callback hell, but they are supported by the send operation.

// callbacks.
client.send(command, (err, data) => {
  // process err and data.
});

v2 compatible style

The client can also send requests using v2 compatible style. However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post on modular packages in AWS SDK for JavaScript

import * as AWS from "@amzn/codewhisperer-streaming";
const client = new AWS.CodeWhispererStreaming({ region: "REGION" });

// async/await.
try {
  const data = await client.sendMessage(params);
  // process data.
} catch (error) {
  // error handling.
}

// Promises.
client
  .sendMessage(params)
  .then((data) => {
    // process data.
  })
  .catch((error) => {
    // error handling.
  });

// callbacks.
client.sendMessage(params, (err, data) => {
  // process err and data.
});

Troubleshooting

When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).

try {
  const data = await client.send(command);
  // process data.
} catch (error) {
  const { requestId, cfId, extendedRequestId } = error.$metadata;
  console.log({ requestId, cfId, extendedRequestId });
  /**
   * The keys within exceptions are also parsed.
   * You can access them by specifying exception names:
   * if (error.name === 'SomeServiceException') {
   *     const value = error.specialKeyInException;
   * }
   */
}

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.

To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.

Contributing

This client code is generated automatically. Any modifications will be overwritten the next time the @amzn/codewhisperer-streaming package is updated. To contribute to client you can check our generate clients scripts.

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.

Client Commands (Operations List)

AllowVendedLogDeliveryForResource

Command API Reference / Input / Output

AssociateCustomizationPermission

Command API Reference / Input / Output

CreateCustomization

Command API Reference / Input / Output

CreateProfile

Command API Reference / Input / Output

DeleteCustomization

Command API Reference / Input / Output

DeleteProfile

Command API Reference / Input / Output

DisassociateCustomizationPermission

Command API Reference / Input / Output

GenerateRecommendations

Command API Reference / Input / Output

GetCustomization

Command API Reference / Input / Output

ListCustomizationPermissions

Command API Reference / Input / Output

ListCustomizations

Command API Reference / Input / Output

ListCustomizationVersions

Command API Reference / Input / Output

ListProfiles

Command API Reference / Input / Output

ListTagsForResource

Command API Reference / Input / Output

TagResource

Command API Reference / Input / Output

UntagResource

Command API Reference / Input / Output

UpdateCustomization

Command API Reference / Input / Output

UpdateProfile

Command API Reference / Input / Output

VendKeyGrant

Command API Reference / Input / Output

CreateArtifactUploadUrl

Command API Reference / Input / Output

CreateTaskAssistConversation

Command API Reference / Input / Output

CreateUploadUrl

Command API Reference / Input / Output

CreateWorkspace

Command API Reference / Input / Output

DeleteTaskAssistConversation

Command API Reference / Input / Output

DeleteWorkspace

Command API Reference / Input / Output

GenerateCompletions

Command API Reference / Input / Output

GetCodeAnalysis

Command API Reference / Input / Output

GetCodeFixJob

Command API Reference / Input / Output

GetTaskAssistCodeGeneration

Command API Reference / Input / Output

GetTestGeneration

Command API Reference / Input / Output

GetTransformation

Command API Reference / Input / Output

GetTransformationPlan

Command API Reference / Input / Output

ListAvailableCustomizations

Command API Reference / Input / Output

ListAvailableProfiles

Command API Reference / Input / Output

ListCodeAnalysisFindings

Command API Reference / Input / Output

ListFeatureEvaluations

Command API Reference / Input / Output

ListWorkspaceMetadata

Command API Reference / Input / Output

ResumeTransformation

Command API Reference / Input / Output

SendTelemetryEvent

Command API Reference / Input / Output

StartCodeAnalysis

Command API Reference / Input / Output

StartCodeFixJob

Command API Reference / Input / Output

StartTaskAssistCodeGeneration

Command API Reference / Input / Output

StartTestGeneration

Command API Reference / Input / Output

StartTransformation

Command API Reference / Input / Output

StopTransformation

Command API Reference / Input / Output

ExportResultArchive

Command API Reference / Input / Output

GenerateAssistantResponse

Command API Reference / Input / Output

GenerateTaskAssistPlan

Command API Reference / Input / Output

AssociateConnectorResource

Command API Reference / Input / Output

CreateAssignment

Command API Reference / Input / Output

CreateExtension

Command API Reference / Input / Output

CreatePlugin

Command API Reference / Input / Output

CreateResolution

Command API Reference / Input / Output

DeleteAssignment

Command API Reference / Input / Output

DeleteConversation

Command API Reference / Input / Output

DeleteExtension

Command API Reference / Input / Output

DeletePlugin

Command API Reference / Input / Output

GetConnector

Command API Reference / Input / Output

GetConversation

Command API Reference / Input / Output

GetExtension

Command API Reference / Input / Output

GetIdentityMetadata

Command API Reference / Input / Output

GetPlugin

Command API Reference / Input / Output

GetTask

Command API Reference / Input / Output

GetTroubleshootingResults

Command API Reference / Input / Output

InvokeTask

Command API Reference / Input / Output

ListConversations

Command API Reference / Input / Output

ListDashboardMetrics

Command API Reference / Input / Output

ListExtensionProviders

Command API Reference / Input / Output

ListExtensions

Command API Reference / Input / Output

ListPluginProviders

Command API Reference / Input / Output

ListPlugins

Command API Reference / Input / Output

ListTagsForResource

Command API Reference / Input / Output

ListTasks

Command API Reference / Input / Output

PassRequest

Command API Reference / Input / Output

RejectConnector

Command API Reference / Input / Output

SendEvent

Command API Reference / Input / Output

SendMessage

Command API Reference / Input / Output

StartConversation

Command API Reference / Input / Output

StartTroubleshootingAnalysis

Command API Reference / Input / Output

StartTroubleshootingResolutionExplanation

Command API Reference / Input / Output

TagResource

Command API Reference / Input / Output

UntagResource

Command API Reference / Input / Output

UpdateConversation

Command API Reference / Input / Output

UpdatePlugin

Command API Reference / Input / Output

UpdateTroubleshootingCommandResult

Command API Reference / Input / Output

UsePlugin

Command API Reference / Input / Output

GenerateCodeFromCommands

Command API Reference / Input / Output

SendMessage

Command API Reference / Input / Output